Karesh A
Karesh A

Reputation: 1751

Elastic search combine bool/filter Query

I am trying to search two points in same query like below. but results returning empty.

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

        }

the query working for only one point at a time.

How can I search two points at a time ?

Upvotes: 0

Views: 65

Answers (1)

Val
Val

Reputation: 217514

If you need OR behavior, yo uneed to use bool/should instead:

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

    }

Upvotes: 1

Related Questions