search-application-search.asciidoc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. [role="xpack"]
  2. [[search-application-search]]
  3. === Search Application Search
  4. beta::[]
  5. ++++
  6. <titleabbrev>Search Application Search</titleabbrev>
  7. ++++
  8. Given specified query parameters, generates and executes an {es} query using the search template associated
  9. with the search application or a default template if none is specified.
  10. Unspecified template parameters will be assigned their default values (if applicable).
  11. [[search-application-search-request]]
  12. ==== {api-request-title}
  13. `POST _application/search_application/<name>/_search`
  14. [[search-application-search-prereqs]]
  15. ==== {api-prereq-title}
  16. Requires read privileges on the backing alias of the search application.
  17. [[search-application-search-path-params]]
  18. ==== {api-path-parms-title}
  19. `typed_keys`::
  20. (Optional, Boolean) If `true`, aggregation and suggester names are prefixed
  21. by their respective types in the response. Defaults to `false`.
  22. [[search-application-search-request-body]]
  23. ==== {api-request-body-title}
  24. `params`::
  25. (Optional, map of strings to objects)
  26. Query parameters used to generate the {es} query from the search template associated with the search application.
  27. If a parameter used in the search template is not specified in `params`, the parameter's default value will be used.
  28. [NOTE]
  29. ====
  30. The search application can be configured to validate search template parameters.
  31. See the `dictionary` parameter in the <<put-search-application-dictionary-param, put search application>> API for more
  32. information.
  33. ====
  34. [[search-application-search-response-codes]]
  35. ==== {api-response-codes-title}
  36. `400`::
  37. Invalid parameter passed to search template.
  38. Examples include:
  39. - Missing required parameter
  40. - Invalid parameter data type
  41. - Invalid parameter value
  42. `404`::
  43. Search Application `<name>` does not exist.
  44. [[search-application-search-example]]
  45. ==== {api-examples-title}
  46. The following example executes a search against a search application called `my-app` that uses the search template from
  47. the <<search-application-api-bm25-template, text search example>>:
  48. ////
  49. [source,console]
  50. ----
  51. PUT /index1
  52. PUT /index1/_doc/1?refresh=true
  53. {
  54. "title": "Sample document",
  55. "description": "A sample document that matches my first query"
  56. }
  57. PUT _application/search_application/my-app
  58. {
  59. "indices": ["index1"],
  60. "template": {
  61. "script": {
  62. "lang": "mustache",
  63. "source": """
  64. {
  65. "query": {
  66. "multi_match": {
  67. "query": "{{query_string}}",
  68. "fields": [{{#text_fields}}"{{name}}^{{boost}}",{{/text_fields}}]
  69. }
  70. },
  71. "explain": "{{explain}}",
  72. "from": "{{from}}",
  73. "size": "{{size}}"
  74. }
  75. """,
  76. "params": {
  77. "query_string": "*",
  78. "text_fields": [
  79. {"name": "title", "boost": 10},
  80. {"name": "description", "boost": 5}
  81. ],
  82. "explain": false,
  83. "from": 0,
  84. "size": 10
  85. }
  86. }
  87. }
  88. }
  89. ----
  90. // TESTSETUP
  91. //////////////////////////
  92. [source,console]
  93. --------------------------------------------------
  94. DELETE _application/search_application/my-app
  95. DELETE /index1
  96. --------------------------------------------------
  97. // TEARDOWN
  98. ////
  99. [source,console]
  100. ----
  101. POST _application/search_application/my-app/_search
  102. {
  103. "params": {
  104. "query_string": "my first query",
  105. "text_fields": [
  106. {"name": "title", "boost": 5},
  107. {"name": "description", "boost": 1}
  108. ]
  109. }
  110. }
  111. ----
  112. The generated {es} query would look like:
  113. [source,console-result]
  114. ----
  115. {
  116. "from": 0,
  117. "size": 10,
  118. "query": {
  119. "multi_match": {
  120. "query": "my first query",
  121. "fields": [
  122. "description^1.0",
  123. "title^5.0"
  124. ]
  125. }
  126. },
  127. "explain": false
  128. }
  129. ----
  130. // TESTRESPONSE[skip:result of request not run in this document]
  131. In this case, the `from`, `size`, and `explain` parameters are not specified in the request, so the default values
  132. specified in the search template are used.
  133. The expected response is the search results from the {es} query that was generated & executed.
  134. The response format is the same as that used by the <<search-api-response-body,{es} Search API>>:
  135. [source,console-result]
  136. ----
  137. {
  138. "took": 5,
  139. "timed_out": false,
  140. "_shards": {
  141. "total": 1,
  142. "successful": 1,
  143. "skipped": 0,
  144. "failed": 0
  145. },
  146. "hits": {
  147. "total": {
  148. "value": 1,
  149. "relation": "eq"
  150. },
  151. "max_score": 0.8630463,
  152. "hits": ...
  153. }
  154. }
  155. ----
  156. // TESTRESPONSE[s/"took": 5/"took": $body.$_path/]
  157. // TESTRESPONSE[s/"hits": \.\.\./"hits": $body.$_path/]