批量插入弹性搜索自动完成建议

曼努埃尔

如何批量插入建议

这里是映射

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
   }
}

您需要根据批量操作的期望来格式化数据,即“索引”操作的一行和带有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 } }
'

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章