ElasticSearch — use distance from point to affect query relevance

后端 未结 2 1867
醉酒成梦
醉酒成梦 2021-02-08 03:19

Trying to use ElasticSearch to create a search that uses distance from a centerpoint to influence relevance.

I don\'t want to simply sort on distance from a point, which

相关标签:
2条回答
  • 2021-02-08 03:24

    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.

    0 讨论(0)
  • 2021-02-08 03:31

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

    0 讨论(0)
提交回复
热议问题