<commit_before>[[percolator]]
=== Percolator type

The `percolator` field type parses a json structure into a native query and
stores that query, so that the <<query-dsl-percolate-query,percolate query>>
can use it to match provided documents.

Any field that contains a json object can be configured to be a percolator
field. The percolator field type has no settings. Just configuring the `percolator`
field type is sufficient to instruct Elasticsearch to treat a field as a
query.

If the following mapping configures the `percolator` field type for the
`query` field:

[source,js]
--------------------------------------------------
{
    "properties": {
        "query": {
            "type": "percolator"
        }
    }
}
--------------------------------------------------

Then the following json snippet can be indexed as a native query:

[source,js]
--------------------------------------------------
{
    "query" : {
		"match" : {
			"field" : "value"
		}
	}
}
--------------------------------------------------

[IMPORTANT]
=====================================

Fields referred to in a percolator query must *already* exist in the mapping
associated with the index used for percolation. In order to make sure these fields exist,
add or update a mapping via the <<indices-create-index,create index>> or <<indices-put-mapping,put mapping>> APIs.
Fields referred in a percolator query may exist in any type of the index containing the `percolator` field type.

Also an index can only contain up to one percolator field mapping. Multiple percolator fields will be rejected by the
put index and put mapping APIs.

=====================================

[float]
==== Dedicated Percolator Index

Percolate queries can be added to any index. Instead of adding percolate queries to the index the data resides in,
these queries can also be added to a dedicated index. The advantage of this is that this dedicated percolator index
can have its own index settings (For example the number of primary and replica shards). If you choose to have a dedicated
percolate index, you need to make sure that the mappings from the normal index are also available on the percolate index.
Otherwise percolate queries can be parsed incorrectly.

[float]
==== Forcing Unmapped Fields to be Handled as Strings

In certain cases it is unknown what kind of percolator queries do get registered, and if no field mapping exists for fields
that are referred by percolator queries then adding a percolator query fails. This means the mapping needs to be updated
to have the field with the appropriate settings, and then the percolator query can be added. But sometimes it is sufficient
if all unmapped fields are handled as if these were default string fields. In those cases one can configure the
`index.percolator.map_unmapped_fields_as_string` setting to `true` (default to `false`) and then if a field referred in
a percolator query does not exist, it will be handled as a default string field so that adding the percolator query doesn't
fail.

[float]
==== Limitations

Because the `percolate` query is processing one document at a time, it doesn't support queries and filters that run
against child documents such as `has_child` and `has_parent`.

The percolator doesn't accepts percolator queries containing `range` queries with ranges that are based on current
time (using `now`).

There are a number of queries that fetch data via a get call during query parsing. For example the `terms` query when
using terms lookup, `template` query when using indexed scripts and `geo_shape` when using pre-indexed shapes. When these
queries are indexed by the `percolator` field type then the get call is executed once. So each time the `percolator`
query evaluates these queries, the fetches terms, shapes etc. as the were upon index time will be used.<commit_msg>docs: describe more explicitly what happens when indexing queries that fetch terms<commit_after>[[percolator]]
=== Percolator type

The `percolator` field type parses a json structure into a native query and
stores that query, so that the <<query-dsl-percolate-query,percolate query>>
can use it to match provided documents.

Any field that contains a json object can be configured to be a percolator
field. The percolator field type has no settings. Just configuring the `percolator`
field type is sufficient to instruct Elasticsearch to treat a field as a
query.

If the following mapping configures the `percolator` field type for the
`query` field:

[source,js]
--------------------------------------------------
{
    "properties": {
        "query": {
            "type": "percolator"
        }
    }
}
--------------------------------------------------

Then the following json snippet can be indexed as a native query:

[source,js]
--------------------------------------------------
{
    "query" : {
		"match" : {
			"field" : "value"
		}
	}
}
--------------------------------------------------

[IMPORTANT]
=====================================

Fields referred to in a percolator query must *already* exist in the mapping
associated with the index used for percolation. In order to make sure these fields exist,
add or update a mapping via the <<indices-create-index,create index>> or <<indices-put-mapping,put mapping>> APIs.
Fields referred in a percolator query may exist in any type of the index containing the `percolator` field type.

Also an index can only contain up to one percolator field mapping. Multiple percolator fields will be rejected by the
put index and put mapping APIs.

=====================================

[float]
==== Dedicated Percolator Index

Percolate queries can be added to any index. Instead of adding percolate queries to the index the data resides in,
these queries can also be added to a dedicated index. The advantage of this is that this dedicated percolator index
can have its own index settings (For example the number of primary and replica shards). If you choose to have a dedicated
percolate index, you need to make sure that the mappings from the normal index are also available on the percolate index.
Otherwise percolate queries can be parsed incorrectly.

[float]
==== Forcing Unmapped Fields to be Handled as Strings

In certain cases it is unknown what kind of percolator queries do get registered, and if no field mapping exists for fields
that are referred by percolator queries then adding a percolator query fails. This means the mapping needs to be updated
to have the field with the appropriate settings, and then the percolator query can be added. But sometimes it is sufficient
if all unmapped fields are handled as if these were default string fields. In those cases one can configure the
`index.percolator.map_unmapped_fields_as_string` setting to `true` (default to `false`) and then if a field referred in
a percolator query does not exist, it will be handled as a default string field so that adding the percolator query doesn't
fail.

[float]
==== Limitations

Because the `percolate` query is processing one document at a time, it doesn't support queries and filters that run
against child documents such as `has_child` and `has_parent`.

The percolator doesn't accepts percolator queries containing `range` queries with ranges that are based on current
time (using `now`).

There are a number of queries that fetch data via a get call during query parsing. For example the `terms` query when
using terms lookup, `template` query when using indexed scripts and `geo_shape` when using pre-indexed shapes. When these
queries are indexed by the `percolator` field type then the get call is executed once. So each time the `percolator`
query evaluates these queries, the fetches terms, shapes etc. as the were upon index time will be used. Important to note
is that fetching of terms that these queries do, happens both each time the percolator query gets indexed on both primary
and replica shards, so the terms that are actually indexed can be different between shard copies, if the source index
changed while indexing.
{'fraction_non_alphanumeric': 0.11365616830573883, 'fraction_numerical': 0.0, 'mean_word_length': 3.4832589285714284, 'pattern_counts': {'":': 6, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5004766', 'n_tokens_mistral': 1989, 'n_tokens_neox': 1881, 'n_words': 1139}