0

Have a problem with this query, when I use geo_distance filter, nothing returned from query. When I remove it I get proper results. Query is bellow:

GET _search
{
 "query": {
  "bool": {
     "filter": {
       "geo_distance": {
          "distance": 20,
          "distance_unit": "km",
          "coordinates": [48.8488576, 2.3354223]
       }  
     },
     "must": {
        "term": {
           "_type": {
              "value": "staff"
           }
        }
     },
     "must_not": [
        {
           "term": {
              "cabinet.zipcode": {
                 "value": "75006"
              }
           }
        },
        {
           "term": {
              "next_availability_in_days": {
                 "value": "-1"
              }
           }
        }
    ]
  }
 }
}

I would appreciate if someone gives me a hint.

UPDATE When I run Elasticsearch Ruby DSL with same query logic, I get proper results:

<Elasticsearch::Model::Searching::SearchRequest:0x007ff335763560
@definition=
{:index=>["development_app_scoped_index_20170428134744", 
"development_app_scoped_index_20170428134744"], :type=>["staff", "light_staff"],
  :body=>
    {:query=>
     {:bool=>
      {:must_not=>[
        {:term=>{"cabinet.zipcode"=>75006}},
        {:term=> {:next_availability_in_days=>-1}}
      ],
      :must=>[
        {:term=>{:_type=>"staff"}}
      ],
      :filter=>{:geo_distance=>
        {:coordinates=>
          {:lat=>48.8488576, :lon=>2.3354223}, 
          :distance=>"6km"
        }
      }}},
  :sort=>[
    {:type=>{:order=>"desc"}},
    {"_geo_distance"=>{"coordinates"=>"48.8488576,2.3354223", "order"=>"asc", 
  "unit"=>"km"}},
    {:next_availability_in_days=>{:order=>"asc"}},
    {:priority=>{:order=>"asc"}}
  ]

}}

So this is really weird and I'm not sure what's going wrong in ES syntax, but it definitely should work as expected. Thanks.

zauzaj
  • 1,206
  • 12
  • 20

1 Answers1

0

There is probably nothing in the range that you have entered. Try to increase the "distance": 20 field to "distance": 500 and check the results then. For example the distance between these two geo points [0,0] and [0,1] is ~138.3414KM .

Another suggestion is to get rid of the "distance_unit" field and put the and put the KM inside the "distance" field as following:

{
  "query": {
    "bool": {
        "filter": {
            "geo_distance": {
                "distance": "20km",
                "coordinates": [
                    48.8488576,
                    2.3354223
                ]
            }
        }
    }
  }
}
RoiHatam
  • 876
  • 10
  • 19
  • Hmm, not sure. There should be. Even if I put 500km nothing changed. But on 1000km there are some results. The whole point is that these are regions in France, and I'm 100% there is some results. Maybe I'm doing something wrong in my query ordering ? – zauzaj May 04 '17 at 19:53
  • I already tried that, no change. It's very weird, but maybe your comment was correct that there is really no data in requested distance. – zauzaj May 05 '17 at 10:31
  • I updated my question, @RoiHatam if you can check please ? – zauzaj May 05 '17 at 12:26