GeoDistance Query Error - ES 5.0

Hi Everyone,

I want to implement proximity search in ES 5.0.0 using Geo-Distance queries. The syntax is the same as specified in the ES 5.0 documentation but still I am getting an error.
Looking forward to get help on this .....

My Query (testsfdc is my index which stores all customer records with a field location(lat,lon)

GET /testsfdc/_search
{
  "query": {
      "bool": {
          "must": [
             {"match_all": {}}
          ]
      },
      "filter":{
          "geo_distance": {
             "distance": 10,
             "distance_unit": "km",
             "location": {
                "lat": 50.4724833,
                "lon": 4.8179051
             }
          }
      }
  }  
} 

Error -

{
   "error": {
      "root_cause": [
         {
            "type": "parsing_exception",
            "reason": "[bool] malformed query, unexpected [FIELD_NAME] found [filter]",
            "line": 8,
            "col": 7
         }
      ],
      "type": "parsing_exception",
      "reason": "[bool] malformed query, unexpected [FIELD_NAME] found [filter]",
      "line": 8,
      "col": 7
   },
   "status": 400
}

I know the error says syntax before "filter" is wrong but I tried playing around but in vain.

Thanks in advance,
Surbi

Please format your code using </> icon. It will make your post more readable.
I updated your question.

filter should be inside bool and not outside. See https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html

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