search.asciidoc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. [[search-routing]]
  16. == Routing
  17. When executing a search, it will be broadcasted to all the index/indices
  18. shards (round robin between replicas). Which shards will be searched on
  19. can be controlled by providing the `routing` parameter. For example,
  20. when indexing tweets, the routing value can be the user name:
  21. [source,js]
  22. --------------------------------------------------
  23. $ curl -XPOST 'http://localhost:9200/twitter/tweet?routing=kimchy' -d '{
  24. "user" : "kimchy",
  25. "postDate" : "2009-11-15T14:12:12",
  26. "message" : "trying out Elastic Search"
  27. }
  28. '
  29. --------------------------------------------------
  30. In such a case, if we want to search only on the tweets for a specific
  31. user, we can specify it as the routing, resulting in the search hitting
  32. only the relevant shard:
  33. [source,js]
  34. --------------------------------------------------
  35. $ curl -XGET 'http://localhost:9200/twitter/tweet/_search?routing=kimchy' -d '{
  36. "query": {
  37. "filtered" : {
  38. "query" : {
  39. "query_string" : {
  40. "query" : "some query string here"
  41. }
  42. },
  43. "filter" : {
  44. "term" : { "user" : "kimchy" }
  45. }
  46. }
  47. }
  48. }
  49. '
  50. --------------------------------------------------
  51. The routing parameter can be multi valued represented as a comma
  52. separated string. This will result in hitting the relevant shards where
  53. the routing values match to.
  54. [float]
  55. [[stats-groups]]
  56. == Stats Groups
  57. A search can be associated with stats groups, which maintains a
  58. statistics aggregation per group. It can later be retrieved using the
  59. <<indices-stats,indices stats>> API
  60. specifically. For example, here is a search body request that associate
  61. the request with two different groups:
  62. [source,js]
  63. --------------------------------------------------
  64. {
  65. "query" : {
  66. "match_all" : {}
  67. },
  68. "stats" : ["group1", "group2"]
  69. }
  70. --------------------------------------------------
  71. --
  72. include::search/search.asciidoc[]
  73. include::search/uri-request.asciidoc[]
  74. include::search/request-body.asciidoc[]
  75. include::search/facets.asciidoc[]
  76. include::search/suggesters.asciidoc[]
  77. include::search/multi-search.asciidoc[]
  78. include::search/count.asciidoc[]
  79. include::search/validate.asciidoc[]
  80. include::search/explain.asciidoc[]
  81. include::search/percolate.asciidoc[]
  82. include::search/more-like-this.asciidoc[]
  83. include::search/termvectors.asciidoc[]