2013-08-28 19:24:34 -04:00
|
|
|
[[analysis]]
|
|
|
|
= Analysis
|
|
|
|
|
|
|
|
[partintro]
|
|
|
|
--
|
|
|
|
|
2016-05-11 08:17:56 -04:00
|
|
|
_Analysis_ is the process of converting text, like the body of any email, into
|
|
|
|
_tokens_ or _terms_ which are added to the inverted index for searching.
|
|
|
|
Analysis is performed by an <<analysis-analyzers,_analyzer_>> which can be
|
|
|
|
either a built-in analyzer or a <<analysis-custom-analyzer,`custom`>> analyzer
|
|
|
|
defined per index.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2016-05-11 08:17:56 -04:00
|
|
|
[float]
|
|
|
|
== Index time analysis
|
|
|
|
|
|
|
|
For instance at index time, the built-in <<english-analyzer,`english`>> _analyzer_ would
|
|
|
|
convert this sentence:
|
|
|
|
|
|
|
|
[source,text]
|
|
|
|
------
|
|
|
|
"The QUICK brown foxes jumped over the lazy dog!"
|
|
|
|
------
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2016-05-11 08:17:56 -04:00
|
|
|
into these terms, which would be added to the inverted index.
|
|
|
|
|
|
|
|
[source,text]
|
|
|
|
------
|
|
|
|
[ quick, brown, fox, jump, over, lazi, dog ]
|
|
|
|
------
|
|
|
|
|
|
|
|
[float]
|
|
|
|
=== Specifying an index time analyzer
|
|
|
|
|
|
|
|
Each <<text,`text`>> field in a mapping can specify its own
|
|
|
|
<<analyzer,`analyzer`>>:
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[source,js]
|
2016-05-11 08:17:56 -04:00
|
|
|
-------------------------
|
|
|
|
PUT my_index
|
|
|
|
{
|
|
|
|
"mappings": {
|
|
|
|
"my_type": {
|
|
|
|
"properties": {
|
|
|
|
"title": {
|
|
|
|
"type": "text",
|
|
|
|
"analyzer": "standard"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
-------------------------
|
|
|
|
// CONSOLE
|
|
|
|
|
|
|
|
At index time, if no `analyzer` has been specified, it looks for an analyzer
|
|
|
|
in the index settings called `default`. Failing that, it defaults to using
|
|
|
|
the <<analysis-standard-analyzer,`standard` analyzer>>.
|
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[float]
|
2016-05-11 08:17:56 -04:00
|
|
|
== Search time analysis
|
|
|
|
|
|
|
|
This same analysis process is applied to the query string at search time in
|
|
|
|
<<full-text-queries,full text queries>> like the
|
|
|
|
<<query-dsl-match-query,`match` query>>
|
|
|
|
to convert the text in the query string into terms of the same form as those
|
|
|
|
that are stored in the inverted index.
|
|
|
|
|
|
|
|
For instance, a user might search for:
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2016-05-11 08:17:56 -04:00
|
|
|
[source,text]
|
|
|
|
------
|
|
|
|
"a quick fox"
|
|
|
|
------
|
|
|
|
|
|
|
|
which would be analysed by the same `english` analyzer into the following terms:
|
|
|
|
|
|
|
|
[source,text]
|
|
|
|
------
|
|
|
|
[ quick, fox ]
|
|
|
|
------
|
|
|
|
|
|
|
|
Even though the exact words used in the query string don't appear in the
|
|
|
|
original text (`quick` vs `QUICK`, `fox` vs `foxes`), because we have applied
|
|
|
|
the same analyzer to both the text and the query string, the terms from the
|
|
|
|
query string exactly match the terms from the text in the inverted index,
|
|
|
|
which means that this query would match our example document.
|
|
|
|
|
|
|
|
[float]
|
|
|
|
=== Specifying a search time analyzer
|
|
|
|
|
|
|
|
Usually the same analyzer should be used both at
|
|
|
|
index time and at search time, and <<full-text-queries,full text queries>>
|
|
|
|
like the <<query-dsl-match-query,`match` query>> will use the mapping to look
|
|
|
|
up the analyzer to use for each field.
|
|
|
|
|
|
|
|
The analyzer to use to search a particular field is determined by
|
|
|
|
looking for:
|
|
|
|
|
|
|
|
* An `analyzer` specified in the query itself.
|
|
|
|
* The <<search-analyzer,`search_analyzer`>> mapping parameter.
|
|
|
|
* The <<analyzer,`analyzer`>> mapping parameter.
|
|
|
|
* An analyzer in the index settings called `default_search`.
|
|
|
|
* An analyzer in the index settings called `default`.
|
|
|
|
* The `standard` analyzer.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
--
|
|
|
|
|
2016-05-11 08:17:56 -04:00
|
|
|
include::analysis/anatomy.asciidoc[]
|
|
|
|
|
|
|
|
include::analysis/testing.asciidoc[]
|
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
include::analysis/analyzers.asciidoc[]
|
|
|
|
|
2016-12-30 03:36:10 -05:00
|
|
|
include::analysis/normalizers.asciidoc[]
|
|
|
|
|
2013-08-28 19:24:34 -04:00
|
|
|
include::analysis/tokenizers.asciidoc[]
|
|
|
|
|
|
|
|
include::analysis/tokenfilters.asciidoc[]
|
|
|
|
|
|
|
|
include::analysis/charfilters.asciidoc[]
|
|
|
|
|