ElasticSearch 5.x对Suggester API(文档)引入了一些(重大)更改.最值得注意的变化如下:
完成建议是面向文档的
建议知道他们所属的文件.现在,关联的文档(
_source)将作为完成建议的一部分返回.
简而言之,所有完成查询都返回所有匹配的文档而不是匹配的单词.这就是问题所在 - 如果自动填充的单词出现在多个文档中,则会重复这些单词.
假设我们有这个简单的映射:
{
"my-index": {
"mappings": {
"users": {
"properties": {
"firstName": {
"type": "text"
},
"lastName": {
"type": "text"
},
"suggest": {
"type": "completion",
"analyzer": "simple"
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
有一些测试文件:
{
"_index": "my-index",
"_type": "users",
"_id": "1",
"_source": {
"firstName": "John",
"lastName": "Doe",
"suggest": [
{
"input": [
"John",
"Doe"
]
}
]
}
},
{
"_index": "my-index",
"_type": "users",
"_id": …Run Code Online (Sandbox Code Playgroud)