-
Notifications
You must be signed in to change notification settings - Fork 801
Closed
Description
Hello, i need use script_fields
complete a complex task, use Python will make this simpler. for example:
In [177]: s = cls.search()
In [178]: s = s.script_fields(
...: commission={
...: 'script': "price * (1 + partner_map.get(doc['colum_id'].value, 0)
...: * partner_map.get(doc['column_id'].value)[1]",
...: 'params': {'partner_map': partner_map},
...: 'lang': 'python'
...: }
...: )
But the execution failed:
In [179]: rs = s.execute()
---------------------------------------------------------------------------
RequestError Traceback (most recent call last)
<ipython-input-179-567d2f95b331> in <module>()
----> 1 rs = s.execute()
/Users/dongweiming/workspace/niffler/venv/src/daenerys/daenerys/search.pyc in execute(self, ignore_cache)
596 doc_type=self._doc_type,
597 body=self.to_dict(),
--> 598 **self._params
599 )
600 )
/Users/dongweiming/workspace/niffler/venv/lib/python2.7/site-packages/elasticsearch/client/utils.pyc in _wrapped(*args, **kwargs)
71 if p in kwargs:
72 params[p] = kwargs.pop(p)
---> 73 return func(*args, params=params, **kwargs)
74 return _wrapped
75 return _wrapper
/Users/dongweiming/workspace/niffler/venv/lib/python2.7/site-packages/elasticsearch/client/__init__.pyc in search(self, index, doc_type, body, params)
567 index = '_all'
568 return self.transport.perform_request('GET', _make_path(index,
--> 569 doc_type, '_search'), params=params, body=body)
570
571 @query_params('_source', '_source_exclude', '_source_include',
/Users/dongweiming/workspace/niffler/venv/lib/python2.7/site-packages/elasticsearch/transport.pyc in perform_request(self, method, url, params, body)
316
317 try:
--> 318 status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
319
320 except TransportError as e:
/Users/dongweiming/workspace/niffler/venv/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.pyc in perform_request(self, method, url, params, body, timeout, ignore)
126 if not (200 <= response.status < 300) and response.status not in ignore:
127 self.log_request_fail(method, full_url, url, body, duration, response.status, raw_data)
--> 128 self._raise_error(response.status, raw_data)
129
130 self.log_request_success(method, full_url, url, body, response.status,
/Users/dongweiming/workspace/niffler/venv/lib/python2.7/site-packages/elasticsearch/connection/base.pyc in _raise_error(self, status_code, raw_data)
120 logger.warning('Undecodable raw error response from server: %s', err)
121
--> 122 raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
123
124
RequestError: TransportError(400, u'parsing_exception', u'Unknown key for a VALUE_STRING in [lang].')
if i remove the lang
field:
In [181]: s = cls.search()
...:
In [182]: s = s.script_fields(
...: commission={
...: 'script': "price * (1 + partner_map.get(doc['colum_id'].value, 0)
...: * partner_map.get(doc['column_id'].value)[1]",
...: 'params': {'partner_map': partner_map},
...: }
...: )
the execution is still going to fail:
...
RequestError: TransportError(400, u'parsing_exception', u'Unknown key for a START_OBJECT in [params].')
What is the correct usage? @honzakral @3lnc
This is my elasticsearch server info:
In [185]: e.info()
Out[185]:
{u'cluster_name': u'elasticsearch_dongweiming',
u'cluster_uuid': u'A-upq2bEQH6zx8XfFrF7Ng',
u'name': u'qQxwDxr',
u'tagline': u'You Know, for Search',
u'version': {u'build_date': u'2016-12-06T12:36:15.409Z',
u'build_hash': u'5395e21',
u'build_snapshot': False,
u'lucene_version': u'6.3.0',
u'number': u'5.1.1'}}
Metadata
Metadata
Assignees
Labels
No labels