批量插入 elasticSearch 以获得自动完成建议
bulk insert elasticSearch for autocomplete suggestion
如何批量插入建议
这里是映射
PUT /myindex/autocomplete/_mapping
{
"autocomplete": {
"properties": {
"name": {
"type": "string"
},
"suggest": {
"type": "completion",
"index_analyzer": "simple",
"search_analyzer": "simple",
"payloads": true
}
}
}
}
如果我惰性化然后一个一个地工作,这里有很少的数据
POST /myindex/autocomplete/
{
"name": "Nevermind",
"suggest": {
"input": [
"Nevermind",
"Nirvana"
],
"output": "Nirvana - Nevermind",
"payload": {
"tip": 1,
"oid": 1
},
"weight": 34
}
}
如何批量插入建议?
PUT /myindex/autocomplete/_bulk
{
"name": "Nevermind",
"suggest": {
"input": [
"Nevermind"
],
"output": "Nirvana - Nevermind",
"payload": {
"tip": 1,
"oid": 1
},
"weight": 34
}
}
{
"name": "Bleach",
"suggest": {
"input": [
"Bleach"
],
"output": "Nirvana - Bleach",
"payload": {
"tip": 2,
"oid": 3
},
"weight": 20
}
}
您需要根据 bulk operation expects 的内容格式化您的数据,即一行用于 "index" 操作,另一行用于 JSON 源,全部由换行符分隔(包括最后一行):
curl -XPOST localhost:9200/myindex/autocomplete/_bulk -d '
{ "index":{"_id": 1} }
{ "name": "Nevermind", "suggest": { "input": [ "Nevermind" ], "output": "Nirvana - Nevermind", "payload": { "tip": 1, "oid": 1 }, "weight": 34 } }
{ "index":{"_id": 2} }
{ "name": "Bleach", "suggest": { "input": [ "Bleach" ], "output": "Nirvana - Bleach", "payload": { "tip": 2, "oid": 3 }, "weight": 20 } }
'
如何批量插入建议
这里是映射
PUT /myindex/autocomplete/_mapping
{
"autocomplete": {
"properties": {
"name": {
"type": "string"
},
"suggest": {
"type": "completion",
"index_analyzer": "simple",
"search_analyzer": "simple",
"payloads": true
}
}
}
}
如果我惰性化然后一个一个地工作,这里有很少的数据
POST /myindex/autocomplete/
{
"name": "Nevermind",
"suggest": {
"input": [
"Nevermind",
"Nirvana"
],
"output": "Nirvana - Nevermind",
"payload": {
"tip": 1,
"oid": 1
},
"weight": 34
}
}
如何批量插入建议?
PUT /myindex/autocomplete/_bulk
{
"name": "Nevermind",
"suggest": {
"input": [
"Nevermind"
],
"output": "Nirvana - Nevermind",
"payload": {
"tip": 1,
"oid": 1
},
"weight": 34
}
}
{
"name": "Bleach",
"suggest": {
"input": [
"Bleach"
],
"output": "Nirvana - Bleach",
"payload": {
"tip": 2,
"oid": 3
},
"weight": 20
}
}
您需要根据 bulk operation expects 的内容格式化您的数据,即一行用于 "index" 操作,另一行用于 JSON 源,全部由换行符分隔(包括最后一行):
curl -XPOST localhost:9200/myindex/autocomplete/_bulk -d '
{ "index":{"_id": 1} }
{ "name": "Nevermind", "suggest": { "input": [ "Nevermind" ], "output": "Nirvana - Nevermind", "payload": { "tip": 1, "oid": 1 }, "weight": 34 } }
{ "index":{"_id": 2} }
{ "name": "Bleach", "suggest": { "input": [ "Bleach" ], "output": "Nirvana - Bleach", "payload": { "tip": 2, "oid": 3 }, "weight": 20 } }
'