suggesters.asciidoc 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. [[search-suggesters]]
  2. === Suggesters
  3. Suggests similar looking terms based on a provided text by using a suggester.
  4. Parts of the suggest feature are still under development.
  5. [source,console]
  6. --------------------------------------------------
  7. POST twitter/_search
  8. {
  9. "query" : {
  10. "match": {
  11. "message": "tring out Elasticsearch"
  12. }
  13. },
  14. "suggest" : {
  15. "my-suggestion" : {
  16. "text" : "tring out Elasticsearch",
  17. "term" : {
  18. "field" : "message"
  19. }
  20. }
  21. }
  22. }
  23. --------------------------------------------------
  24. // TEST[setup:twitter]
  25. [[search-suggesters-api-request]]
  26. ==== {api-request-title}
  27. The suggest feature suggests similar looking terms based on a provided text by
  28. using a suggester. The suggest request part is defined alongside the query part
  29. in a `_search` request. If the query part is left out, only suggestions are
  30. returned.
  31. NOTE: `_suggest` endpoint has been deprecated in favour of using suggest via
  32. `_search` endpoint. In 5.0, the `_search` endpoint has been optimized for
  33. suggest only search requests.
  34. [[search-suggesters-api-example]]
  35. ==== {api-examples-title}
  36. Several suggestions can be specified per request. Each suggestion is identified
  37. with an arbitrary name. In the example below two suggestions are requested. Both
  38. `my-suggest-1` and `my-suggest-2` suggestions use the `term` suggester, but have
  39. a different `text`.
  40. [source,console]
  41. --------------------------------------------------
  42. POST _search
  43. {
  44. "suggest": {
  45. "my-suggest-1" : {
  46. "text" : "tring out Elasticsearch",
  47. "term" : {
  48. "field" : "message"
  49. }
  50. },
  51. "my-suggest-2" : {
  52. "text" : "kmichy",
  53. "term" : {
  54. "field" : "user"
  55. }
  56. }
  57. }
  58. }
  59. --------------------------------------------------
  60. // TEST[setup:twitter]
  61. The below suggest response example includes the suggestion response for
  62. `my-suggest-1` and `my-suggest-2`. Each suggestion part contains
  63. entries. Each entry is effectively a token from the suggest text and
  64. contains the suggestion entry text, the original start offset and length
  65. in the suggest text and if found an arbitrary number of options.
  66. [source,console-result]
  67. --------------------------------------------------
  68. {
  69. "_shards": ...
  70. "hits": ...
  71. "took": 2,
  72. "timed_out": false,
  73. "suggest": {
  74. "my-suggest-1": [ {
  75. "text": "tring",
  76. "offset": 0,
  77. "length": 5,
  78. "options": [ {"text": "trying", "score": 0.8, "freq": 1 } ]
  79. }, {
  80. "text": "out",
  81. "offset": 6,
  82. "length": 3,
  83. "options": []
  84. }, {
  85. "text": "elasticsearch",
  86. "offset": 10,
  87. "length": 13,
  88. "options": []
  89. } ],
  90. "my-suggest-2": ...
  91. }
  92. }
  93. --------------------------------------------------
  94. // TESTRESPONSE[s/"_shards": \.\.\./"_shards": "$body._shards",/]
  95. // TESTRESPONSE[s/"hits": .../"hits": "$body.hits",/]
  96. // TESTRESPONSE[s/"took": 2,/"took": "$body.took",/]
  97. // TESTRESPONSE[s/"my-suggest-2": \.\.\./"my-suggest-2": "$body.suggest.my-suggest-2"/]
  98. Each options array contains an option object that includes the
  99. suggested text, its document frequency and score compared to the suggest
  100. entry text. The meaning of the score depends on the used suggester. The
  101. term suggester's score is based on the edit distance.
  102. [float]
  103. [[global-suggest]]
  104. ===== Global suggest text
  105. To avoid repetition of the suggest text, it is possible to define a
  106. global text. In the example below the suggest text is defined globally
  107. and applies to the `my-suggest-1` and `my-suggest-2` suggestions.
  108. [source,console]
  109. --------------------------------------------------
  110. POST _search
  111. {
  112. "suggest": {
  113. "text" : "tring out Elasticsearch",
  114. "my-suggest-1" : {
  115. "term" : {
  116. "field" : "message"
  117. }
  118. },
  119. "my-suggest-2" : {
  120. "term" : {
  121. "field" : "user"
  122. }
  123. }
  124. }
  125. }
  126. --------------------------------------------------
  127. The suggest text can in the above example also be specified as
  128. suggestion specific option. The suggest text specified on suggestion
  129. level override the suggest text on the global level.
  130. include::suggesters/term-suggest.asciidoc[]
  131. include::suggesters/phrase-suggest.asciidoc[]
  132. include::suggesters/completion-suggest.asciidoc[]
  133. include::suggesters/context-suggest.asciidoc[]
  134. include::suggesters/misc.asciidoc[]