Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs around querying on the _index field. #48436

Merged
merged 1 commit into from
Oct 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions docs/reference/mapping/fields/index-field.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,11 @@
When performing queries across multiple indexes, it is sometimes desirable to
add query clauses that are associated with documents of only certain indexes.
The `_index` field allows matching on the index a document was indexed into.
Its value is accessible in `term`, or `terms` queries, aggregations,
scripts, and when sorting:

NOTE: The `_index` is exposed as a virtual field -- it is not added to the
Lucene index as a real field. This means that you can use the `_index` field
in a `term` or `terms` query (or any query that is rewritten to a `term`
query, such as the `match`, `query_string` or `simple_query_string` query),
but it does not support `prefix`, `wildcard`, `regexp`, or `fuzzy` queries.
Its value is accessible in certain queries and aggregations, and when sorting
or scripting:

[source,console]
--------------------------
# Example documents
PUT index_1/_doc/1
{
"text": "Document in index 1"
Expand Down Expand Up @@ -63,3 +56,20 @@ GET index_1,index_2/_search
<2> Aggregating on the `_index` field
<3> Sorting on the `_index` field
<4> Accessing the `_index` field in scripts

The `_index` field is exposed virtually -- it is not added to the Lucene index
as a real field. This means that you can use the `_index` field in a `term` or
`terms` query (or any query that is rewritten to a `term` query, such as the
`match`, `query_string` or `simple_query_string` query), as well as `prefix`
and `wildcard` queries. However, it does not support `regexp` and `fuzzy`
queries.

Queries on the `_index` field accept index aliases in addition to concrete
index names.

NOTE: When specifying a remote index name such as `cluster_1:index_3`, the
query must contain the separator character `:`. For example, a `wildcard` query
on `cluster_*:index_3` would match documents from the remote index. However, a
query on `cluster*index_1` is only matched against local indices, since no
separator is present. This behavior aligns with the usual resolution rules for
remote index names.