analysis.asciidoc 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. [[analysis]]
  2. = Analysis
  3. [partintro]
  4. --
  5. _Analysis_ is the process of converting text, like the body of any email, into
  6. _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. === Specifying an index time analyzer
  28. Each <<text,`text`>> field in a mapping can specify its own
  29. <<analyzer,`analyzer`>>:
  30. [source,js]
  31. -------------------------
  32. PUT my_index
  33. {
  34. "mappings": {
  35. "_doc": {
  36. "properties": {
  37. "title": {
  38. "type": "text",
  39. "analyzer": "standard"
  40. }
  41. }
  42. }
  43. }
  44. }
  45. -------------------------
  46. // CONSOLE
  47. At index time, if no `analyzer` has been specified, it looks for an analyzer
  48. in the index settings called `default`. Failing that, it defaults to using
  49. the <<analysis-standard-analyzer,`standard` analyzer>>.
  50. [float]
  51. == Search time analysis
  52. This same analysis process is applied to the query string at search time in
  53. <<full-text-queries,full text queries>> like the
  54. <<query-dsl-match-query,`match` query>>
  55. to convert the text in the query string into terms of the same form as those
  56. that are stored in the inverted index.
  57. For instance, a user might search for:
  58. [source,text]
  59. ------
  60. "a quick fox"
  61. ------
  62. which would be analysed by the same `english` analyzer into the following terms:
  63. [source,text]
  64. ------
  65. [ quick, fox ]
  66. ------
  67. Even though the exact words used in the query string don't appear in the
  68. original text (`quick` vs `QUICK`, `fox` vs `foxes`), because we have applied
  69. the same analyzer to both the text and the query string, the terms from the
  70. query string exactly match the terms from the text in the inverted index,
  71. which means that this query would match our example document.
  72. [float]
  73. === Specifying a search time analyzer
  74. Usually the same analyzer should be used both at
  75. index time and at search time, and <<full-text-queries,full text queries>>
  76. like the <<query-dsl-match-query,`match` query>> will use the mapping to look
  77. up the analyzer to use for each field.
  78. The analyzer to use to search a particular field is determined by
  79. looking for:
  80. * An `analyzer` specified in the query itself.
  81. * The <<search-analyzer,`search_analyzer`>> mapping parameter.
  82. * The <<analyzer,`analyzer`>> mapping parameter.
  83. * An analyzer in the index settings called `default_search`.
  84. * An analyzer in the index settings called `default`.
  85. * The `standard` analyzer.
  86. --
  87. include::analysis/anatomy.asciidoc[]
  88. include::analysis/testing.asciidoc[]
  89. include::analysis/analyzers.asciidoc[]
  90. include::analysis/normalizers.asciidoc[]
  91. include::analysis/tokenizers.asciidoc[]
  92. include::analysis/tokenfilters.asciidoc[]
  93. include::analysis/charfilters.asciidoc[]