# Replace content of field without deleting other content of id

**URL:** <https://discuss.elastic.co/t/replace-content-of-field-without-deleting-other-content-of-id/5211>\
**Category:** Elasticsearch\
**Created:** [August 21, 2011, 1:33pm UTC](https://discuss.elastic.co/t/replace-content-of-field-without-deleting-other-content-of-id/5211 "2011-08-21T13:33:47Z")\
**Posts on this page:** 6\
**Page:** 1

<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 21, 2011, 1:33pm UTC](https://discuss.elastic.co/t/replace-content-of-field-without-deleting-other-content-of-id/5211/1 "2011-08-21T13:33:47Z")

</div>

Hello everybody,

Let's say I have the following mapping:

curl -X PUT "localhost:9200/test/map1/\_mapping" -d '{

```
"map1" : {
    "properties" : {
        "user" : {"type" : "string"},
        "message" : {"type" : "string", "null_value" : "na"},
        "postDate" : {"type" : "date"},
        "priority" : {"type" : "integer"},
        "rank" : {"type" : "float"}
    }
}

```

}'

and I post an arbitrary content to it (like user and message) and now put  
again a field, which is not yet specified for the id, it is just added.  
Any search queries work fine now.

If I change the content of one field already existing, the content of all  
the other fields vanishes and only the replaced content remains.

Let's say, for id 1 I filled all fields and now want to replace "message"  
without any change to the remaining fields "user", "postdate" etc.

First entry:

curl -XPUT 'localhost:9200/test/map2/1' -d '{  
"user":"esuser",  
"message":"esftw",  
"postDate":"20111008"  
}'

Replace :

curl -XPUT 'localhost:9200/test/map2/1' -d '{  
"message":"esrulez",  
}'

Any search now returns:

{  
"\_index" : "test",  
"\_type" : "map2",  
"\_id" : "1",  
"\_version" : 7,  
"exists" : true, "\_source" : { "message" : "esrulz" }  
}

instead of  
{  
[...]  
"exists" : true, "\_source" : {  
"user":"esuser",  
"message":"esftw",  
"postDate":"20111008"  
}  
}

What can I do?

Thx in advance

---

<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 21, 2011, 2:42pm UTC](https://discuss.elastic.co/t/replace-content-of-field-without-deleting-other-content-of-id/5211/2 "2011-08-21T14:42:35Z")

</div>

Correction:

It should return:

{  
[...]  
"exists" : true, "\_source" : {  
"user":"esuser",  
_"message":"esrulz",_  
"postDate":"20111008"  
}  
}

---

<div class="post-metadata">

**Author:** ![Stefan\_Matheis](https://avatars.discourse-cdn.com/v4/letter/s/977dab/32.png) [@Stefan\_Matheis](https://discuss.elastic.co/u/Stefan_Matheis)\
**Post date:** [August 21, 2011, 3:11pm UTC](https://discuss.elastic.co/t/replace-content-of-field-without-deleting-other-content-of-id/5211/3 "2011-08-21T15:11:25Z")

</div>

You have to request the current document first .. change the fields  
and send it back to ES. it isn't possible to change one or more fields  
directly.

Regards  
Stefan

On Sun, Aug 21, 2011 at 4:42 PM, Frifri [henning.frieder@googlemail.com](mailto:henning.frieder@googlemail.com) wrote:

> Correction:
> 
> It should return:
> 
> {  
> [...]  
> "exists" : true, "\_source" : {  
> "user":"esuser",  
> "message":"esrulz",  
> "postDate":"20111008"  
> }  
> }

---

<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 21, 2011, 7:08pm UTC](https://discuss.elastic.co/t/replace-content-of-field-without-deleting-other-content-of-id/5211/4 "2011-08-21T19:08:59Z")

</div>

Alright, thx so far.

In my case, I want to add some additional tags (like comments etc) to an  
indexed PDF (type attachment).

Example: PDF A, Comment B, preferably same id in the same mapping. If  
somebody searches for a string which is part of both the content stream A  
and the comment B, I'd like ES to return only one result as there is only  
one id. If I use the same id in different mappings, I would have to merge  
the two results, which is too much overhead in big deployments.

Should I use nested type (as described here:  
[http://www.elasticsearch.org/guide/reference/mapping/nested-type.html](http://www.elasticsearch.org/guide/reference/mapping/nested-type.html)) or a  
parent/child configuration?

Regards

---

<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 22, 2011, 6:48pm UTC](https://discuss.elastic.co/t/replace-content-of-field-without-deleting-other-content-of-id/5211/5 "2011-08-22T18:48:11Z")

</div>

Nested still requires working with the full document, as nested objects are  
part of the json document you index (and thats the reason why "joining" on  
them is so fast). Parent child is one way to go, where comments can be  
children to the parent PDF doc.

On Sun, Aug 21, 2011 at 10:08 PM, Frifri [henning.frieder@googlemail.com](mailto:henning.frieder@googlemail.com)wrote:

> Alright, thx so far.
> 
> In my case, I want to add some additional tags (like comments etc) to an  
> indexed PDF (type attachment).
> 
> Example: PDF A, Comment B, preferably same id in the same mapping. If  
> somebody searches for a string which is part of both the content stream A  
> and the comment B, I'd like ES to return only one result as there is only  
> one id. If I use the same id in different mappings, I would have to merge  
> the two results, which is too much overhead in big deployments.
> 
> Should I use nested type (as described here:  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/nested-type.html)) or  
> a parent/child configuration?
> 
> Regards

---

<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:56am UTC](https://discuss.elastic.co/t/replace-content-of-field-without-deleting-other-content-of-id/5211/6 "2017-07-06T03:56:22Z")

</div>


