Muthu
Muthu

Reputation: 247

How to form search query in Elastic search Query DSL in python for geo points?

{
  "geo_bounding_box": {
    "location": {
      "top_right": {
        "lat": 4.482137,
        "lon": 51.0355306
      },
      "bottom_left": {
        "lat": 4.482137,
        "lon": 51.0146768
      }
    }
  }
} . 

Convert the above search filter to Elastic search query DSL.(Python)

Upvotes: 2

Views: 435

Answers (2)

ChintanShah25
ChintanShah25

Reputation: 12672

If you look at the source code, you will find geo_bounding_box filter, your script should look something like this

from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search

client = Elasticsearch()

s = Search(using=client, index="my_index") \
    .filter("geo_bounding_box", location={
            "top_right": {
              "lat": 4.482137,
              "lon": 51.0355306
            },
            "bottom_left": {
              "lat": 4.482137,
              "lon": 51.0146768
            }
          })

Hope this helps!

Upvotes: 4

Muthu
Muthu

Reputation: 247

.filter("geo_bounding_box", location = { "top_right" : {"lat": 4.482137, "lon": 51.0355306 }, "bottom_left" : { "lat": 4.482137, "lon": 51.0146768 }}).

This will work !

Upvotes: 0

Related Questions