Returning the type of the suggester
有时你需要知道确切的suggester类型,以解析其结果。 typed_keys参数可用于在响应中更改suggester的名称,它将以其类型为前缀。
考虑以下两个suggester term
和phrase的例子:
POST _search?typed_keys
{
"suggest": {
"text" : "some test mssage",
"my-first-suggester" : {
"term" : {
"field" : "message"
}
},
"my-second-suggester" : {
"phrase" : {
"field" : "message"
}
}
}
}
在回应中,suggester命名将分别改为term#my-first-suggester和phrase#my-second-suggester,以反映每个suggestion的类型:
{
"suggest": {
"term#my-first-suggester": [ 【1】
{
"text": "some",
"offset": 0,
"length": 4,
"options": []
},
{
"text": "test",
"offset": 5,
"length": 4,
"options": []
},
{
"text": "mssage",
"offset": 10,
"length": 6,
"options": [
{
"text": "message",
"score": 0.8333333,
"freq": 4
}
]
}
],
"phrase#my-second-suggester": [ 【2】
{
"text": "some test mssage",
"offset": 0,
"length": 16,
"options": [
{
"text": "some test message",
"score": 0.030227963
}
]
}
]
},
...
}
【1】名字my-first-suggester现在包含term前缀。
【2】名字my-second-suggester现在包含phrase
前缀。
原文地址:https://www.elastic.co/guide/en/elasticsearch/reference/5.4/returning-suggesters-type.html