mlt-query.asciidoc 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. [[query-dsl-mlt-query]]
  2. === More Like This Query
  3. More like this query find documents that are "like" provided text by
  4. running it against one or more fields.
  5. [source,js]
  6. --------------------------------------------------
  7. {
  8. "more_like_this" : {
  9. "fields" : ["name.first", "name.last"],
  10. "like" : "text like this one",
  11. "min_term_freq" : 1,
  12. "max_query_terms" : 12
  13. }
  14. }
  15. --------------------------------------------------
  16. More Like This can find documents that are "like" a set of
  17. chosen documents. The syntax to specify one or more documents is similar to
  18. the <<docs-multi-get,Multi GET API>>.
  19. If only one document is specified, the query behaves the same as the
  20. <<search-more-like-this,More Like This API>>.
  21. [source,js]
  22. --------------------------------------------------
  23. {
  24. "more_like_this" : {
  25. "fields" : ["name.first", "name.last"],
  26. "like" : [
  27. {
  28. "_index" : "test",
  29. "_type" : "type",
  30. "_id" : "1"
  31. },
  32. {
  33. "_index" : "test",
  34. "_type" : "type",
  35. "_id" : "2"
  36. },
  37. "and also some text like this one!"
  38. ],
  39. "min_term_freq" : 1,
  40. "max_query_terms" : 12
  41. }
  42. }
  43. --------------------------------------------------
  44. Additionally, <<docs-termvectors-artificial-doc,artificial documents>> are also supported.
  45. This is useful in order to specify one or more documents not present in the index.
  46. [source,js]
  47. --------------------------------------------------
  48. {
  49. "more_like_this" : {
  50. "fields" : ["name.first", "name.last"],
  51. "like" : [
  52. {
  53. "_index" : "test",
  54. "_type" : "type",
  55. "doc" : {
  56. "name": {
  57. "first": "Ben",
  58. "last": "Grimm"
  59. },
  60. "tweet": "You got no idea what I'd... what I'd give to be invisible."
  61. }
  62. }
  63. },
  64. {
  65. "_index" : "test",
  66. "_type" : "type",
  67. "_id" : "2"
  68. }
  69. ],
  70. "min_term_freq" : 1,
  71. "max_query_terms" : 12
  72. }
  73. }
  74. --------------------------------------------------
  75. `more_like_this` can be shortened to `mlt`.
  76. Under the hood, `more_like_this` simply creates multiple `should` clauses in a `bool` query of
  77. interesting terms extracted from some provided text. The interesting terms are
  78. selected with respect to their tf-idf scores. These are controlled by
  79. `min_term_freq`, `min_doc_freq`, and `max_doc_freq`. The number of interesting
  80. terms is controlled by `max_query_terms`. While the minimum number of clauses
  81. that must be satisfied is controlled by `minimum_should_match`. The terms
  82. are extracted from the text in `like` and analyzed by the analyzer associated
  83. with the field, unless specified by `analyzer`. There are other parameters,
  84. such as `min_word_length`, `max_word_length` or `stop_words`, to control what
  85. terms should be considered as interesting. In order to give more weight to
  86. more interesting terms, each boolean clause associated with a term could be
  87. boosted by the term tf-idf score times some boosting factor `boost_terms`.
  88. When a search for multiple documents is issued, More Like This generates a
  89. `more_like_this` query per document field in `fields`. These `fields` are
  90. specified as a top level parameter or within each document request.
  91. IMPORTANT: The fields must be indexed and of type `string`. Additionally, when
  92. using `like` with documents, the fields must be either `stored`, store `term_vector`
  93. or `_source` must be enabled.
  94. The `more_like_this` top level parameters include:
  95. [cols="<,<",options="header",]
  96. |=======================================================================
  97. |Parameter |Description
  98. |`fields` |A list of the fields to run the more like this query against.
  99. Defaults to the `_all` field for text and to all possible fields
  100. for documents.
  101. |`like`|coming[2.0]
  102. Can either be some text, some documents or a combination of all, *required*.
  103. A document request follows the same syntax as the
  104. <<docs-multi-get,Multi Get API>> or <<docs-multi-termvectors,Multi Term Vectors API>>.
  105. In this case, the text is fetched from `fields` unless specified otherwise in each document request.
  106. The text is analyzed by the default analyzer at the field, unless overridden by the
  107. `per_field_analyzer` parameter of the <<docs-termvectors-per-field-analyzer,Term Vectors API>>.
  108. |`like_text` |deprecated[2.0,Replaced by `like`]
  109. The text to find documents like it, *required* if `ids` or `docs` are
  110. not specified.
  111. |`ids` or `docs` |deprecated[2.0,Replaced by `like`]
  112. A list of documents following the same syntax as the
  113. <<docs-multi-get,Multi GET API>> or <<docs-multi-termvectors,Multi termvectors API>>.
  114. The text is fetched from `fields` unless specified otherwise in each `doc`.
  115. The text is analyzed by the default analyzer at the field, unless specified by the
  116. `per_field_analyzer` parameter of the <<docs-termvectors-per-field-analyzer,Term Vectors API>>.
  117. |`include` |When using `like` with document requests, specifies whether the documents should be
  118. included from the search. Defaults to `false`.
  119. |`minimum_should_match`| From the generated query, the number of terms that
  120. must match following the <<query-dsl-minimum-should-match,minimum should
  121. syntax>>. (Defaults to `"30%"`).
  122. |`min_term_freq` |The frequency below which terms will be ignored in the
  123. source doc. The default frequency is `2`.
  124. |`max_query_terms` |The maximum number of query terms that will be
  125. included in any generated query. Defaults to `25`.
  126. |`stop_words` |An array of stop words. Any word in this set is
  127. considered "uninteresting" and ignored. Even if your Analyzer allows
  128. stopwords, you might want to tell the MoreLikeThis code to ignore them,
  129. as for the purposes of document similarity it seems reasonable to assume
  130. that "a stop word is never interesting".
  131. |`min_doc_freq` |The frequency at which words will be ignored which do
  132. not occur in at least this many docs. Defaults to `5`.
  133. |`max_doc_freq` |The maximum frequency in which words may still appear.
  134. Words that appear in more than this many docs will be ignored. Defaults
  135. to unbounded.
  136. |`min_word_length` |The minimum word length below which words will be
  137. ignored. Defaults to `0`.(Old name "min_word_len" is deprecated)
  138. |`max_word_length` |The maximum word length above which words will be
  139. ignored. Defaults to unbounded (`0`). (Old name "max_word_len" is deprecated)
  140. |`boost_terms` |Sets the boost factor to use when boosting terms.
  141. Defaults to deactivated (`0`). Any other value activates boosting with given
  142. boost factor.
  143. |`boost` |Sets the boost value of the query. Defaults to `1.0`.
  144. |`analyzer` |The analyzer that will be used to analyze the `like text`.
  145. Defaults to the analyzer associated with the first field in `fields`.
  146. |=======================================================================