similarity.asciidoc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. [[similarity]]
  2. === `similarity`
  3. {es} allows you to configure a text scoring algorithm or _similarity_
  4. per field. The `similarity` setting provides a simple way of choosing a
  5. text similarity algorithm other than the default `BM25`, such as `boolean`.
  6. Only text-based field types like <<text,`text`>> and <<keyword,`keyword`>>
  7. support this configuration.
  8. Custom similarities can be configured by tuning the parameters of the built-in
  9. similarities. For more details about this expert options, see the
  10. <<index-modules-similarity,similarity module>>.
  11. The only similarities which can be used out of the box, without any further
  12. configuration are:
  13. `BM25`::
  14. The {wikipedia}/Okapi_BM25[Okapi BM25 algorithm]. The
  15. algorithm used by default in {es} and Lucene.
  16. `boolean`::
  17. A simple boolean similarity, which is used when full-text ranking is not needed
  18. and the score should only be based on whether the query terms match or not.
  19. Boolean similarity gives terms a score equal to their query boost.
  20. The `similarity` can be set on the field level when a field is first created,
  21. as follows:
  22. [source,console]
  23. --------------------------------------------------
  24. PUT my-index-000001
  25. {
  26. "mappings": {
  27. "properties": {
  28. "default_field": { <1>
  29. "type": "text"
  30. },
  31. "boolean_sim_field": {
  32. "type": "text",
  33. "similarity": "boolean" <2>
  34. }
  35. }
  36. }
  37. }
  38. --------------------------------------------------
  39. <1> The `default_field` uses the `BM25` similarity.
  40. <2> The `boolean_sim_field` uses the `boolean` similarity.