Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Elasticsearch [size] query malformed, no start_object after query name'

I have a query I was using in Postman. It is:

{ "size": 1, "sort": { "event_date": "desc"}, "query": { "match_all": {} } }

This returns the latest date in event_date for everything ingested and performs just like I want it to.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

When I go to Python, I get the error though:

elasticsearch.exceptions.RequestError: RequestError(400, ‘parsing_exception’, ‘[size] query malformed, no start_object after query name’)

The call:

last_date_query = {
   "size": 1,
   "sort": { "event_date": "desc"},
   "query": {
      "match_all": {}
   }
}

if es is None:
    es = connect()

search_result = es.search(index=index, query = last_date_query)

How do I get the same query results when calling elasticsearch from python for my rather simple query?

I tried the above code in Python.

>Solution :

The query argument should only contain the query part, size and sort are other parameters to the search function.
You need to do it this way

sort = { "event_date": "desc"}
last_date_query = {
   "match_all": {}
}

if es is None:
    es = connect()

search_result = es.search(index=index, query = last_date_query, size = 1, sort = sort)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading