Counting documents with both text matching and distance to a point

I have an ElasticSearch index with a list of "stores."

I want to allow customers to search for these stores both using geo_distance(so finding a point and getting stores near this place), and text matching, for example, matching the store’s name / address.

I would like to get results that meet one of these two criteria, and I would like the order of these results to be a combination of both. The stronger the text match and the closer to the point found, the higher the result. (Obviously, there will be a formula for combining the two, which need to be set up and not too worried about this part).

My problem / what I tried:

  • geo_distanceis filter, and not query, therefore I cannot combine both in parts of queryrequest.

  • I can use a filter bool => should(rather than a query) that matches the name or location. This gives me the results that I want, but not in order.

  • I can also have, _geo_distanceas part of the proposal sort, documents closer to the ranking point above.

What I did not understand is how I take the “regular” _scorethat ElasticSearch provides to documents when performing text matches, and combine this with the rating geo_distance.

, , , ( ). , query geo_distance filter, OR, AND.

, :

{
  function_score: {
    query: {  ... },
    functions: [
      { geo_distance function },
      { multi_match_result score },
    ],
    score_mode: 'multiply'
  }
}

, geo_distance , , multi_match_result score , .

.

ElasticSearch v1.4, .

+4
1

, geo_distance , , multi_match_result .

, , , , . , .

, / , , function_score, , . , , , , - , . / , . , - , , , /.

. , date s, - - geo_point s. , , , , . , , , , "". gauss.

"function_score": {
  "functions": [
    "gauss": {
      "my_geo_point_field": {
        "origin": "0, 1",
        "scale": "5km",
        "offset": "500m",
        "decay": 0.5
      }
    }
  ]
}

, origin x, y (- GeoJSON), longitude, latitude.

Decay

, ( ). 0, , . .

scale decay , decay, scale - origin (+/- the offset). 5km origin - origin.

, .

, .

bool/should. OR , . , - :

{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": { ... }
        },
        {
          "function_score": {
            "functions": [
              "gauss": {
                "my_geo_point_field": {
                  "origin": "0, 1",
                  "scale": "5km",
                  "offset": "500m",
                  "decay": 0.5
                }
              }
            ]
          }
        }
      ]
    }
  }
}

. must, should OR- ( , 1 ) ( ).

ElasticSearch v1.4, .

Elasticsearch 2.0, , . - , . , , , .

, Geo, ES 2.2+. ( ), . ES 5.0 !

+5

All Articles