我有一个弹性搜索的自动完成工作版本。但有一个问题是,如果我搜索xbox 360.我会得到xbox 360和xbox one作为可能的建议。
我想建议只考虑包含整个查询的建议,直到建议点为止。例如,如果我输入xbox 3,弹性搜索应该永远不会返回xbox,而只能返回xbox 360.
我的查询是针对_suggestions终点运行的。 我的配置如下。
{
"mappings": {
"query" : {
"properties" : {
"product" : { "type" : "string" },
"name_suggest" : {
"type" : "completion"
}
}
}
答案 0 :(得分:1)
我认为你正在描述完成建议者。如果是这种情况,您可以将其作为示例:
PUT /mymusicsuggest
{
"settings": {
"number_of_shards": 1,
"number_of_replicas": 0
},
"mappings": {
"album": {
"properties": {
"name": {
"type": "string"
},
"suggest": {
"type": "completion",
"index_analyzer": "simple",
"search_analyzer": "simple",
"payloads": true
}
}
}
}
}
PUT /mymusicsuggest/album/1
{
"name" : "Tori Amos - Little Earthquakes",
"suggest" : {
"input": [ "earthquakes", "little", "tori", "amos" ],
"output": "Tori Amos - Little Earthquakes",
"payload" : { "songs" : ["11861","11839","11849","11853","11841", "11847","11851","11845","11855","11843","11859","11857"] },
"weight" : 10
}
}