IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
position_increment_gap
edit
IMPORTANT: This documentation is no longer updated. Refer to Elastic's version policy and the latest documentation.
position_increment_gap
editAnalyzed 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:
response = client.index(
index: 'my-index-000001',
id: 1,
body: {
names: [
'John Abraham',
'Lincoln Smith'
]
}
)
puts response
response = client.search(
index: 'my-index-000001',
body: {
query: {
match_phrase: {
names: {
query: 'Abraham Lincoln'
}
}
}
}
)
puts response
response = client.search(
index: 'my-index-000001',
body: {
query: {
match_phrase: {
names: {
query: 'Abraham Lincoln',
slop: 101
}
}
}
}
)
puts response
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 |
The position_increment_gap can be specified in the mapping. For instance:
response = client.indices.create(
index: 'my-index-000001',
body: {
mappings: {
properties: {
names: {
type: 'text',
position_increment_gap: 0
}
}
}
}
)
puts response
response = client.index(
index: 'my-index-000001',
id: 1,
body: {
names: [
'John Abraham',
'Lincoln Smith'
]
}
)
puts response
response = client.search(
index: 'my-index-000001',
body: {
query: {
match_phrase: {
names: 'Abraham Lincoln'
}
}
}
)
puts response