2013-08-28 19:24:34 -04:00
[[index-modules-similarity]]
== Similarity module
A similarity (scoring / ranking model) defines how matching documents
are scored. Similarity is per field, meaning that via the mapping one
can define a different similarity per field.
Configuring a custom similarity is considered a expert feature and the
2015-08-06 11:24:29 -04:00
builtin similarities are most likely sufficient as is described in
<<similarity>>.
2013-08-28 19:24:34 -04:00
[float]
2013-09-25 12:17:40 -04:00
[[configuration]]
2013-08-28 19:24:34 -04:00
=== Configuring a similarity
Most existing or custom Similarities have configuration options which
can be configured via the index settings as shown below. The index
options can be provided when creating an index or updating index
settings.
[source,js]
--------------------------------------------------
"similarity" : {
"my_similarity" : {
"type" : "DFR",
"basic_model" : "g",
"after_effect" : "l",
"normalization" : "h2",
"normalization.h2.c" : "3.0"
}
}
--------------------------------------------------
Here we configure the DFRSimilarity so it can be referenced as
`my_similarity` in mappings as is illustrate in the below example:
[source,js]
--------------------------------------------------
{
"book" : {
"properties" : {
"title" : { "type" : "string", "similarity" : "my_similarity" }
}
2015-08-06 11:24:29 -04:00
}
2013-08-28 19:24:34 -04:00
--------------------------------------------------
[float]
=== Available similarities
[float]
2015-12-15 06:07:07 -05:00
[[classic-similarity]]
==== Classic similarity
2013-08-28 19:24:34 -04:00
2015-12-15 06:07:07 -05:00
The classic similarity that is based on the TF/IDF model. This
2015-08-06 11:24:29 -04:00
similarity has the following option:
2013-08-28 19:24:34 -04:00
2015-08-06 11:24:29 -04:00
`discount_overlaps`::
2013-08-28 19:24:34 -04:00
Determines whether overlap tokens (Tokens with
0 position increment) are ignored when computing norm. By default this
is true, meaning overlap tokens do not count when computing norms.
2015-12-15 06:07:07 -05:00
Type name: `classic`
2013-08-28 19:24:34 -04:00
[float]
2013-09-25 12:17:40 -04:00
[[bm25]]
2013-08-28 19:24:34 -04:00
==== BM25 similarity
Another TF/IDF based similarity that has built-in tf normalization and
is supposed to work better for short fields (like names). See
http://en.wikipedia.org/wiki/Okapi_BM25[Okapi_BM25] for more details.
This similarity has the following options:
[horizontal]
2015-08-06 11:24:29 -04:00
`k1`::
2013-08-28 19:24:34 -04:00
Controls non-linear term frequency normalization
2015-08-06 11:24:29 -04:00
(saturation).
2013-08-28 19:24:34 -04:00
2015-08-06 11:24:29 -04:00
`b`::
Controls to what degree document length normalizes tf values.
2013-08-28 19:24:34 -04:00
2015-08-06 11:24:29 -04:00
`discount_overlaps`::
2013-08-28 19:24:34 -04:00
Determines whether overlap tokens (Tokens with
0 position increment) are ignored when computing norm. By default this
is true, meaning overlap tokens do not count when computing norms.
Type name: `BM25`
[float]
2013-09-25 12:17:40 -04:00
[[drf]]
2014-02-13 10:45:30 -05:00
==== DFR similarity
2013-08-28 19:24:34 -04:00
Similarity that implements the
2015-08-06 11:24:29 -04:00
http://lucene.apache.org/core/5_2_1/core/org/apache/lucene/search/similarities/DFRSimilarity.html[divergence
2013-08-28 19:24:34 -04:00
from randomness] framework. This similarity has the following options:
[horizontal]
2015-08-06 11:24:29 -04:00
`basic_model`::
Possible values: `be`, `d`, `g`, `if`, `in`, `ine` and `p`.
2013-08-28 19:24:34 -04:00
`after_effect`::
2015-08-06 11:24:29 -04:00
Possible values: `no`, `b` and `l`.
2013-08-28 19:24:34 -04:00
2015-08-06 11:24:29 -04:00
`normalization`::
2013-08-28 19:24:34 -04:00
Possible values: `no`, `h1`, `h2`, `h3` and `z`.
All options but the first option need a normalization value.
Type name: `DFR`
[float]
2013-09-25 12:17:40 -04:00
[[ib]]
2013-08-28 19:24:34 -04:00
==== IB similarity.
2015-08-06 11:24:29 -04:00
http://lucene.apache.org/core/5_2_1/core/org/apache/lucene/search/similarities/IBSimilarity.html[Information
2015-12-14 08:27:40 -05:00
based model] . The algorithm is based on the concept that the information content in any symbolic 'distribution'
sequence is primarily determined by the repetitive usage of its basic elements.
For written texts this challenge would correspond to comparing the writing styles of diferent authors.
This similarity has the following options:
2013-08-28 19:24:34 -04:00
[horizontal]
2015-08-06 11:24:29 -04:00
`distribution`:: Possible values: `ll` and `spl`.
`lambda`:: Possible values: `df` and `ttf`.
2013-08-28 19:24:34 -04:00
`normalization`:: Same as in `DFR` similarity.
Type name: `IB`
2014-04-06 22:20:46 -04:00
[float]
[[lm_dirichlet]]
==== LM Dirichlet similarity.
2015-08-06 11:24:29 -04:00
http://lucene.apache.org/core/5_2_1/core/org/apache/lucene/search/similarities/LMDirichletSimilarity.html[LM
2014-04-06 22:20:46 -04:00
Dirichlet similarity] . This similarity has the following options:
[horizontal]
`mu`:: Default to `2000`.
Type name: `LMDirichlet`
[float]
[[lm_jelinek_mercer]]
==== LM Jelinek Mercer similarity.
2015-08-06 11:24:29 -04:00
http://lucene.apache.org/core/5_2_1/core/org/apache/lucene/search/similarities/LMJelinekMercerSimilarity.html[LM
2015-12-14 08:27:40 -05:00
Jelinek Mercer similarity] . The algorithm attempts to capture important patterns in the text, while leaving out noise. This similarity has the following options:
2014-04-06 22:20:46 -04:00
[horizontal]
`lambda`:: The optimal value depends on both the collection and the query. The optimal value is around `0.1`
2015-12-14 08:27:40 -05:00
for title queries and `0.7` for long queries. Default to `0.1`. When value approaches `0`, documents that match more query terms will be ranked higher than those that match fewer terms.
2014-04-06 22:20:46 -04:00
Type name: `LMJelinekMercer`
2013-08-28 19:24:34 -04:00
[float]
2013-09-30 17:32:00 -04:00
[[default-base]]
2013-08-28 19:24:34 -04:00
==== Default and Base Similarities
By default, Elasticsearch will use whatever similarity is configured as
`default`. However, the similarity functions `queryNorm()` and `coord()`
are not per-field. Consequently, for expert users wanting to change the
implementation used for these two methods, while not changing the
`default`, it is possible to configure a similarity with the name
`base`. This similarity will then be used for the two methods.
2015-11-19 19:41:29 -05:00
You can change the default similarity for all fields by putting the following setting into `elasticsearch.yml`:
2013-08-28 19:24:34 -04:00
[source,js]
--------------------------------------------------
index.similarity.default.type: BM25
--------------------------------------------------