弹性搜索结合bool / filter Query

时间:2017-09-20 11:59:35

标签: elasticsearch elasticsearch-5

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

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

        }

查询一次只能处理一个点。

我如何一次搜索两个点?

1 个答案:

答案 0 :(得分: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"
                    }
                }
            }
            ]
        }

    }