# Updating nested hash

**URL:** <https://discuss.elastic.co/t/updating-nested-hash/12960>\
**Category:** Elasticsearch\
**Created:** [July 26, 2013, 3:51pm UTC](https://discuss.elastic.co/t/updating-nested-hash/12960 "2013-07-26T15:51:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![harshp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/harshp/32/2207_2.png) [@harshp](https://discuss.elastic.co/u/harshp)\
**Post date:** [July 26, 2013, 3:51pm UTC](https://discuss.elastic.co/t/updating-nested-hash/12960/1 "2013-07-26T15:51:25Z")

</div>

Hi,

I have been trying to \_update a nested hash and am facing some issues. My doc looks like this  
curl -XGET [http://localhost:9200/twitter/tweet/QTEYNIn6Tdej0rQNW4Nh-A?pretty=true](http://localhost:9200/twitter/tweet/QTEYNIn6Tdej0rQNW4Nh-A?pretty=true)  
{  
"\_index" : "twitter",  
"\_type" : "tweet",  
"\_id" : "QTEYNIn6Tdej0rQNW4Nh-A",  
"\_version" : 7,  
"exists" : true, "\_source" : {"last\_seen":"20130726T15:32:39","hit\_count":1,"hits\_by\_day":{"20130726":1},"remote\_addr":["10.10.10.10"]}}

Here I am trying to add 1 to "20130726", however accessing the variable and setting it seems to be the issue. When I run the below query I get no error, the query executes and the \_version changes. However there are no changes to the field.

The issue might be the way I am trying to access the hash.

curl -XPOST [http://localhost:9200/twitter/tweet/QTEYNIn6Tdej0rQNW4Nh-A](http://localhost:9200/twitter/tweet/QTEYNIn6Tdej0rQNW4Nh-A)' -d '  
{  
"script":"ctx.\_source.hits\_by\_day.containsKey("todate") ? ctx.\_source.hits\_by\_day.todate += count : ctx.\_source.hits\_by\_day.todate = 1;",  
"params":{  
"count":1,"todate":"20130726"}}'

{"ok":true,"\_index":"twitter","\_type":"tweet","\_id":"QTEYNIn6Tdej0rQNW4Nh-A","\_version":7}

Thanks a ton for the help.

Harsh

---

<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:** [July 6, 2017, 2:24am UTC](https://discuss.elastic.co/t/updating-nested-hash/12960/2 "2017-07-06T02:24:15Z")

</div>

Closed on July 6, 2017, 2:24am UTC


