search-application-render-query.asciidoc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. [role="xpack"]
  2. [[search-application-render-query]]
  3. === Render Search Application Query
  4. preview::[]
  5. ++++
  6. <titleabbrev>Render Search Application Query</titleabbrev>
  7. ++++
  8. Given specified query parameters, creates an Elasticsearch query to run. Any unspecified template parameters will be
  9. assigned their default values if applicable. Returns the specific Elasticsearch query that would be generated and
  10. run by calling <<search-application-search,search application search>>.
  11. [[search-application-render-query-request]]
  12. ==== {api-request-title}
  13. `POST _application/search_application/<name>/_render_query`
  14. [[search-application-render-query-prereqs]]
  15. ==== {api-prereq-title}
  16. Requires read privileges on the backing alias of the search application.
  17. [[search-application-render-query-request-body]]
  18. ==== {api-request-body-title}
  19. `params`::
  20. (Optional, map of strings to objects)
  21. Query parameters specific to this request, which will override any defaults specified in the template.
  22. [[search-application-render-query-response-codes]]
  23. ==== {api-response-codes-title}
  24. `404`::
  25. Search Application `<name>` does not exist.
  26. [[search-application-render-query-example]]
  27. ==== {api-examples-title}
  28. The following example renders a query for a search application called `my-app`. In this case, the `from` and `size`
  29. parameters are not specified, so default values are pulled from the search application template.
  30. ////
  31. [source,console]
  32. ----
  33. PUT /index1
  34. PUT _application/search_application/my-app
  35. {
  36. "indices": ["index1"],
  37. "template": {
  38. "script": {
  39. "lang": "mustache",
  40. "source": """
  41. {
  42. "query": {
  43. "multi_match": {
  44. "query": "{{query_string}}",
  45. "fields": [{{#text_fields}}"{{name}}^{{boost}}",{{/text_fields}}]
  46. }
  47. },
  48. "explain": "{{explain}}",
  49. "from": "{{from}}",
  50. "size": "{{size}}"
  51. }
  52. """,
  53. "params": {
  54. "query_string": "*",
  55. "text_fields": [
  56. {"name": "title", "boost": 10},
  57. {"name": "description", "boost": 5}
  58. ],
  59. "explain": false,
  60. "from": 0,
  61. "size": 10
  62. }
  63. }
  64. }
  65. }
  66. ----
  67. // TESTSETUP
  68. [source,console]
  69. --------------------------------------------------
  70. DELETE _application/search_application/my-app
  71. DELETE index1
  72. --------------------------------------------------
  73. // TEARDOWN
  74. ////
  75. [source,console]
  76. ----
  77. POST _application/search_application/my-app/_render_query
  78. {
  79. "params": {
  80. "query_string": "my first query",
  81. "text_fields": [
  82. {
  83. "name": "title",
  84. "boost": 10
  85. },
  86. {
  87. "name": "text",
  88. "boost": 1
  89. }
  90. ]
  91. }
  92. }
  93. ----
  94. A sample response:
  95. [source,console-result]
  96. ----
  97. {
  98. "from": 0,
  99. "size": 10,
  100. "query": {
  101. "multi_match": {
  102. "query": "my first query",
  103. "fields": [
  104. "text^1.0",
  105. "title^10.0"
  106. ]
  107. }
  108. },
  109. "explain": false
  110. }
  111. ----
  112. // TEST[continued]