uri-request.asciidoc 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. [[search-uri-request]]
  2. === URI Search
  3. Specifies search criteria as query parameters in the request URI.
  4. [source,js]
  5. --------------------------------------------------
  6. GET twitter/_search?q=user:kimchy
  7. --------------------------------------------------
  8. // CONSOLE
  9. // TEST[setup:twitter]
  10. [[search-uri-request-api-request]]
  11. ==== {api-request-title}
  12. `GET /<index>/_search?q=<parameter>`
  13. [[search-uri-request-api-desc]]
  14. ==== {api-description-title}
  15. You can use query parameters to define your search criteria directly in the
  16. request URI, rather than in the request body. Request URI searches do not
  17. support the full {es} Query DSL, but are handy for testing.
  18. [[search-uri-request-api-path-params]]
  19. ==== {api-path-parms-title}
  20. include::{docdir}/rest-api/common-parms.asciidoc[tag=index]
  21. [[search-uri-request-api-query-params]]
  22. ==== {api-query-parms-title}
  23. `allow_partial_search_results`::
  24. (Optional, boolean) Set to `false` to fail the request if only partial results
  25. are available. Defaults to `true`, which returns partial results in the event
  26. of timeouts or partial failures You can override the default behavior for all
  27. requests by setting `search.default_allow_partial_results` to `false` in the
  28. cluster settings.
  29. include::{docdir}/rest-api/common-parms.asciidoc[tag=analyze_wildcard]
  30. include::{docdir}/rest-api/common-parms.asciidoc[tag=analyzer]
  31. `batched_reduce_size`::
  32. (Optional, integer) The number of shard results that should be reduced at once
  33. on the coordinating node. This value should be used as a protection mechanism
  34. to reduce the memory overhead per search request if the potential number of
  35. shards in the request can be large.
  36. include::{docdir}/rest-api/common-parms.asciidoc[tag=default_operator]
  37. include::{docdir}/rest-api/common-parms.asciidoc[tag=df]
  38. `explain`::
  39. (Optional, string) For each hit, include an explanation of how the score was
  40. computed.
  41. include::{docdir}/rest-api/common-parms.asciidoc[tag=from]
  42. include::{docdir}/rest-api/common-parms.asciidoc[tag=lenient]
  43. include::{docdir}/rest-api/common-parms.asciidoc[tag=search-q]
  44. include::{docdir}/rest-api/common-parms.asciidoc[tag=search_type]
  45. `size`::
  46. (Optional, integer) The number of hits to return. Defaults to `10`.
  47. include::{docdir}/rest-api/common-parms.asciidoc[tag=source]
  48. include::{docdir}/rest-api/common-parms.asciidoc[tag=source_excludes]
  49. include::{docdir}/rest-api/common-parms.asciidoc[tag=source_includes]
  50. `stored_fields`::
  51. (Optional, string) The selective stored fields of the document to return for
  52. each hit, comma delimited. Not specifying any value will cause no fields to
  53. return.
  54. `sort`::
  55. (Optional, string) Sorting to perform. Can either be in the form of
  56. `fieldName`, or `fieldName:asc`/`fieldName:desc`. The fieldName can either be
  57. an actual field within the document, or the special `_score` name to indicate
  58. sorting based on scores. There can be several `sort` parameters (order is
  59. important).
  60. `track_scores`::
  61. (Optional, boolean) When sorting, set to `true` in order to still track scores
  62. and return them as part of each hit.
  63. `track_total_hits`::
  64. (Optional, integer) Defaults to `10,000`. Set to `false` in order to disable
  65. the tracking of the total number of hits that match the query. It also accepts
  66. an integer which in this case represents the number of hits to count
  67. accurately. (See the <<request-body-search-track-total-hits, request body>>
  68. documentation for more details).
  69. `timeout`::
  70. (Optional, <<time-units, time units>>) A search timeout, bounding the search
  71. request to be executed within the specified time value and bail with the hits
  72. accumulated up to that point when expired. Defaults to no timeout.
  73. include::{docdir}/rest-api/common-parms.asciidoc[tag=terminate_after]
  74. [[search-uri-request-api-example]]
  75. ==== {api-examples-title}
  76. [source,js]
  77. --------------------------------------------------
  78. GET twitter/_search?q=user:kimchy
  79. --------------------------------------------------
  80. // CONSOLE
  81. // TEST[setup:twitter]
  82. The API returns the following response:
  83. [source,js]
  84. --------------------------------------------------
  85. {
  86. "timed_out": false,
  87. "took": 62,
  88. "_shards":{
  89. "total" : 1,
  90. "successful" : 1,
  91. "skipped" : 0,
  92. "failed" : 0
  93. },
  94. "hits":{
  95. "total" : {
  96. "value": 1,
  97. "relation": "eq"
  98. },
  99. "max_score": 1.3862944,
  100. "hits" : [
  101. {
  102. "_index" : "twitter",
  103. "_type" : "_doc",
  104. "_id" : "0",
  105. "_score": 1.3862944,
  106. "_source" : {
  107. "user" : "kimchy",
  108. "date" : "2009-11-15T14:12:12",
  109. "message" : "trying out Elasticsearch",
  110. "likes": 0
  111. }
  112. }
  113. ]
  114. }
  115. }
  116. --------------------------------------------------
  117. // TESTRESPONSE[s/"took": 62/"took": "$body.took"/]