ElasticSearch — use distance from point to affect query relevance

僤鯓⒐⒋嵵緔 提交于 2019-12-03 07:19:36

You can use distance function in the script of the Custom Score Query to modify _score based on the distance from a centerpoint.

The recently (0.90.4) added function_score query type adds support for ranking based on distance. This is an alternative to the custom score query type.

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-function-score-query.html

An example lifted from there:

"query": {
  "function_score": {
    "functions": [
      { "gauss":  { "loc":   { "origin": "51,0", "scale": "5km" }}},
    ]
  }
}

This applies a decay function (there are several) to a field ("loc") that scores against the distance from an origin given a particular scale. This is exactly what you'd want for distance ranking since it gives you a lot of flexibility to how it should rank without writing custom scripts.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!