|
4 | 4 | When performing queries across multiple indexes, it is sometimes desirable to |
5 | 5 | add query clauses that are associated with documents of only certain indexes. |
6 | 6 | The `_index` field allows matching on the index a document was indexed into. |
7 | | -Its value is accessible in `term`, or `terms` queries, aggregations, |
8 | | -scripts, and when sorting: |
9 | | - |
10 | | -NOTE: The `_index` is exposed as a virtual field -- it is not added to the |
11 | | -Lucene index as a real field. This means that you can use the `_index` field |
12 | | -in a `term` or `terms` query (or any query that is rewritten to a `term` |
13 | | -query, such as the `match`, `query_string` or `simple_query_string` query), |
14 | | -but it does not support `prefix`, `wildcard`, `regexp`, or `fuzzy` queries. |
| 7 | +Its value is accessible in certain queries and aggregations, and when sorting |
| 8 | +or scripting: |
15 | 9 |
|
16 | 10 | [source,console] |
17 | 11 | -------------------------- |
18 | | -# Example documents |
19 | 12 | PUT index_1/_doc/1 |
20 | 13 | { |
21 | 14 | "text": "Document in index 1" |
@@ -63,3 +56,20 @@ GET index_1,index_2/_search |
63 | 56 | <2> Aggregating on the `_index` field |
64 | 57 | <3> Sorting on the `_index` field |
65 | 58 | <4> Accessing the `_index` field in scripts |
| 59 | + |
| 60 | +The `_index` field is exposed virtually -- it is not added to the Lucene index |
| 61 | +as a real field. This means that you can use the `_index` field in a `term` or |
| 62 | +`terms` query (or any query that is rewritten to a `term` query, such as the |
| 63 | +`match`, `query_string` or `simple_query_string` query), as well as `prefix` |
| 64 | +and `wildcard` queries. However, it does not support `regexp` and `fuzzy` |
| 65 | +queries. |
| 66 | + |
| 67 | +Queries on the `_index` field accept index aliases in addition to concrete |
| 68 | +index names. |
| 69 | + |
| 70 | +NOTE: When specifying a remote index name such as `cluster_1:index_3`, the |
| 71 | +query must contain the separator character `:`. For example, a `wildcard` query |
| 72 | +on `cluster_*:index_3` would match documents from the remote index. However, a |
| 73 | +query on `cluster*index_1` is only matched against local indices, since no |
| 74 | +separator is present. This behavior aligns with the usual resolution rules for |
| 75 | +remote index names. |
0 commit comments