2019-07-17 08:49:22 -04:00
|
|
|
[[return-suggesters-type]]
|
2019-07-19 14:35:36 -04:00
|
|
|
==== Returning the type of the suggester
|
2017-02-10 04:53:38 -05:00
|
|
|
|
|
|
|
Sometimes you need to know the exact type of a suggester in order to parse its results. The `typed_keys` parameter
|
|
|
|
can be used to change the suggester's name in the response so that it will be prefixed by its type.
|
|
|
|
|
|
|
|
Considering the following example with two suggesters `term` and `phrase`:
|
|
|
|
|
2019-09-05 10:11:25 -04:00
|
|
|
[source,console]
|
2017-02-10 04:53:38 -05:00
|
|
|
--------------------------------------------------
|
|
|
|
POST _search?typed_keys
|
|
|
|
{
|
|
|
|
"suggest": {
|
|
|
|
"text" : "some test mssage",
|
|
|
|
"my-first-suggester" : {
|
|
|
|
"term" : {
|
|
|
|
"field" : "message"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"my-second-suggester" : {
|
|
|
|
"phrase" : {
|
|
|
|
"field" : "message"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// TEST[setup:twitter]
|
|
|
|
|
|
|
|
In the response, the suggester names will be changed to respectively `term#my-first-suggester` and
|
|
|
|
`phrase#my-second-suggester`, reflecting the types of each suggestion:
|
|
|
|
|
2019-09-06 16:09:09 -04:00
|
|
|
[source,console-result]
|
2017-02-10 04:53:38 -05:00
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"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
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
...
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// TESTRESPONSE[s/\.\.\./"took": "$body.took", "timed_out": false, "_shards": "$body._shards", "hits": "$body.hits"/]
|
2020-03-27 05:23:16 -04:00
|
|
|
// TESTRESPONSE[s/"score": 0.8333333/"score": $body.suggest.term#my-first-suggester.2.options.0.score/]
|
|
|
|
// TESTRESPONSE[s/"score": 0.030227963/"score": $body.suggest.phrase#my-second-suggester.0.options.0.score/]
|
2017-02-10 04:53:38 -05:00
|
|
|
|
|
|
|
<1> The name `my-first-suggester` now contains the `term` prefix.
|
|
|
|
<2> The name `my-second-suggester` now contains the `phrase` prefix.
|