Converting app engine search API query to elasticsearch query

Viewed 263

I'm migrating my existing python 2.7 project from app engine. In my code, there's extensive use of Document Search API. I'm using Elasticsearch to replace it outside the app engine.

I've created a base handler to replace the creation and deletion of documents with Elastic search handler. But I'm stuck at searching the documents.

In the app engine search API, there are so many different types of queries available (check out docs) and I'm thinking to make a single function to replace those queries with the elastic search compatible query.

For example, a simple Search API query looks like:

search_query = "forFromDate : 2019-06-01 forToDate : 2019-07-01"

but the same query for elastic search would be like:

es_query = {
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "forToDate": "2019-07-01"
                    }
                },
                {
                    "match": {
                        "forFromDate": "2019-06-01"
                    }
                }
            ]
        }
    }
}

I can achieve such simple query conversion with the simple python function, but for complex queries, it's difficult to manage. Any idea of how to convert such queries?? Any help would be appreciated.

0 Answers
Related