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
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2017-12-14 11:47:53 -05:00
|
|
|
PUT my_index/_doc/1
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"names": [ "John Abraham", "Lincoln Smith"]
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
GET my_index/_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
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
GET my_index/_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]
|
|
|
|
--------------------------------------------------
|
2019-01-14 16:08:01 -05:00
|
|
|
PUT my_index?include_type_name=true
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"mappings": {
|
2017-12-14 11:47:53 -05:00
|
|
|
"_doc": {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
PUT my_index/_doc/1
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"names": [ "John Abraham", "Lincoln Smith"]
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
GET my_index/_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
|
|
|
|