0 votes
1 view
in AWS by (18.2k points)

I am doing a query on data in python,

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

res = es.search( body={"size" : 100, 

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

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

Now when I introduce range, it starts giving an error

res = es.search( body={"size" : 100, 

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

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

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

The error it throws is

 elasticsearch.exceptions.RequestError: 

 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 (42.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.

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...