如何批量插入建议
这里是映射
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
}
}
如何做一个BULK插入的建议?
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
}
}
答案 0 :(得分:1)
您需要根据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 } }
'