I need to query restaurants scoring by match +distance

I need to query restaurants scoring by match +distance here is what I want

Example Data field “restaurant name”:burger(nearest) , BurgerA

Case 1 if in put is “burger” The result must be

1.Burger (Nearest)

2.Burger A

.

Case 2 if in put is “Burger A” the first must be

1.Burger A

2.Burger (Nearest)

So please let guide me how implementing by Elasticsearch

++++upupup

Hi, You just showed an example and the scoring algorithm is unclear. You need clarify both the filtering condition and ranking algorithm to construct the query.Why "Burger A" comes in the second position in Case 1? Where the second nearest burger shop should be??

What will happen if there is "Coffee Stand A" in Case 2??

In most cases complex ranking rules could be implemented by function score query, but in some cases it is better to use two queries and merge two results by client side.

Thank you for you quick response
So we are food delivery application we would like client searching restaurant match as much as we can
Example is we have Clint origin geo point at "0"
And we have 4 Restaurant

1.Restaurant name "Burger" geo points at"1"

2.Restaurant name "Burger 2" geo points at"2"

3.Restaurant name "Burger3" geo points at"3"

4.Restaurant name "A Burger" geo points at"4"

(Geo point prioritize according 0>1>2>3>4

scenario1: client search "Burger"
Result:
1.Restaurant name "Burger" geo points at"1"
2.Restaurant name "Burger 2" geo points at"2"
3.Restaurant name "Burger3" geo points at"3"
4.Restaurant name "Burger A" geo points at"4"

scenario2: client search "A Burger"
Result:
1.Restaurant name "Burger A" geo points at"4"
1.Restaurant name "Burger" geo points at"1"
2.Restaurant name "Burger 2" geo points at"2"
3.Restaurant name "Burger3" geo points at"3"

Our logic is if client search by regular name result must prioritize by distance more than matching
If client search by specific name result must prioritize by matching more than distance

I've not understood the entire rule, but how about something like this?


GET test_function_score/_search
{
  "query":{
    "bool":{
      "should":[
        {
          "bool":{
            "must":{
              "distance_feature":{
                "field":"position",
                "pivot": "100km",
                "origin": [0,0]
              }
            },
            "filter":{
              "match":{
                "name": "A Burger"
              }
            }
          }
        },
        {
          "match_phrase":{
            "name": "A Burger"
          }
        }]
    }
  }
}
1 Like

Thank you sir for you favor.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.