使用Elasticsearch完成建议程序我在返回与单字查询匹配的多字输入建议时遇到问题。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": []
}
]
}
我希望同样的结果作为工作的查询,匹配“猫狗”。任何建议是什么问题以及如何使失败的查询工作?当使用标准分析仪代替空白分析仪时,我会得到相同的结果。我想在上面的例子中给每个输入字符串使用多个单词。
搜索+查询不返回文本和我的情况下,文本可以是三个字段中的任何东西,所以我怎么能显示自动完成确切的文本。 –