analysis.asciidoc 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. [[analysis]]
  2. = Text analysis
  3. [partintro]
  4. --
  5. _Text analysis_ is the process of converting text, like the body of any email,
  6. into _tokens_ or _terms_ which are added to the inverted index for searching.
  7. Analysis is performed by an <<analysis-analyzers,_analyzer_>> which can be
  8. either a built-in analyzer or a <<analysis-custom-analyzer,`custom`>> analyzer
  9. defined per index.
  10. [float]
  11. == Index time analysis
  12. For instance, at index time the built-in <<english-analyzer,`english`>> _analyzer_
  13. will first convert the sentence:
  14. [source,text]
  15. ------
  16. "The QUICK brown foxes jumped over the lazy dog!"
  17. ------
  18. into distinct tokens. It will then lowercase each token, remove frequent
  19. stopwords ("the") and reduce the terms to their word stems (foxes -> fox,
  20. jumped -> jump, lazy -> lazi). In the end, the following terms will be added
  21. to the inverted index:
  22. [source,text]
  23. ------
  24. [ quick, brown, fox, jump, over, lazi, dog ]
  25. ------
  26. [float]
  27. [[specify-index-time-analyzer]]
  28. === Specifying an index time analyzer
  29. {es} determines which index-time analyzer to use by
  30. checking the following parameters in order:
  31. . The <<analyzer,`analyzer`>> mapping parameter of the field
  32. . The `default` analyzer parameter in the index settings
  33. If none of these parameters are specified, the
  34. <<analysis-standard-analyzer,`standard` analyzer>> is used.
  35. [discrete]
  36. [[specify-index-time-field-analyzer]]
  37. ==== Specify the index-time analyzer for a field
  38. Each <<text,`text`>> field in a mapping can specify its own
  39. <<analyzer,`analyzer`>>:
  40. [source,console]
  41. -------------------------
  42. PUT my_index
  43. {
  44. "mappings": {
  45. "properties": {
  46. "title": {
  47. "type": "text",
  48. "analyzer": "standard"
  49. }
  50. }
  51. }
  52. }
  53. -------------------------
  54. [discrete]
  55. [[specify-index-time-default-analyzer]]
  56. ==== Specify a default index-time analyzer
  57. When <<indices-create-index,creating an index>>, you can set a default
  58. index-time analyzer using the `default` analyzer setting:
  59. [source,console]
  60. ----
  61. PUT my_index
  62. {
  63. "settings": {
  64. "analysis": {
  65. "analyzer": {
  66. "default": {
  67. "type": "whitespace"
  68. }
  69. }
  70. }
  71. }
  72. }
  73. ----
  74. A default index-time analyzer is useful when mapping multiple `text` fields that
  75. use the same analyzer. It's also used as a general fallback analyzer for both
  76. index-time and search-time analysis.
  77. [float]
  78. == Search time analysis
  79. This same analysis process is applied to the query string at search time in
  80. <<full-text-queries,full text queries>> like the
  81. <<query-dsl-match-query,`match` query>>
  82. to convert the text in the query string into terms of the same form as those
  83. that are stored in the inverted index.
  84. For instance, a user might search for:
  85. [source,text]
  86. ------
  87. "a quick fox"
  88. ------
  89. which would be analysed by the same `english` analyzer into the following terms:
  90. [source,text]
  91. ------
  92. [ quick, fox ]
  93. ------
  94. Even though the exact words used in the query string don't appear in the
  95. original text (`quick` vs `QUICK`, `fox` vs `foxes`), because we have applied
  96. the same analyzer to both the text and the query string, the terms from the
  97. query string exactly match the terms from the text in the inverted index,
  98. which means that this query would match our example document.
  99. [float]
  100. === Specifying a search time analyzer
  101. Usually the same analyzer should be used both at
  102. index time and at search time, and <<full-text-queries,full text queries>>
  103. like the <<query-dsl-match-query,`match` query>> will use the mapping to look
  104. up the analyzer to use for each field.
  105. The analyzer to use to search a particular field is determined by
  106. looking for:
  107. * An `analyzer` specified in the query itself.
  108. * The <<search-analyzer,`search_analyzer`>> mapping parameter.
  109. * The <<analyzer,`analyzer`>> mapping parameter.
  110. * An analyzer in the index settings called `default_search`.
  111. * An analyzer in the index settings called `default`.
  112. * The `standard` analyzer.
  113. --
  114. include::analysis/overview.asciidoc[]
  115. include::analysis/anatomy.asciidoc[]
  116. include::analysis/testing.asciidoc[]
  117. include::analysis/analyzers.asciidoc[]
  118. include::analysis/normalizers.asciidoc[]
  119. include::analysis/tokenizers.asciidoc[]
  120. include::analysis/tokenfilters.asciidoc[]
  121. include::analysis/charfilters.asciidoc[]