Mass update using Python elasticsearch

I am trying to perform a bulk update based on a state change in a document property. Creating works is beautiful, but exciting in bulk. I get an error "script or doc missing", but everything looks good.

Here's how I try bulk update:

frequency_cleared = [
    {
        "_id": result['_id'], 
        "_type": "the-type", 
        "_index": "the-index", 
        "_source": result['_source'],
        "_op_type": 'update'
    } 
    for result in search_results['hits']['hits']
]

The reason I repeat my results is because I use if in my understanding of the list, but since I can see the results I return, I know that this is not a problem. I can’t show the results and had to change the names of the properties, since this is for the company I work for.

Here is the trace:

Elasticsearch.exceptions.RequestError: 
TransportError(400, 'action_request_validation_exception',
  'Validation Failed: 1: script or doc is missing...') 

Ellipses indicate that it shows the same error for each item in the list.

+4
1

, , . , , "doc". , , !

frequency_cleared = [
    {
        '_id': result['_id'], 
        "_type": "the-type", 
        "_index": "the-index", 
        "_source": {'doc': result['_source']}, 
        '_op_type': 'update'
    } 
    for result in search_results['hits']['hits']
]

, "_source" {'doc': result ['_ source']}

+6

Source: https://habr.com/ru/post/1627178/


All Articles