15

I'm attempting to do a bulk update based on state change on a document property. Create works fine but bulk is freaking out. I'm getting an error to the effect of "script or doc is missing" but everything looks good.

Here is how I am attempting the 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'm iterating over my results is that I use an if in my list comprehension but since I'm able to see the results I get back I know that isn't the issue. I can't show results and had to change property names since this is for the company I work at.

Here is the traceback:

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

The ellipses represent it showing the same error for every element in the list fails.

1 Answer 1

27

It was difficult to tell based on the docs but I found out the issue. If you want to do a bulk update you need to wrap your source in a dictionary with the key being "doc". Here is the correct example, hope this helps!

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']
]

Notice the slight change is "_source" to {'doc': result['_source']}

Sign up to request clarification or add additional context in comments.

1 Comment

This is useful - their python docs appear to be inaccurate. There, 'doc' is not wrapped inside a '_source' object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.