# Elasticsearch Update by Query using CTX

**URL:** <https://discuss.elastic.co/t/elasticsearch-update-by-query-using-ctx/112176>\
**Category:** Elasticsearch\
**Created:** [December 18, 2017, 8:39am UTC](https://discuss.elastic.co/t/elasticsearch-update-by-query-using-ctx/112176 "2017-12-18T08:39:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adityosn](https://avatars.discourse-cdn.com/v4/letter/a/e5b9ba/32.png) [@adityosn](https://discuss.elastic.co/u/adityosn)\
**Post date:** [December 18, 2017, 8:39am UTC](https://discuss.elastic.co/t/elasticsearch-update-by-query-using-ctx/112176/1 "2017-12-18T08:39:55Z")

</div>

I would like to update all documents inside the the index. I found that Update Query is the method we should use. But, I am facing problem when I am using ctx.\_now as a value for updated document's field, causing the field value become null.  
This is the sample:

```
{
  "script": {
    "inline": "ctx._source.timenow = ctx._now"
  },
  "query": {
    "match_all": {}
  }
}

```

![timenow](https://us1.discourse-cdn.com/elastic/original/3X/2/2/22db22d42fd12d3e9bb4c2aa7d5a91c740229b57.PNG)

When I am using random number value, it is work. Let say that I put timenow = 5. Then, All documents field timenow become 5. But, it is not work using this ctx method.  
How should I do that ?  
Thank You

---

<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 15, 2018, 8:40am UTC](https://discuss.elastic.co/t/elasticsearch-update-by-query-using-ctx/112176/2 "2018-01-15T08:40:30Z")

</div>

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