search.asciidoc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. [[search]]
  2. = Search APIs
  3. [partintro]
  4. --
  5. ["float",id="search-multi-index"]
  6. == Multiple Indices
  7. All search APIs support execution across multiple indices, using simple
  8. `test1,test2,test3` notation (or `_all` for all indices). It also
  9. support wildcards, for example: `test*`, and the ability to "add" (`+`)
  10. and "remove" (`-`), for example: `+test*,-test3`.
  11. All multi indices API support the `ignore_indices` option. Setting it to
  12. `missing` will cause indices that do not exists to be ignored from the
  13. execution. By default, when its not set, the request will fail.
  14. [float]
  15. == Routing
  16. When executing a search, it will be broadcasted to all the index/indices
  17. shards (round robin between replicas). Which shards will be searched on
  18. can be controlled by providing the `routing` parameter. For example,
  19. when indexing tweets, the routing value can be the user name:
  20. [source,js]
  21. --------------------------------------------------
  22. $ curl -XPOST 'http://localhost:9200/twitter/tweet?routing=kimchy' -d '{
  23. "user" : "kimchy",
  24. "postDate" : "2009-11-15T14:12:12",
  25. "message" : "trying out Elastic Search"
  26. }
  27. '
  28. --------------------------------------------------
  29. In such a case, if we want to search only on the tweets for a specific
  30. user, we can specify it as the routing, resulting in the search hitting
  31. only the relevant shard:
  32. [source,js]
  33. --------------------------------------------------
  34. $ curl -XGET 'http://localhost:9200/twitter/tweet/_search?routing=kimchy' -d '{
  35. "query": {
  36. "filtered" : {
  37. "query" : {
  38. "query_string" : {
  39. "query" : "some query string here"
  40. }
  41. },
  42. "filter" : {
  43. "term" : { "user" : "kimchy" }
  44. }
  45. }
  46. }
  47. }
  48. '
  49. --------------------------------------------------
  50. The routing parameter can be multi valued represented as a comma
  51. separated string. This will result in hitting the relevant shards where
  52. the routing values match to.
  53. [float]
  54. == Stats Groups
  55. A search can be associated with stats groups, which maintains a
  56. statistics aggregation per group. It can later be retrieved using the
  57. <<indices-stats,indices stats>> API
  58. specifically. For example, here is a search body request that associate
  59. the request with two different groups:
  60. [source,js]
  61. --------------------------------------------------
  62. {
  63. "query" : {
  64. "match_all" : {}
  65. },
  66. "stats" : ["group1", "group2"]
  67. }
  68. --------------------------------------------------
  69. --
  70. include::search/search.asciidoc[]
  71. include::search/uri-request.asciidoc[]
  72. include::search/request-body.asciidoc[]
  73. include::search/facets.asciidoc[]
  74. include::search/suggesters.asciidoc[]
  75. include::search/multi-search.asciidoc[]
  76. include::search/count.asciidoc[]
  77. include::search/validate.asciidoc[]
  78. include::search/explain.asciidoc[]
  79. include::search/percolate.asciidoc[]
  80. include::search/more-like-this.asciidoc[]