search.asciidoc 2.9 KB

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