I'm trying to use the Update API via the elasticsearch-py python client on ES 2.1.1 and I'm having trouble.
es.index(index='boston', doc_type='stem_map', id=111, body={'word': 'showing', 'counter': 29})
es.get(index='boston', doc_type='stem_map', id=111)
{'_id': '111',
'_index': 'boston',
'_source': {'counter': 29, 'word': 'showing'},
'_type': 'stem_map',
'_version': 1,
'found': True}
upscript = {
'script': {
'inline': 'ctx._source.counter += count',
'params': {
'count': 100
}
}
}
Then I tried both of the following:
es.update(index='boston', doc_type='stem_map', id=111, body=upscript)
es.update(index='boston', doc_type='stem_map', id=111, script=upscript)
I'm getting the following error:
RequestError: TransportError(400, 'illegal_argument_exception', '[John Walker][127.0.0.1:9300][indices:data/write/update[s]]')
Does anybody know what I'm doing wrong?
UPDATE: This also does not work
es.index(index='boston', doc_type='stem_map', id='111', body={'word': 'showing', 'counter': 29})
{'_id': '111',
'_index': 'boston',
'_shards': {'failed': 0, 'successful': 1, 'total': 2},
'_type': 'stem_map',
'_version': 1,
'created': True}
upscript = {
"script" : "ctx._source.counter += count",
"params" : {
'count': 100
}
}
es.update(index='boston', doc_type='stem_map', id='111', body=upscript)
WARNING:elasticsearch:POST /boston/stem_map/111/_update [status:400 request:0.002s]
...
RequestError: TransportError(400, 'illegal_argument_exception', '[Atum][127.0.0.1:9300][indices:data/write/update[s]]')
ANSWER: My mistake. I didn't realize I had to enable scripting on ES first by changing the config/elasticsearch.yml file. My original code works after enabling scripting.