【问题标题】:Elastic search combine bool/filter Query弹性搜索结合 bool/filter 查询
【发布时间】:2017-09-20 20:17:35
【问题描述】:

我正在尝试在同一个查询中搜索两个点,如下所示。 但结果返回空。

"query": {
            "bool": {
                "must": {
                    "match_all": {}
                },
                "filter": [{
                    "geo_shape": {
                        "border": {
                            "shape": {
                                "type": "point",
                                "coordinates": [longitude1, latitude1]
                            },
                            "relation": "intersects"
                        }
                    }
                }, {
                    "geo_shape": {
                        "border": {
                            "shape": {
                                "type": "point",
                                "coordinates": [longitude2, latitude2]
                            },
                            "relation": "intersects"
                        }
                    }
                }
                ]
            }

        }

查询一次只工作一个点。

如何一次搜索两个点?

【问题讨论】:

  • 我还在查询块中尝试了两个布尔查询。那也是空的
  • 两个点需要匹配还是只需要其中一个匹配?
  • 结果应该是 OR。如果一个多边形上的一个点和另一个多边形上的一个点,查询应该返回两个多边形 ID。如果它在同一个多边形中,查询可以返回两个具有相同 id 或一个的结果。

标签: elasticsearch elasticsearch-5


【解决方案1】:

如果你需要 OR 行为,你不需要使用 bool/should 来代替:

"query": {
        "bool": {
            "should": [{                <--- change this
                "geo_shape": {
                    "border": {
                        "shape": {
                            "type": "point",
                            "coordinates": [longitude1, latitude1]
                        },
                        "relation": "intersects"
                    }
                }
            }, {
                "geo_shape": {
                    "border": {
                        "shape": {
                            "type": "point",
                            "coordinates": [longitude2, latitude2]
                        },
                        "relation": "intersects"
                    }
                }
            }
            ]
        }

    }

【讨论】:

  • 酷,很高兴它有帮助!
猜你喜欢
  • 2020-04-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-22
  • 2018-01-13
  • 2014-11-09
相关资源
最近更新 更多