# Updating the fields in index

**URL:** <https://discuss.elastic.co/t/updating-the-fields-in-index/5232>\
**Category:** Elasticsearch\
**Created:** [August 24, 2011, 7:09am UTC](https://discuss.elastic.co/t/updating-the-fields-in-index/5232 "2011-08-24T07:09:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![arien](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@arien](https://discuss.elastic.co/u/arien)\
**Post date:** [August 24, 2011, 7:09am UTC](https://discuss.elastic.co/t/updating-the-fields-in-index/5232/1 "2011-08-24T07:09:13Z")

</div>

Hi all;  
To provide the general idea about the problem i m facing,i m giving an  
example of very simple form of index generation as per the tutorial.

lets say i have created an index with some fields as;

curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
"user" : "admin",  
"post\_date" : "2009-11-15T14:12:12",  
"message" : "trying out Elastic Search"  
}'

I want to update the only field "user" so that it will have value as  
"arien",for that i will have to do something like this

curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
"user" : "arien",  
"post\_date" : "2009-11-15T14:12:12",  
"message" : "trying out Elastic Search"  
}'

Now the problem with this is I want to retain valuefields for  
"post\_date" and "message" unchanged without providing them at the time  
of updation against same index id.for ex. something like this

curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
"user" : "arien",  
}'

but while querying(in search api) i should be getting all the 3 fields  
specified in the index unlike i get only "user" field after updation  
as the overridden index.

I m dealing with very large chunk of data at the time of indexing  
using attachment mapper and its really an overhead to update an index  
using all the fields everytime for even a small attribute change.So  
please provide some suggestions regarding this.

Thanking you;  
arien

---

<div class="post-metadata">

**Author:** ![Nicolas\_Lalevee](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nicolas_lalevee/32/2892_2.png) [@Nicolas\_Lalevee](https://discuss.elastic.co/u/Nicolas_Lalevee)\
**Post date:** [August 24, 2011, 8:01am UTC](https://discuss.elastic.co/t/updating-the-fields-in-index/5232/2 "2011-08-24T08:01:21Z")

</div>

Le 24 août 2011 à 09:09, arien a écrit :

> Hi all;  
> To provide the general idea about the problem i m facing,i m giving an  
> example of very simple form of index generation as per the tutorial.
> 
> lets say i have created an index with some fields as;
> 
> curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
> "user" : "admin",  
> "post\_date" : "2009-11-15T14:12:12",  
> "message" : "trying out Elastic Search"  
> }'
> 
> I want to update the only field "user" so that it will have value as  
> "arien",for that i will have to do something like this
> 
> curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
> "user" : "arien",  
> "post\_date" : "2009-11-15T14:12:12",  
> "message" : "trying out Elastic Search"  
> }'
> 
> Now the problem with this is I want to retain valuefields for  
> "post\_date" and "message" unchanged without providing them at the time  
> of updation against same index id.for ex. something like this
> 
> curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
> "user" : "arien",  
> }'
> 
> but while querying(in search api) i should be getting all the 3 fields  
> specified in the index unlike i get only "user" field after updation  
> as the overridden index.
> 
> I m dealing with very large chunk of data at the time of indexing  
> using attachment mapper and its really an overhead to update an index  
> using all the fields everytime for even a small attribute change.So  
> please provide some suggestions regarding this.

The underlying library used by Elasticsearch, Lucene, doesn't handle field update, and will probably not anytime soon. There were some discussion to have a work around in Elasticsearch but it is not yet there, and it seems to be really a work around.

If the case fits for you, try to separate the fields that needs that needs to be indexed from the ones which don't. The fields that needs to be indexed, let them be handled by Elasticsearch, and for the others, choose another tool to store them, another classical database which would handle an update of just a field of a document. For the indexed fields, you'll have no choice but to push the entire document for each update. For the others, just update what you need. And when you query, search in elasticsearch and reconcile the data with the external data store.

Nicolas

---

<div class="post-metadata">

