如何批量插入建议

这里是映射

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的格式来格式化数据,即“索引”操作的一行和带有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 } }
'

关于elasticsearch - 批量插入 Elasticsearch 自动完成建议,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33261241/

10-10 07:55