OpenSearch/docs/reference/mapping/params/position-increment-gap.asciidoc
Nik Everett 4b1c116461 Generate and run tests from the docs
Adds infrastructure so `gradle :docs:check` will extract tests from
snippets in the documentation and execute the tests. This is included
in `gradle check` so it should happen on CI and during a normal build.

By default each `// AUTOSENSE` snippet creates a unique REST test. These
tests are executed in a random order and the cluster is wiped between
each one. If multiple snippets chain together into a test you can annotate
all snippets after the first with `// TEST[continued]` to have the
generated tests for both snippets joined.

Snippets marked as `// TESTRESPONSE` are checked against the response
of the last action.

See docs/README.asciidoc for lots more.

Closes #12583. That issue is about catching bugs in the docs during build.
This catches *some* bugs in the docs during build which is a good start.
2016-05-05 13:58:03 -04:00

91 lines
2.3 KiB
Plaintext

[[position-increment-gap]]
=== `position_increment_gap`
<<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 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`.
For example:
[source,js]
--------------------------------------------------
PUT my_index/groups/1
{
"names": [ "John Abraham", "Lincoln Smith"]
}
GET my_index/groups/_search
{
"query": {
"match_phrase": {
"names": {
"query": "Abraham Lincoln" <1>
}
}
}
}
GET my_index/groups/_search
{
"query": {
"match_phrase": {
"names": {
"query": "Abraham Lincoln",
"slop": 101 <2>
}
}
}
}
--------------------------------------------------
// AUTOSENSE
<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`.
The `position_increment_gap` can be specified in the mapping. For instance:
[source,js]
--------------------------------------------------
PUT my_index
{
"mappings": {
"groups": {
"properties": {
"names": {
"type": "text",
"position_increment_gap": 0 <1>
}
}
}
}
}
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 0 terms apart from the
last term in the previous array element.
<2> The phrase query matches our document which is weird, but its what we asked
for in the mapping.
TIP: The `position_increment_gap` setting is allowed to have different settings
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>>.