uri-request.asciidoc 4.8 KB

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