# \[elasticsearch-py\] problem update array of json

**URL:** <https://discuss.elastic.co/t/elasticsearch-py-problem-update-array-of-json/110163>\
**Category:** Elasticsearch\
**Created:** [December 4, 2017, 2:48pm UTC](https://discuss.elastic.co/t/elasticsearch-py-problem-update-array-of-json/110163 "2017-12-04T14:48:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tab](https://avatars.discourse-cdn.com/v4/letter/t/3da27b/32.png) [@tab](https://discuss.elastic.co/u/tab)\
**Post date:** [December 4, 2017, 2:48pm UTC](https://discuss.elastic.co/t/elasticsearch-py-problem-update-array-of-json/110163/1 "2017-12-04T14:48:51Z")

</div>

Hello,  
this is my first post but I spent a lot of time for searching a solution to my problem.  
I have a document of this type:  
doc = {  
"id": 1,  
"sites": {  
"[google.com](http://google.com)": [{  
"date": "01/01/1970",  
"last\_visit": "30/11/2017",  
"username": "Matt",  
},  
{  
"date": "01/01/1994",  
"last\_visit": "25/11/2017",  
"username": "George",  
}],  
"[yahoo.com](http://yahoo.com)": [{  
"date": "01/01/1976",  
"last\_visit": "30/05/2017",  
"username": "Luis",  
}]  
}  
}

This is the script I use to update this document via Python 2.7 (elasticsearch-py for Elasticsearch 6):  
body={"script":"ctx.\_source.sites += params.sites",  
"params":{  
"sites": {  
site\_variable: [{  
"date": date\_var,  
"last\_visit": visit\_var,  
"username": user\_var,  
}]  
}  
}  
})

And this is the error:

> Traceback (most recent call last):  
> File "elastic\_test2.py", line 84, in   
> line2json()  
> File "elastic\_test2.py", line 77, in line2json  
> "username": user\_var  
> File "build/bdist.cygwin-2.7.0-i686/egg/elasticsearch/client/utils.py", line 76, in \_wrapped  
> File "build/bdist.cygwin-2.7.0-i686/egg/elasticsearch/client/ **init**.py", line 528, in update  
> File "build/bdist.cygwin-2.7.0-i686/egg/elasticsearch/transport.py", line 314, in perform\_request  
> File "build/bdist.cygwin-2.7.0-i686/egg/elasticsearch/connection/http\_urllib3.py", line 161, in perform\_request  
> File "build/bdist.cygwin-2.7.0-i686/egg/elasticsearch/connection/base.py", line 125, in \_raise\_error  
> elasticsearch.exceptions.RequestError: TransportError(400, u'action\_request\_validation\_exception', u'Validation Failed: 1: script or doc is missing;

I also tried to enclose body content in ''' and ''' but in that case I have the error of

> 'Unable to serialize set(....)

---

<div class="post-metadata">

**Author:** ![tab](https://avatars.discourse-cdn.com/v4/letter/t/3da27b/32.png) [@tab](https://discuss.elastic.co/u/tab)\
**Post date:** [December 5, 2017, 11:32am UTC](https://discuss.elastic.co/t/elasticsearch-py-problem-update-array-of-json/110163/2 "2017-12-05T11:32:53Z")

</div>

For those looking for a solution to this problem,  
I solved adding "inline" parameter inside the script.

Eg.:  
es.update(  
index="test",  
doc\_type="type",  
id=3,  
body={  
"script" : {  
"inline":"ctx.\_source.data.domains.add(params.newDomain)",  
"params":{  
"newDomain":"[elastic.co](http://elastic.co)"  
}  
}  
})

Bye! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 2, 2018, 11:33am UTC](https://discuss.elastic.co/t/elasticsearch-py-problem-update-array-of-json/110163/3 "2018-01-02T11:33:01Z")

</div>

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