使用 Elasticsearch 补全建议器时,我在返回与单字查询匹配的多字输入建议时遇到问题。
示例结构:
PUT /test_index/
{
"mappings": {
"item": {
"properties": {
"test_suggest": {
"type": "completion",
"index_analyzer": "whitespace",
"search_analyzer": "whitespace",
"payloads": false
}
}
}
}
}
PUT /test_index/item/1
{
"test_suggest": {
"input": [
"cat dog",
"elephant"
]
}
}
工作查询:
POST /test_index/_suggest
{
"test_suggest":{
"text":"cat",
"completion": {
"field" : "test_suggest"
}
}
}
结果
{
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"test_suggest": [
{
"text": "cat",
"offset": 0,
"length": 3,
"options": [
{
"text": "cat dog",
"score": 1
}
]
}
]
}
查询失败:
POST /test_index/_suggest
{
"test_suggest":{
"text":"dog",
"completion": {
"field" : "test_suggest"
}
}
}
结果
{
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"test_suggest": [
{
"text": "dog",
"offset": 0,
"length": 3,
"options": []
}
]
}
我希望与工作查询相同的结果,匹配“猫狗”。任何建议是什么问题以及如何使失败的查询工作?使用标准分析器而不是空白分析器时,我得到了相同的结果。我想在每个输入字符串中使用多个单词,如上面的示例所示。