position-increment-gap.asciidoc 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. [[position-increment-gap]]
  2. === `position_increment_gap`
  3. <<mapping-index,Analyzed>> text fields take term <<index-options,positions>>
  4. into account, in order to be able to support
  5. <<query-dsl-match-query-phrase,proximity or phrase queries>>.
  6. When indexing text fields with multiple values a "fake" gap is added between
  7. the values to prevent most phrase queries from matching across the values. The
  8. size of this gap is configured using `position_increment_gap` and defaults to
  9. `100`.
  10. For example:
  11. [source,js]
  12. --------------------------------------------------
  13. PUT my_index/groups/1
  14. {
  15. "names": [ "John Abraham", "Lincoln Smith"]
  16. }
  17. GET my_index/groups/_search
  18. {
  19. "query": {
  20. "match_phrase": {
  21. "names": {
  22. "query": "Abraham Lincoln" <1>
  23. }
  24. }
  25. }
  26. }
  27. GET my_index/groups/_search
  28. {
  29. "query": {
  30. "match_phrase": {
  31. "names": {
  32. "query": "Abraham Lincoln",
  33. "slop": 101 <2>
  34. }
  35. }
  36. }
  37. }
  38. --------------------------------------------------
  39. // CONSOLE
  40. <1> This phrase query doesn't match our document which is totally expected.
  41. <2> This phrase query matches our document, even though `Abraham` and `Lincoln`
  42. are in separate strings, because `slop` > `position_increment_gap`.
  43. The `position_increment_gap` can be specified in the mapping. For instance:
  44. [source,js]
  45. --------------------------------------------------
  46. PUT my_index
  47. {
  48. "mappings": {
  49. "groups": {
  50. "properties": {
  51. "names": {
  52. "type": "text",
  53. "position_increment_gap": 0 <1>
  54. }
  55. }
  56. }
  57. }
  58. }
  59. PUT my_index/groups/1
  60. {
  61. "names": [ "John Abraham", "Lincoln Smith"]
  62. }
  63. GET my_index/groups/_search
  64. {
  65. "query": {
  66. "match_phrase": {
  67. "names": "Abraham Lincoln" <2>
  68. }
  69. }
  70. }
  71. --------------------------------------------------
  72. // CONSOLE
  73. <1> The first term in the next array element will be 0 terms apart from the
  74. last term in the previous array element.
  75. <2> The phrase query matches our document which is weird, but its what we asked
  76. for in the mapping.
  77. TIP: The `position_increment_gap` setting is allowed to have different settings
  78. for fields of the same name in the same index. Its value can be updated on
  79. existing fields using the <<indices-put-mapping,PUT mapping API>>.