# Elasticsearch-mapper-attachments : Loosing file.content on \_update

**URL:** <https://discuss.elastic.co/t/elasticsearch-mapper-attachments-loosing-file-content-on--update/46790>\
**Category:** Elasticsearch\
**Created:** [April 8, 2016, 10:07am UTC](https://discuss.elastic.co/t/elasticsearch-mapper-attachments-loosing-file-content-on--update/46790 "2016-04-08T10:07:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ptrussart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ptrussart/32/25648_2.png) [@ptrussart](https://discuss.elastic.co/u/ptrussart)\
**Post date:** [April 8, 2016, 10:07am UTC](https://discuss.elastic.co/t/elasticsearch-mapper-attachments-loosing-file-content-on--update/46790/1 "2016-04-08T10:07:59Z")

</div>

Hi,

I have a problem linked on the mapping I use :

```auto
PUT documents/myDoc/_mapping
{
    "myDoc": {
        "_source": {
            "excludes": [
                "file"
            ]
        },
        "properties": {
           "title": {
                  "type": "string"
           },
            "file": {
                "type": "attachment",
                "fields": {
                    "content": {
                        "type": "string",
                        "term_vector": "with_positions_offsets",
                        "store": true
                    }
            }
       }
}

```

I'm doing this in order to not storing the file content and to be able to retrieve highlighted text from the extracted text.  
I set the `file._content` with the document content and then I can query on the extracted text with `file.content`. It works fine.

However, I have an issue when I try to update an entry. If I do, for instance

```auto
POST documents/myDoc/123456789/_update
{
  "doc": { "title": "my new title"}
}

```

After this update, I will have an empty value for `file.content`. From what I have understood, this is the standard behavior as the `file` is excluded from the `_source` and because `file.content` is also not in the `_source`. On partial updates, Elasticsearch looses the properties which are not on the `_source`.

I know I can re-upload the document on every update but it is not convenient at all. My question is : Is there a way to force the `file.content` (the extracted text) to be part of the `_source`, so I will not loose the extracted text on a partial update ?

Thanks in advance for your answer.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 9, 2016, 11:18pm UTC](https://discuss.elastic.co/t/elasticsearch-mapper-attachments-loosing-file-content-on--update/46790/2 "2016-04-09T23:18:36Z")

</div>

Not unless you store it.

---

<div class="post-metadata">

**Author:** ![ptrussart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ptrussart/32/25648_2.png) [@ptrussart](https://discuss.elastic.co/u/ptrussart)\
**Post date:** [April 11, 2016, 7:13am UTC](https://discuss.elastic.co/t/elasticsearch-mapper-attachments-loosing-file-content-on--update/46790/3 "2016-04-11T07:13:19Z")

</div>

Why do you mean by that ?  
The `file.content`is already stored. It is not part of the source though. Only the`file._content`is.

Is there something else I can do ?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [April 11, 2016, 7:16am UTC](https://discuss.elastic.co/t/elasticsearch-mapper-attachments-loosing-file-content-on--update/46790/4 "2016-04-11T07:16:56Z")

</div>

It's because when you update a record it needs `_source` to exist, otherwise it sees there is nothing and assumes that whatever you are passing in is `_source`.

See [Update API | Elasticsearch Guide [2.3] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/docs-update.html#docs-update);

> Note, this operation still means **full reindex of the document** , it just removes some network roundtrips and reduces chances of version conflicts between the get and the index. **The \_source field need to be enabled for this feature to work.**

---

<div class="post-metadata">

**Author:** ![ptrussart](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ptrussart/32/25648_2.png) [@ptrussart](https://discuss.elastic.co/u/ptrussart)\
**Post date:** [April 11, 2016, 7:35am UTC](https://discuss.elastic.co/t/elasticsearch-mapper-attachments-loosing-file-content-on--update/46790/5 "2016-04-11T07:35:20Z")

</div>

I understand that.

This is why I'm trying to add the `file.content` to the `_source`. I guess this is the only way avoiding storing the complete file in ES while being able to perform `_update`.

Any ideas on how to do that ?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 11, 2016, 7:56am UTC](https://discuss.elastic.co/t/elasticsearch-mapper-attachments-loosing-file-content-on--update/46790/6 "2016-04-11T07:56:46Z")

</div>

As I wrote here [Loosing file.content on \_update · Issue #209 · elastic/elasticsearch-mapper-attachments · GitHub](https://github.com/elastic/elasticsearch-mapper-attachments/issues/209#issuecomment-207363491)

> And for now I don't believe the update API could work with attachments.

---

<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 5, 2017, 11:00pm UTC](https://discuss.elastic.co/t/elasticsearch-mapper-attachments-loosing-file-content-on--update/46790/7 "2017-07-05T23:00:47Z")

</div>


