【问题标题】:Elastic Search Multi Geo Points弹性搜索多地理点
【发布时间】:2017-01-18 13:04:50
【问题描述】:

现在寻找一下,看看这是否可能。

我在 es 中有文档,它们的映射中有两个地理点。

  1. originGeo
  2. 目的地地理位置

我正在寻找创建一个查询,我可以找到距离 originGeo x 英里和destinationGeo y 英里内的所有文档。

我目前正在尝试以下几种不同的方式:

1

这不是我想要的,因为它使用每个地理点的相同距离。但是,它似乎也只返回与destinationGeo 相关的文档。

{
    "query": {
        "filtered": {
            "filter": {
                "bool": {
                    "must": [],
                    "must_not": [{
                        "term": {
                            "system": "boo"
                        }
                    }]
                }
            },
            "query": {
                "filtered": {
                    "filter": {
                        "geo_distance": {
                            "distance": "1mi",
                            "originGeo": {
                                "lat": 33.9962144,
                                "lon": -118.46887759999998
                            },
                            "destinationGeo": {
                                "lat": 34.0348144,
                                "lon": -117.58480250000002
                            }
                        }
                    }
                }
            }
        }
    }
}

2

这会导致解析错误:过滤器格式错误,start_object 后没有字段

{
    "query": {
        "filtered": {
            "filter": {
                "bool": {
                    "must": [],
                    "must_not": [{
                        "term": {
                            "system": "boo"
                        }
                    }]
                },
                "geo_distance": {
                    "distance": "1mi",
                    "originGeo": {
                        "lat": 33.9962144,
                        "lon": -118.46887759999998
                    },
                    "destinationGeo": {
                        "lat": 34.0348144,
                        "lon": -117.58480250000002
                    }
                }
            }
        }
    }
}

一如既往地感谢任何帮助!

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    ES 2.x 及更高版本的以下查询应该满足您的需要

    {
      "query": {
        "bool": {
          "filter": [
            {
              "geo_distance": {
                "distance": "1mi",
                "originGeo": {
                  "lat": 33.9962144,
                  "lon": -118.46887759999998
                }
              }
            },
            {
              "geo_distance": {
                "distance": "1mi",
                "destinationGeo": {
                  "lat": 34.0348144,
                  "lon": -117.58480250000002
                }
              }
            }
          ],
          "must_not": [
            {
              "term": {
                "system": "boo"
              }
            }
          ]
        }
      }
    }
    

    如果你在 ES 1.x 上运行,那么你可以使用这个:

    {
      "query": {
        "filtered": {
          "filter": {
            "bool": {
              "must": [
                {
                  "geo_distance": {
                    "distance": "1mi",
                    "originGeo": {
                      "lat": 33.9962144,
                      "lon": -118.46887759999998
                    }
                  }
                },
                {
                  "geo_distance": {
                    "distance": "1mi",
                    "destinationGeo": {
                      "lat": 34.0348144,
                      "lon": -117.58480250000002
                    }
                  }
                }
              ],
              "must_not": [
                {
                  "term": {
                    "system": "boo"
                  }
                }
              ]
            }
          }
        }
      }
    }
    

    【讨论】:

    • 嗨 Val,非常感谢您的帮助!我被其他事情分心了,但是,这似乎没有帮助:nested: QueryParsingException[[myindex] bool query does not support [filter]]; }]"
    • 好的,这意味着您仍在使用 ES 1.x,对吧?在这种情况下,您可以在我的回答中使用第二个查询。
    • 太棒了,很高兴它有帮助!
    猜你喜欢
    • 2016-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-23
    • 1970-01-01
    • 2012-03-06
    相关资源
    最近更新 更多