2013-08-28 19:24:34 -04:00
|
|
|
[[query-dsl-indices-query]]
|
2015-06-03 19:59:22 -04:00
|
|
|
=== Indices Query
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-10-23 15:14:52 -04:00
|
|
|
The `indices` query is useful in cases where a search is executed across
|
|
|
|
multiple indices. It allows to specify a list of index names and an inner
|
|
|
|
query that is only executed for indices matching names on that list.
|
|
|
|
For other indices that are searched, but that don't match entries
|
|
|
|
on the list, the alternative `no_match_query` is exectuted.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
{
|
|
|
|
"indices" : {
|
|
|
|
"indices" : ["index1", "index2"],
|
|
|
|
"query" : {
|
|
|
|
"term" : { "tag" : "wow" }
|
|
|
|
},
|
|
|
|
"no_match_query" : {
|
|
|
|
"term" : { "tag" : "kow" }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
|
2013-11-06 09:52:29 -05:00
|
|
|
You can use the `index` field to provide a single index.
|
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
`no_match_query` can also have "string" value of `none` (to match no
|
2013-11-06 09:52:29 -05:00
|
|
|
documents), and `all` (to match all). Defaults to `all`.
|
|
|
|
|
2013-11-14 09:53:13 -05:00
|
|
|
`query` is mandatory, as well as `indices` (or `index`).
|
2013-11-06 09:52:29 -05:00
|
|
|
|
2013-11-14 09:53:13 -05:00
|
|
|
[TIP]
|
2015-06-03 19:59:22 -04:00
|
|
|
====================================================================
|
2013-11-14 09:53:13 -05:00
|
|
|
The fields order is important: if the `indices` are provided before `query`
|
|
|
|
or `no_match_query`, the related queries get parsed only against the indices
|
|
|
|
that they are going to be executed on. This is useful to avoid parsing queries
|
|
|
|
when it is not necessary and prevent potential mapping errors.
|
2015-06-03 19:59:22 -04:00
|
|
|
====================================================================
|