2015-08-22 04:39:18 -04:00
|
|
|
[[position-increment-gap]]
|
|
|
|
=== `position_increment_gap`
|
2015-08-06 11:24:29 -04:00
|
|
|
|
|
|
|
<<mapping-index,Analyzed>> string fields take term <<index-options,positions>>
|
|
|
|
into account, in order to be able to support
|
|
|
|
<<query-dsl-match-query-phrase,proximity or phrase queries>>.
|
2015-08-31 13:59:00 -04:00
|
|
|
When indexing string 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`.
|
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
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2016-04-29 10:42:03 -04:00
|
|
|
PUT my_index/groups/1
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"names": [ "John Abraham", "Lincoln Smith"]
|
|
|
|
}
|
|
|
|
|
2016-04-29 10:42:03 -04:00
|
|
|
GET my_index/groups/_search
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"match_phrase": {
|
2015-09-23 03:18:26 -04:00
|
|
|
"names": {
|
|
|
|
"query": "Abraham Lincoln" <1>
|
|
|
|
}
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-31 13:59:00 -04:00
|
|
|
|
2016-04-29 10:42:03 -04:00
|
|
|
GET my_index/groups/_search
|
2015-08-31 13:59:00 -04:00
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"match_phrase": {
|
2015-09-23 03:18:26 -04:00
|
|
|
"names": {
|
|
|
|
"query": "Abraham Lincoln",
|
|
|
|
"slop": 101 <2>
|
|
|
|
}
|
2015-08-31 13:59:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-06 11:24:29 -04:00
|
|
|
--------------------------------------------------
|
2016-05-09 09:42:23 -04:00
|
|
|
// CONSOLE
|
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
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
PUT my_index
|
|
|
|
{
|
|
|
|
"mappings": {
|
2015-09-23 03:18:26 -04:00
|
|
|
"groups": {
|
2015-08-06 11:24:29 -04:00
|
|
|
"properties": {
|
|
|
|
"names": {
|
2016-03-18 12:01:27 -04:00
|
|
|
"type": "text",
|
2015-08-31 13:59:00 -04:00
|
|
|
"position_increment_gap": 0 <1>
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-29 10:42:03 -04:00
|
|
|
PUT my_index/groups/1
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"names": [ "John Abraham", "Lincoln Smith"]
|
|
|
|
}
|
|
|
|
|
2016-04-29 10:42:03 -04:00
|
|
|
GET my_index/groups/_search
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"match_phrase": {
|
|
|
|
"names": "Abraham Lincoln" <2>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-05-09 09:42:23 -04:00
|
|
|
// CONSOLE
|
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
|
|
|
|
2015-08-22 04:39:18 -04:00
|
|
|
TIP: The `position_increment_gap` setting is allowed to have different settings
|
2015-08-12 15:21:37 -04:00
|
|
|
for fields of the same name in the same index. Its value can be updated on
|
|
|
|
existing fields using the <<indices-put-mapping,PUT mapping API>>.
|