在 elasticsearch 服务器中的字段上实现完成建议器

rud*_*211 4 autocomplete elasticsearch

我正在尝试在 elasticsearch 服务器中的字段中实现完成建议。当我尝试执行 curl 命令时

curl -X POST localhost:9200/anisug/_suggest?pretty -d '{
 "test" : {
    "text" : "n",
    "completion" : {
        "field" : "header"
    }
}
}'
Run Code Online (Sandbox Code Playgroud)

我得到一个例外:

ElasticSearchException[Field [header] 不是完成建议字段]。

我错过了什么?

aas*_*ash 5

我认为,在定义anisug的映射时,您需要设置标题字段以完成提示。例如,你可以使用这个

curl -X PUT localhost:9200/anisug/_mapping -d '{
  "test" : {
        "properties" : {
            "name" : { "type" : "string" },
            "header" : { "type" : "completion",
                          "index_analyzer" : "simple",
                          "search_analyzer" : "simple",
                          "payloads" : true
            }
         }
    }
}'
Run Code Online (Sandbox Code Playgroud)

同样,在索引数据时,您需要发送额外的完成信息。有关更多信息,请访问此链接