**Author:** ![arien](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@arien](https://discuss.elastic.co/u/arien)\
**Post date:** [August 24, 2011, 1:58pm UTC](https://discuss.elastic.co/t/updating-the-fields-in-index/5232/3 "2011-08-24T13:58:50Z")

</div>

Hi;  
Thanks for your suggestion.I m looking forward to consider it as one of the  
prominent way to solve my issue.

2011/8/24 Nicolas Lalevée [nicolas.lalevee@hibnet.org](mailto:nicolas.lalevee@hibnet.org)

> Le 24 août 2011 à 09:09, arien a écrit :
> 
> > Hi all;  
> > To provide the general idea about the problem i m facing,i m giving an  
> > example of very simple form of index generation as per the tutorial.
> > 
> > lets say i have created an index with some fields as;
> > 
> > curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
> > "user" : "admin",  
> > "post\_date" : "2009-11-15T14:12:12",  
> > "message" : "trying out Elastic Search"  
> > }'
> > 
> > I want to update the only field "user" so that it will have value as  
> > "arien",for that i will have to do something like this
> > 
> > curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
> > "user" : "arien",  
> > "post\_date" : "2009-11-15T14:12:12",  
> > "message" : "trying out Elastic Search"  
> > }'
> > 
> > Now the problem with this is I want to retain valuefields for  
> > "post\_date" and "message" unchanged without providing them at the time  
> > of updation against same index id.for ex. something like this
> > 
> > curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
> > "user" : "arien",  
> > }'
> > 
> > but while querying(in search api) i should be getting all the 3 fields  
> > specified in the index unlike i get only "user" field after updation  
> > as the overridden index.
> > 
> > I m dealing with very large chunk of data at the time of indexing  
> > using attachment mapper and its really an overhead to update an index  
> > using all the fields everytime for even a small attribute change.So  
> > please provide some suggestions regarding this.
> 
> The underlying library used by Elasticsearch, Lucene, doesn't handle field  
> update, and will probably not anytime soon. There were some discussion to  
> have a work around in Elasticsearch but it is not yet there, and it seems to  
> be really a work around.
> 
> If the case fits for you, try to separate the fields that needs that needs  
> to be indexed from the ones which don't. The fields that needs to be  
> indexed, let them be handled by Elasticsearch, and for the others, choose  
> another tool to store them, another classical database which would handle an  
> update of just a field of a document. For the indexed fields, you'll have no  
> choice but to push the entire document for each update. For the others, just  
> update what you need. And when you query, search in elasticsearch and  
> reconcile the data with the external data store.
> 
> Nicolas

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [August 24, 2011, 6:16pm UTC](https://discuss.elastic.co/t/updating-the-fields-in-index/5232/4 "2011-08-24T18:16:20Z")

</div>

The simplest way to solve this is to get the document, update the relevant  
field, and then index the document again. You can use versioning to make  
sure no other update has "sneaked" in while you were doing the update.

On Wed, Aug 24, 2011 at 10:09 AM, arien [ajaypadvi@gmail.com](mailto:ajaypadvi@gmail.com) wrote:

> Hi all;  
> To provide the general idea about the problem i m facing,i m giving an  
> example of very simple form of index generation as per the tutorial.
> 
> lets say i have created an index with some fields as;
> 
> curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
> "user" : "admin",  
> "post\_date" : "2009-11-15T14:12:12",  
> "message" : "trying out Elastic Search"  
> }'
> 
> I want to update the only field "user" so that it will have value as  
> "arien",for that i will have to do something like this
> 
> curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
> "user" : "arien",  
> "post\_date" : "2009-11-15T14:12:12",  
> "message" : "trying out Elastic Search"  
> }'
> 
> Now the problem with this is I want to retain valuefields for  
> "post\_date" and "message" unchanged without providing them at the time  
> of updation against same index id.for ex. something like this
> 
> curl -XPUT '[http://localhost:9200/twitter/tweet/1](http://localhost:9200/twitter/tweet/1)' -d '{  
> "user" : "arien",  
> }'
> 
> but while querying(in search api) i should be getting all the 3 fields  
> specified in the index unlike i get only "user" field after updation  
> as the overridden index.
> 
> I m dealing with very large chunk of data at the time of indexing  
> using attachment mapper and its really an overhead to update an index  
> using all the fields everytime for even a small attribute change.So  
> please provide some suggestions regarding this.
> 
> Thanking you;  
> arien

---

<div class="post-metadata">

**Author:** ![Frifri](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@Frifri](https://discuss.elastic.co/u/Frifri)\
**Post date:** [August 26, 2011, 4:31pm UTC](https://discuss.elastic.co/t/updating-the-fields-in-index/5232/5 "2011-08-26T16:31:58Z")

</div>

Let's say I save content in two mappings of which I update (replace) only  
one normally. In both mappings, I would use the same id. If now, for  
example, both contents contain each the same string in at least one field,  
is it possible to return only \*one \*hit as if I found the string in only  
one mapping? (MySQL equivalent of "group by id")?

Thx

---

<div class="post-metadata">

**Author:** ![summersmile1984](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@summersmile1984](https://discuss.elastic.co/u/summersmile1984)\
**Post date:** [August 26, 2011, 5:10pm UTC](https://discuss.elastic.co/t/updating-the-fields-in-index/5232/6 "2011-08-26T17:10:22Z")

</div>

The Autonomy IDOL search engine has a ReplaceFieldValue action could update the indexed item . In fact ,I am facing the same problem with you. Extracting the attachment file is a heavy job. Re index the item makes the work quite unhappy , especially you have a lot of items to reindex. Such as you want to update the view count of the document, the replay count. If you want to order search results by this numbers. You have to index them into the index but not store it in the database.

The underline way of implement Update of Autonomy IDOL, seems to is making a new item by copy the indexed item and then replace the value from the parameter. Deleting the older item some time later.

May be the version feature of elasticsearch could make some sense to this senario.  
Just some suggestion, I am a new comer of ES.

---

<div class="post-metadata">

**Author:** ![Frifri](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@Frifri](https://discuss.elastic.co/u/Frifri)\
**Post date:** [August 29, 2011, 9:36am UTC](https://discuss.elastic.co/t/updating-the-fields-in-index/5232/7 "2011-08-29T09:36:52Z")

</div>

Could it be possible to use Parent/Child? From my point of view that seems  
to be feasible, but a little slow as there are always two queries to be  
made. I'd use one mapping for the attachment and another for the comments.

---

<div class="post-metadata">

**Author:** ![Frifri](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@Frifri](https://discuss.elastic.co/u/Frifri)\
**Post date:** [August 29, 2011, 9:41am UTC](https://discuss.elastic.co/t/updating-the-fields-in-index/5232/8 "2011-08-29T09:41:59Z")

</div>

Yeah, looks like it seems to be ok. I overlooked a post of kimchy.

---

<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, 3:55am UTC](https://discuss.elastic.co/t/updating-the-fields-in-index/5232/9 "2017-07-06T03:55:46Z")

</div>


