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>>.
|
|
|
|
When indexing an array of strings, each string of the array is indexed
|
|
|
|
directly after the previous one, almost as though all the strings in the array
|
|
|
|
had been concatenated into one big string.
|
|
|
|
|
|
|
|
This can result in matches from phrase queries spanning two array elements.
|
|
|
|
For instance:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
PUT /my_index/groups/1
|
|
|
|
{
|
|
|
|
"names": [ "John Abraham", "Lincoln Smith"]
|
|
|
|
}
|
|
|
|
|
|
|
|
GET /my_index/groups/_search
|
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"match_phrase": {
|
|
|
|
"names": "Abraham Lincoln" <1>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// AUTOSENSE
|
|
|
|
<1> This phrase query matches our document, even though `Abraham` and `Lincoln` are in separate strings.
|
|
|
|
|
2015-08-22 04:39:18 -04:00
|
|
|
The `position_increment_gap` can introduce a fake gap between each array element. For instance:
|
2015-08-06 11:24:29 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
PUT my_index
|
|
|
|
{
|
|
|
|
"mappings": {
|
|
|
|
"my_type": {
|
|
|
|
"properties": {
|
|
|
|
"names": {
|
|
|
|
"type": "string",
|
2015-08-22 04:39:18 -04:00
|
|
|
"position_increment_gap": 50 <1>
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PUT /my_index/groups/1
|
|
|
|
{
|
|
|
|
"names": [ "John Abraham", "Lincoln Smith"]
|
|
|
|
}
|
|
|
|
|
|
|
|
GET /my_index/groups/_search
|
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"match_phrase": {
|
|
|
|
"names": "Abraham Lincoln" <2>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
// AUTOSENSE
|
|
|
|
<1> The first term in the next array element will be 50 terms apart from the
|
|
|
|
last term in the previous array element.
|
2015-08-12 15:21:37 -04:00
|
|
|
<2> The phrase query no longer matches our document.
|
|
|
|
|
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>>.
|
|
|
|
|