# Add new field to index using update\_by\_query

**URL:** https://discuss.elastic.co/t/add-new-field-to-index-using-update-by-query/129498
**Category:** Elasticsearch
**Created:** [April 25, 2018, 1:21pm UTC](https://discuss.elastic.co/t/add-new-field-to-index-using-update-by-query/129498 "2018-04-25T13:21:05Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nkaenzig](https://avatars.discourse-cdn.com/v4/letter/n/97f17d/32.png) [@nkaenzig](https://discuss.elastic.co/u/nkaenzig)
#### Post date: [April 25, 2018, 1:21pm UTC](https://discuss.elastic.co/t/add-new-field-to-index-using-update-by-query/129498/1 "2018-04-25T13:21:06Z")

</div>

Dear Community,

I'm trying to add a new field to all documents that match a certain condition.  
After doing some research I found that the update\_by\_query API might be a suitable method to achieve this.  
What I have so far is the following:

> POST packets-test/\_update\_by\_query  
> {  
> "script": {  
> "source": "ctx.\_source.status = 1",  
> "lang": "painless"  
> },  
> "query": {  
> "match": {  
> "layers.ip.ip\_ip\_src": "10.7.6.2"  
> }  
> }  
> }

In other words I want to add a "status" field with value 1 to all documents where the field "layers.ip.ip\_ip\_src" is "10.7.6.2" (type: ip).  
However, running this, I get the following error:

> {  
> "statusCode": 504,  
> "error": "Gateway Time-out",  
> "message": "Client request timeout"  
> }

Am I doing something wrong?  
My (test) index has 1.5mio documents and 484,003 of those match the above query condition.  
However the real index where I would like to apply this to holds about 200mio documents.

Does update\_by\_query even scale to such dimensions? If not what would be a possible solution to do this in a reasonable amount of time?  
(I use Elasticsearch 6.2)

EDIT:  
Ich habe nun noch einen Versuch mit einer "match\_all" query gemacht (also um das Feld in allen Dokumenten zu updaten): So läuft es durch ohne timeout error, wenn auch ziemlich langsam.

1. warum läuft es nicht mit einer spezifischeren query?
2. wie kann man das schneller machen/parallelisieren (e.g. mit der Python API?)

---

<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: [May 23, 2018, 1:21pm UTC](https://discuss.elastic.co/t/add-new-field-to-index-using-update-by-query/129498/2 "2018-05-23T13:21:11Z")

</div>

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