0

此查询有问题,当我使用 geo_distance 过滤器时,查询没有返回任何内容。当我删除它时,我会得到正确的结果。查询如下:

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"
              }
           }
        }
    ]
  }
 }
}

如果有人给我提示,我将不胜感激。

更新 当我使用相同的查询逻辑运行 Elasticsearch Ruby DSL 时,我得到了正确的结果:

<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"}}
  ]

}}

所以这真的很奇怪,我不确定 ES 语法出了什么问题,但它肯定应该按预期工作。谢谢。

4

1 回答 1

0

您输入的范围内可能没有任何内容。尝试将"distance": 20字段增加到"distance": 500并检查结果。例如,这两个地理点 [0,0] 和 [0,1] 之间的距离是 ~138.3414KM 。

另一个建议是去掉该"distance_unit"字段并将 KM 放入该"distance"字段中,如下所示:

{
  "query": {
    "bool": {
        "filter": {
            "geo_distance": {
                "distance": "20km",
                "coordinates": [
                    48.8488576,
                    2.3354223
                ]
            }
        }
    }
  }
}
于 2017-05-04T18:36:27.983 回答