Percolator typeedit

The percolator field type parses a json structure into a native query and stores that query, so that the 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:

{
    "properties": {
        "query": {
            "type": "percolator"
        }
    }
}

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

{
    "query" : {
		"match" : {
			"field" : "value"
		}
	}
}

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 create index or 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.

Dedicated Percolator Indexedit

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.

Forcing Unmapped Fields to be Handled as Stringsedit

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.

Limitationsedit

Parent/childedit

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.

Range queriesedit

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

Fetching queriesedit

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.

Script queryedit

The script inside a script query can only access doc values fields. The percolate query indexes the provided document into an in-memory index. This in-memory index doesn’t support stored fields and because of that the _source field and other stored fields are not stored. This is the reason why in the script query the _source and other stored fields aren’t available.