1
0

similarity.asciidoc 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. [[index-modules-similarity]]
  2. == Similarity module
  3. A similarity (scoring / ranking model) defines how matching documents
  4. are scored. Similarity is per field, meaning that via the mapping one
  5. can define a different similarity per field.
  6. Configuring a custom similarity is considered a expert feature and the
  7. builtin similarities are most likely sufficient as is described in the
  8. <<mapping-core-types,mapping section>>
  9. [float]
  10. === Configuring a similarity
  11. Most existing or custom Similarities have configuration options which
  12. can be configured via the index settings as shown below. The index
  13. options can be provided when creating an index or updating index
  14. settings.
  15. [source,js]
  16. --------------------------------------------------
  17. "similarity" : {
  18. "my_similarity" : {
  19. "type" : "DFR",
  20. "basic_model" : "g",
  21. "after_effect" : "l",
  22. "normalization" : "h2",
  23. "normalization.h2.c" : "3.0"
  24. }
  25. }
  26. --------------------------------------------------
  27. Here we configure the DFRSimilarity so it can be referenced as
  28. `my_similarity` in mappings as is illustrate in the below example:
  29. [source,js]
  30. --------------------------------------------------
  31. {
  32. "book" : {
  33. "properties" : {
  34. "title" : { "type" : "string", "similarity" : "my_similarity" }
  35. }
  36. }
  37. --------------------------------------------------
  38. [float]
  39. === Available similarities
  40. [float]
  41. ==== Default similarity
  42. The default similarity that is based on the TF/IDF model. This
  43. similarity has the following option:
  44. `discount_overlaps`::
  45. Determines whether overlap tokens (Tokens with
  46. 0 position increment) are ignored when computing norm. By default this
  47. is true, meaning overlap tokens do not count when computing norms.
  48. Type name: `default`
  49. [float]
  50. ==== BM25 similarity
  51. Another TF/IDF based similarity that has built-in tf normalization and
  52. is supposed to work better for short fields (like names). See
  53. http://en.wikipedia.org/wiki/Okapi_BM25[Okapi_BM25] for more details.
  54. This similarity has the following options:
  55. [horizontal]
  56. `k1`::
  57. Controls non-linear term frequency normalization
  58. (saturation).
  59. `b`::
  60. Controls to what degree document length normalizes tf values.
  61. `discount_overlaps`::
  62. Determines whether overlap tokens (Tokens with
  63. 0 position increment) are ignored when computing norm. By default this
  64. is true, meaning overlap tokens do not count when computing norms.
  65. Type name: `BM25`
  66. [float]
  67. ==== DRF similarity
  68. Similarity that implements the
  69. http://lucene.apache.org/core/4_1_0/core/org/apache/lucene/search/similarities/DFRSimilarity.html[divergence
  70. from randomness] framework. This similarity has the following options:
  71. [horizontal]
  72. `basic_model`::
  73. Possible values: `be`, `d`, `g`, `if`, `in`, `ine` and `p`.
  74. `after_effect`::
  75. Possible values: `no`, `b` and `l`.
  76. `normalization`::
  77. Possible values: `no`, `h1`, `h2`, `h3` and `z`.
  78. All options but the first option need a normalization value.
  79. Type name: `DFR`
  80. [float]
  81. ==== IB similarity.
  82. http://lucene.apache.org/core/4_1_0/core/org/apache/lucene/search/similarities/IBSimilarity.html[Information
  83. based model] . This similarity has the following options:
  84. [horizontal]
  85. `distribution`:: Possible values: `ll` and `spl`.
  86. `lambda`:: Possible values: `df` and `ttf`.
  87. `normalization`:: Same as in `DFR` similarity.
  88. Type name: `IB`
  89. [float]
  90. ==== Default and Base Similarities
  91. By default, Elasticsearch will use whatever similarity is configured as
  92. `default`. However, the similarity functions `queryNorm()` and `coord()`
  93. are not per-field. Consequently, for expert users wanting to change the
  94. implementation used for these two methods, while not changing the
  95. `default`, it is possible to configure a similarity with the name
  96. `base`. This similarity will then be used for the two methods.
  97. You can change the default similarity for all fields like this:
  98. [source,js]
  99. --------------------------------------------------
  100. index.similarity.default.type: BM25
  101. --------------------------------------------------