G
G
German Zvonchuk2018-11-18 00:43:35
elasticsearch
German Zvonchuk, 2018-11-18 00:43:35

How to use geo_distance and geo_bounding_box in the same request?

Goodnight.
I would be very grateful if you tell me how it is possible to use geo_distance and geo_bounding_box within one request in one request?
I have such a query where I pull out data from the index within a radius of 1km from the specified point.

{
  "from": 0,
  "size": 10,
  "query": {
    "bool": {
      "filter": {
        "geo_distance": {
          "distance": "1km",
          "location": "40.5586,49.6971"
        }
      }
    }
  }
}

Next, I need to leave only the data that is included in this square (phone visibility screen), I want to do this in order to receive only the data that will be visible on the screen. Not to ask for too much data.
{
  "from": 0,
  "size": 10,
  "query": {
    "bool": {
      "filter": {
        "geo_bounding_box": {
          "location": {
            "top_left": "49.1248,36.9448",
            "bottom_right": "29.8779,58.3725"
          }
        }
      }
    }
  }
}

I would be very grateful if you tell me how to form a nested query, which will contain geo_distance and geo_bounding_box.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
German Zvonchuk, 2018-11-20
@inside22

After transferring geo_bounding_box to should everything worked.

{
  "from": 0,
  "size": 10,
  "query": {
    "bool": {
      "filter": {
        "geo_distance": {
          "distance": "1km",
          "location": "40.5586,49.6971"
        }
      },
      "should": {
        "geo_bounding_box": {
          "location": {
            "top_left": "49.1248,36.9448",
            "bottom_right": "29.8779,58.3725"
          }
        }
      }
    }
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question