Problem with parameters of the search() function ES-5.3.0


(Khaoula ARI) #1

I’ve problem with the function search more precisely with the parameter fields
so I’m trying to run the following code and getting the error below

code :
if ElasticSearchMonitor.jobs is None:
es = elasticsearch
start = self.timestamp.replace(minutes=-lookback_minutes)
stop = self.timestamp

        body = '''
        {
            "query": {
                "bool": {
                  "must": [
                    { "range": { "_timestamp": { "gte": %(start)s, "lte": %(stop)s }}}
                  ]
                }
            }
        }''' % {'start': start.timestamp*1000, 'stop':stop.timestamp*1000}


        r = es.search(index, doc_type, body,fields=['_id','_timestamp'], size=10000)

        def gather(memo, value):
            memo[value['_id']] = value['fields']
            return memo

        ElasticSearchMonitor.jobs = reduce(gather, r['hits']['hits'], {})

error :

raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)

elasticsearch.exceptions.RequestError: TransportError(400, {u'root_cause': [{u'reason': u'The parameter [fields] is no longer supported, please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored', u'type': u'illegal_argument_exception'}], u'type': u'illegal_argument_exception', u'reason': u'The parameter [fields] is no longer supported, please use [stored_fields] to retrieve stored fields or _source filtering if the field is not stored'})

i've tried to change fields by stored-fields but it doesn’t work
any help plz ?
ps : i'm using elasticsearch 5.3.0


(Simon Willnauer) #2

try to use this instead:

        r = es.search(index, doc_type, body,stored_fields=['_id','_timestamp'], size=10000)

(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.