Distance values between the current point and each restaurant

Now, consider the scenario where you need to find the distance between the user location and each restaurant. How can we achieve this requirement? We can use scripts; the current geo coordinates are passed to the script and then the query to find the distance between each restaurant is run, as in the following code. Here, the current location is given as (1, 2):

curl -XPOST 'http://localhost:9200/restaurants/_search?pretty' -d '{
  "script_fields": {
    "distance": {
      "script": "doc['"'"'location'"'"'].arcDistanceInKm(1, 2)"
    }
  },
  "fields": [
    "name"
  ],
  "query": {
    "match": {
      "name": "chinese"
    }
  }
}'

We have used the function called arcDistanceInKm in the preceding query, which accepts the geo ...

Get Elasticsearch Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.