position_increment_gap
Elastic Cloud Serverless projects are autoscaled environments, fully managed by Elastic and available on Elastic Cloud. Availability This functionality is generally available and ready for production usage. Serverless interfaces and procedures might differ from classic Elastic Stack deployments. The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats. Availability This functionality is generally available and ready for production usage. Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments. This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.
Serverless
Generally available
Stack
Generally available
Analyzed text fields take term positions into account, in order to be able to support proximity or phrase queries. When indexing text fields with multiple values a "fake" gap is added between the values to prevent most phrase queries from matching across the values. The size of this gap is configured using position_increment_gap and defaults to 100.
For example:
PUT my-index-000001/_doc/1{ "names": [ "John Abraham", "Lincoln Smith"] }GET my-index-000001/_search{ "query": { "match_phrase": { "names": { "query": "Abraham Lincoln" } } } }GET my-index-000001/_search{ "query": { "match_phrase": { "names": { "query": "Abraham Lincoln", "slop": 101 } } } }
- This phrase query doesn’t match our document which is totally expected.
- This phrase query matches our document, even though
AbrahamandLincolnare in separate strings, becauseslop>position_increment_gap.
The position_increment_gap can be specified in the mapping. For instance:
PUT my-index-000001{ "mappings": { "properties": { "names": { "type": "text", "position_increment_gap": 0 } } } }PUT my-index-000001/_doc/1{ "names": [ "John Abraham", "Lincoln Smith"] }GET my-index-000001/_search{ "query": { "match_phrase": { "names": "Abraham Lincoln" } } }
- The first term in the next array element will be 0 terms apart from the last term in the previous array element.
- The phrase query matches our document which is weird, but its what we asked for in the mapping.