2015-08-22 04:39:18 -04:00
|
|
|
[[position-increment-gap]]
|
|
|
|
=== `position_increment_gap`
|
2015-08-06 11:24:29 -04:00
|
|
|
|
2016-05-11 08:17:56 -04:00
|
|
|
<<mapping-index,Analyzed>> text fields take term <<index-options,positions>>
|
2015-08-06 11:24:29 -04:00
|
|
|
into account, in order to be able to support
|
|
|
|
<<query-dsl-match-query-phrase,proximity or phrase queries>>.
|
2016-05-11 08:17:56 -04:00
|
|
|
When indexing text fields with multiple values a "fake" gap is added between
|
2015-08-31 13:59:00 -04:00
|
|
|
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`.
|
2015-08-06 11:24:29 -04:00
|
|
|
|
2015-08-31 13:59:00 -04:00
|
|
|
For example:
|
2015-08-06 11:24:29 -04:00
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2015-08-06 11:24:29 -04:00
|
|
|
--------------------------------------------------
|
2020-07-27 15:58:26 -04:00
|
|
|
PUT my-index-000001/_doc/1
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"names": [ "John Abraham", "Lincoln Smith"]
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
|
2020-07-27 15:58:26 -04:00
|
|
|
GET my-index-000001/_search
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"query": {
|
|
|
|
"match_phrase": {
|
|
|
|
"names": {
|
|
|
|
"query": "Abraham Lincoln" <1>
|
|
|
|
}
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
2015-08-31 13:59:00 -04:00
|
|
|
|
2020-07-27 15:58:26 -04:00
|
|
|
GET my-index-000001/_search
|
2015-08-31 13:59:00 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"query": {
|
|
|
|
"match_phrase": {
|
|
|
|
"names": {
|
|
|
|
"query": "Abraham Lincoln",
|
|
|
|
"slop": 101 <2>
|
|
|
|
}
|
2015-08-31 13:59:00 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2015-08-31 13:59:00 -04:00
|
|
|
}
|
2015-08-06 11:24:29 -04:00
|
|
|
--------------------------------------------------
|
2019-09-06 11:31:13 -04:00
|
|
|
|
2015-08-31 13:59:00 -04:00
|
|
|
<1> This phrase query doesn't match our document which is totally expected.
|
|
|
|
<2> This phrase query matches our document, even though `Abraham` and `Lincoln`
|
|
|
|
are in separate strings, because `slop` > `position_increment_gap`.
|
2015-08-06 11:24:29 -04:00
|
|
|
|
2015-08-31 13:59:00 -04:00
|
|
|
|
|
|
|
The `position_increment_gap` can be specified in the mapping. For instance:
|
2015-08-06 11:24:29 -04:00
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2015-08-06 11:24:29 -04:00
|
|
|
--------------------------------------------------
|
2020-07-27 15:58:26 -04:00
|
|
|
PUT my-index-000001
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"mappings": {
|
2019-01-22 09:13:52 -05:00
|
|
|
"properties": {
|
|
|
|
"names": {
|
|
|
|
"type": "text",
|
|
|
|
"position_increment_gap": 0 <1>
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-27 15:58:26 -04:00
|
|
|
PUT my-index-000001/_doc/1
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"names": [ "John Abraham", "Lincoln Smith"]
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
|
2020-07-27 15:58:26 -04:00
|
|
|
GET my-index-000001/_search
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
2020-07-21 15:49:58 -04:00
|
|
|
"query": {
|
|
|
|
"match_phrase": {
|
|
|
|
"names": "Abraham Lincoln" <2>
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
2020-07-21 15:49:58 -04:00
|
|
|
}
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2019-09-06 11:31:13 -04:00
|
|
|
|
2015-08-31 13:59:00 -04:00
|
|
|
<1> The first term in the next array element will be 0 terms apart from the
|
2015-08-06 11:24:29 -04:00
|
|
|
last term in the previous array element.
|
2015-08-31 13:59:00 -04:00
|
|
|
<2> The phrase query matches our document which is weird, but its what we asked
|
|
|
|
for in the mapping.
|
2015-08-12 15:21:37 -04:00
|
|
|
|