David Kullmann
David Kullmann

Reputation: 918

ElasticSearch returns items that are too far away when using a geo_distance filter

When I am searching my ElasticSearch documents using a nested filter -> and -> geo_distance I retrieve documents which are too far away (and I don't want returned.) You can see the query and a screenshot below of the results (raw results on the left and manually filtered results on the right).

enter image description here

Here's another copy of the query:

{
   "query":{
      "match_all":{

      }
   },
   "filter":{
      "and":[
         {
            "term":{
               "PropertySubType":"Single Family"
            }
         },
         {
            "term":{
               "City":"Los Angeles"
            }
         },
         {
            "geo_distance":{
               "distance":"2.25miles",
               "Location":[
                  34.111583657,
                  -118.324646099
               ]
            }
         },
         {
            "range":{
               "BedroomsTotal":{
                  "gte":3
               }
            }
         },   
         {    
            "range":{
               "BuildingSize":{
                  "gte":3000
               }
            }
         },
         {    
            "range":{
               "YearBuilt":{
                  "lte":2000
               }
            }
         },
         {    
            "terms":{
               "ListingStatus":[
                  "Active",
                  "Pending",
                  "Closed"
               ]
            } 
         } 
      ] 
   },
   "size":100
}       

Upvotes: 1

Views: 2004

Answers (1)

David Kullmann
David Kullmann

Reputation: 918

Adding the option "distance_type" and setting it to "plane" fixed this issue. See "distance_type" here:

http://www.elasticsearch.org/guide/reference/query-dsl/geo-distance-filter.html

Upvotes: 2

Related Questions