uri-request.asciidoc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. [[search-uri-request]]
  2. == URI Search
  3. A search request can be executed purely using a URI by providing request
  4. parameters. Not all search options are exposed when executing a search
  5. using this mode, but it can be handy for quick "curl tests". Here is an
  6. example:
  7. [source,js]
  8. --------------------------------------------------
  9. GET twitter/tweet/_search?q=user:kimchy
  10. --------------------------------------------------
  11. // CONSOLE
  12. // TEST[setup:twitter]
  13. And here is a sample response:
  14. [source,js]
  15. --------------------------------------------------
  16. {
  17. "timed_out": false,
  18. "took": 62,
  19. "_shards":{
  20. "total" : 5,
  21. "successful" : 5,
  22. "failed" : 0
  23. },
  24. "hits":{
  25. "total" : 1,
  26. "max_score": 1.0,
  27. "hits" : [
  28. {
  29. "_index" : "twitter",
  30. "_type" : "tweet",
  31. "_id" : "0",
  32. "_score": 1.0,
  33. "_source" : {
  34. "user" : "kimchy",
  35. "date" : "2009-11-15T14:12:12",
  36. "message" : "trying out Elasticsearch",
  37. "likes": 0
  38. }
  39. }
  40. ]
  41. }
  42. }
  43. --------------------------------------------------
  44. // TESTRESPONSE[s/"took": 62/"took": "$body.took"/]
  45. [float]
  46. === Parameters
  47. The parameters allowed in the URI are:
  48. [cols="<,<",options="header",]
  49. |=======================================================================
  50. |Name |Description
  51. |`q` |The query string (maps to the `query_string` query, see
  52. <<query-dsl-query-string-query,_Query String
  53. Query_>> for more details).
  54. |`df` |The default field to use when no field prefix is defined within the
  55. query.
  56. |`analyzer` |The analyzer name to be used when analyzing the query string.
  57. |`lowercase_expanded_terms` |Should terms be automatically lowercased or
  58. not. Defaults to `true`.
  59. |`analyze_wildcard` |Should wildcard and prefix queries be analyzed or
  60. not. Defaults to `false`.
  61. |`default_operator` |The default operator to be used, can be `AND` or
  62. `OR`. Defaults to `OR`.
  63. |`lenient` |If set to true will cause format based failures (like
  64. providing text to a numeric field) to be ignored. Defaults to false.
  65. |`explain` |For each hit, contain an explanation of how scoring of the
  66. hits was computed.
  67. |`_source`|Set to `false` to disable retrieval of the `_source` field. You can also retrieve
  68. part of the document by using `_source_include` & `_source_exclude` (see the <<search-request-source-filtering, request body>>
  69. documentation for more details)
  70. |`fields` |The selective stored fields of the document to return for each hit,
  71. comma delimited. Not specifying any value will cause no fields to return.
  72. |`sort` |Sorting to perform. Can either be in the form of `fieldName`, or
  73. `fieldName:asc`/`fieldName:desc`. The fieldName can either be an actual
  74. field within the document, or the special `_score` name to indicate
  75. sorting based on scores. There can be several `sort` parameters (order
  76. is important).
  77. |`track_scores` |When sorting, set to `true` in order to still track
  78. scores and return them as part of each hit.
  79. |`timeout` |A search timeout, bounding the search request to be executed
  80. within the specified time value and bail with the hits accumulated up to
  81. that point when expired. Defaults to no timeout.
  82. |`terminate_after` |The maximum number of documents to collect for
  83. each shard, upon reaching which the query execution will terminate early.
  84. If set, the response will have a boolean field `terminated_early` to
  85. indicate whether the query execution has actually terminated_early.
  86. Defaults to no terminate_after.
  87. |`from` |The starting from index of the hits to return. Defaults to `0`.
  88. |`size` |The number of hits to return. Defaults to `10`.
  89. |`search_type` |The type of the search operation to perform. Can be
  90. `dfs_query_then_fetch` or `query_then_fetch`.
  91. Defaults to `query_then_fetch`. See
  92. <<search-request-search-type,_Search Type_>> for
  93. more details on the different types of search that can be performed.
  94. |=======================================================================