misc.asciidoc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. [[return-suggesters-type]]
  2. ==== Returning the type of the suggester
  3. Sometimes you need to know the exact type of a suggester in order to parse its results. The `typed_keys` parameter
  4. can be used to change the suggester's name in the response so that it will be prefixed by its type.
  5. Considering the following example with two suggesters `term` and `phrase`:
  6. [source,console]
  7. --------------------------------------------------
  8. POST _search?typed_keys
  9. {
  10. "suggest": {
  11. "text" : "some test mssage",
  12. "my-first-suggester" : {
  13. "term" : {
  14. "field" : "message"
  15. }
  16. },
  17. "my-second-suggester" : {
  18. "phrase" : {
  19. "field" : "message"
  20. }
  21. }
  22. }
  23. }
  24. --------------------------------------------------
  25. // TEST[setup:twitter]
  26. In the response, the suggester names will be changed to respectively `term#my-first-suggester` and
  27. `phrase#my-second-suggester`, reflecting the types of each suggestion:
  28. [source,console-result]
  29. --------------------------------------------------
  30. {
  31. "suggest": {
  32. "term#my-first-suggester": [ <1>
  33. {
  34. "text": "some",
  35. "offset": 0,
  36. "length": 4,
  37. "options": []
  38. },
  39. {
  40. "text": "test",
  41. "offset": 5,
  42. "length": 4,
  43. "options": []
  44. },
  45. {
  46. "text": "mssage",
  47. "offset": 10,
  48. "length": 6,
  49. "options": [
  50. {
  51. "text": "message",
  52. "score": 0.8333333,
  53. "freq": 4
  54. }
  55. ]
  56. }
  57. ],
  58. "phrase#my-second-suggester": [ <2>
  59. {
  60. "text": "some test mssage",
  61. "offset": 0,
  62. "length": 16,
  63. "options": [
  64. {
  65. "text": "some test message",
  66. "score": 0.030227963
  67. }
  68. ]
  69. }
  70. ]
  71. },
  72. ...
  73. }
  74. --------------------------------------------------
  75. // TESTRESPONSE[s/\.\.\./"took": "$body.took", "timed_out": false, "_shards": "$body._shards", "hits": "$body.hits"/]
  76. <1> The name `my-first-suggester` now contains the `term` prefix.
  77. <2> The name `my-second-suggester` now contains the `phrase` prefix.