Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in AWS by (19.1k points)

I am doing a query on data in python,

When I just do a match and sort it works fine.

res = body={"size" : 100, 

                "query": {"match": {"SensorId": "f0038c53272a"}},

                "sort":{"StartDateTime": "desc"}})

Now when I introduce range, it starts giving an error

res = body={"size" : 100, 

       "query": {"match": {"SensorId": "f0038c53272a"}},

       "sort":{"StartDateTime": "desc"},

       "range":{"StartDateTime":{"gte":"now-50d/d","lt": "now/d"}}})

The error it throws is


 TransportError(400, 'search_phase_execution_exception', 

 'No mapping found for [StartDateTime] in order to sort on')

Elasticsearch version is 2.3. Any clue would be helpful.

1 Answer

0 votes
by (44.4k points)

Check if there is any typo in the name field or it is empty or something.

The syntax of the filter is incorrect in your code. Check out this - Filter context or Post contextThis is the updated query:


  "query": {

    "bool": {

      "must": {"match": {"SensorId": "f0038c53272a"}},

      "filter": {"range": {"StartDateTime": {"gte": "now-50d/d", "lt": "now/d"}}}



  "sort":{"StartDateTime": "desc"}


If SensorId is a match, then there is no need for scoring. Later, you might optimize your query moving the match in the filter.

Related questions

Want to get 50% Hike on your Salary?

Learn how we helped 50,000+ professionals like you !

0 votes
1 answer

Browse Categories