index-prefixes.asciidoc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. [[index-prefixes]]
  2. === `index_prefixes`
  3. The `index_prefixes` parameter enables the indexing of term prefixes to speed
  4. up prefix searches. It accepts the following optional settings:
  5. [horizontal]
  6. `min_chars`::
  7. The minimum prefix length to index. Must be greater than 0, and defaults
  8. to 2. The value is inclusive.
  9. `max_chars`::
  10. The maximum prefix length to index. Must be less than 20, and defaults to 5.
  11. The value is inclusive.
  12. This example creates a text field using the default prefix length settings:
  13. [source,console]
  14. --------------------------------
  15. PUT my-index-000001
  16. {
  17. "mappings": {
  18. "properties": {
  19. "body_text": {
  20. "type": "text",
  21. "index_prefixes": { } <1>
  22. }
  23. }
  24. }
  25. }
  26. --------------------------------
  27. <1> An empty settings object will use the default `min_chars` and `max_chars`
  28. settings
  29. This example uses custom prefix length settings:
  30. [source,console]
  31. --------------------------------
  32. PUT my-index-000001
  33. {
  34. "mappings": {
  35. "properties": {
  36. "full_name": {
  37. "type": "text",
  38. "index_prefixes": {
  39. "min_chars" : 1,
  40. "max_chars" : 10
  41. }
  42. }
  43. }
  44. }
  45. }
  46. --------------------------------
  47. `index_prefixes` parameter instructs {ES} to create a subfield "._index_prefix". This
  48. field will be used to do fast prefix queries. When doing highlighting, add "._index_prefix"
  49. subfield to the `matched_fields` parameter to highlight the main field based on the
  50. found matches of the prefix field, like in the request below:
  51. [source,console]
  52. --------------------------------
  53. GET my-index-000001/_search
  54. {
  55. "query": {
  56. "prefix": {
  57. "full_name": {
  58. "value": "ki"
  59. }
  60. }
  61. },
  62. "highlight": {
  63. "fields": {
  64. "full_name": {
  65. "matched_fields": ["full_name._index_prefix"]
  66. }
  67. }
  68. }
  69. }
  70. --------------------------------
  71. // TEST[continued]