【问题标题】:geo_distance doesn't return any hit Elasticsearchgeo_distance 不返回任何命中 Elasticsearch
【发布时间】:2017-05-04 18:20:59
【问题描述】:

这个查询有问题,当我使用 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 语法出了什么问题,但它肯定可以按预期工作。 谢谢。

【问题讨论】:

    标签: elasticsearch elasticsearch-rails


    【解决方案1】:

    您输入的范围内可能没有任何内容。 尝试将"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
                    ]
                }
            }
        }
      }
    }
    

    【讨论】:

    • 嗯,不确定。应该有。即使我跑了 500 公里,也没有任何改变。但是在 1000 公里上有一些结果。重点是这些是法国的地区,我 100% 有一些结果。也许我在查询顺序中做错了什么?
    • 我已经试过了,没有改变。这很奇怪,但也许您的评论是正确的,在请求的距离内确实没有数据。
    • 我更新了我的问题,@RoiHatam 是否可以检查一下?
    猜你喜欢
    • 1970-01-01
    • 2016-11-24
    • 1970-01-01
    • 2011-12-25
    • 2021-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多