# How to remove a field from document?

**URL:** <https://discuss.elastic.co/t/how-to-remove-a-field-from-document/246420>\
**Category:** Elasticsearch\
**Created:** [August 26, 2020, 9:13am UTC](https://discuss.elastic.co/t/how-to-remove-a-field-from-document/246420 "2020-08-26T09:13:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jake\_hickory](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jake_hickory/32/74527_2.png) [@jake\_hickory](https://discuss.elastic.co/u/jake_hickory)\
**Post date:** [August 26, 2020, 9:13am UTC](https://discuss.elastic.co/t/how-to-remove-a-field-from-document/246420/1 "2020-08-26T09:13:04Z")

</div>

Hello,  
I am new to the forum so hi. I have the old **\_type** field from previous elasticsearch versions in all my documents and want it removed from my documents. How can I do this?

Document:

```auto
"_index": "new-index",
"_type": "_doc",
"_id": "VB1pTXMBOl0fwoYtvNZ0",
"_score": 1,
"_source": {
    "result": "P",
    ......

```

Thanks Jake!

---

<div class="post-metadata">

**Author:** ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)\
**Post date:** [August 26, 2020, 9:20am UTC](https://discuss.elastic.co/t/how-to-remove-a-field-from-document/246420/2 "2020-08-26T09:20:39Z")

</div>

if `_type` is part of \_source then you can use `_update_by_query`

```
POST new-index/_update_by_query?wait_for_completion=false&conflicts=proceed
{
  "script": "ctx._source.remove('_type')",
  "query": {
    "bool": {
      "must": [
        {
          "exists": {
            "field": "_type"
          }
        }
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![jake\_hickory](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jake_hickory/32/74527_2.png) [@jake\_hickory](https://discuss.elastic.co/u/jake_hickory)\
**Post date:** [August 26, 2020, 9:50am UTC](https://discuss.elastic.co/t/how-to-remove-a-field-from-document/246420/3 "2020-08-26T09:50:47Z")

</div>

Hi, thanks for the answer.  
Did what you said but the \_type is still in the index.

 ![grafik](https://us1.discourse-cdn.com/elastic/original/3X/c/3/c38081f033951d0be74638315d22a7455ca236bb.png)  
Result:

```auto
{
    "task": "3fZNyFX-QlqmqzziGGcvCg:4777538"
}

```

Checking for tasks with /tasks tells me that no such task is active.  
Searching the index with idexName/\_search tells me that all the documents still have the \_type field:

 ![grafik](https://us1.discourse-cdn.com/elastic/original/3X/4/8/484d7d58d10bc25c5117fae4ea45f86c1940cc60.png)

Any other ideas? Thanks for your time.

---

<div class="post-metadata">

**Author:** ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)\
**Post date:** [August 26, 2020, 9:52am UTC](https://discuss.elastic.co/t/how-to-remove-a-field-from-document/246420/4 "2020-08-26T09:52:49Z")

</div>

Yes the field \_type is part of the metadata is will be there with default value "\_doc"  
befre es 6, it was possible to define multiple \_type as part of the index mapping ....  
And that was my reflex is that you still have a field \_type under the \_source part of the doc

...

---

<div class="post-metadata">

**Author:** ![jake\_hickory](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jake_hickory/32/74527_2.png) [@jake\_hickory](https://discuss.elastic.co/u/jake_hickory)\
**Post date:** [August 26, 2020, 9:54am UTC](https://discuss.elastic.co/t/how-to-remove-a-field-from-document/246420/5 "2020-08-26T09:54:47Z")

</div>

So is it fine that the field type is still there? I heard that it wont be supported later on so I want to get rid of it to not run into issues with next versions.

---

<div class="post-metadata">

**Author:** ![ylasri](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ylasri/32/86120_2.png) [@ylasri](https://discuss.elastic.co/u/ylasri)\
**Post date:** [August 26, 2020, 9:57am UTC](https://discuss.elastic.co/t/how-to-remove-a-field-from-document/246420/6 "2020-08-26T09:57:26Z")

</div>

It's ok, there is a default value \_doc  
All your documents are accessible from the endpoint \_doc (so \_doc is an endpoint now and no a type)

Example you can get a doc like this GET new-index/\_doc/doc\_id ...

---

<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:** [September 23, 2020, 9:57am UTC](https://discuss.elastic.co/t/how-to-remove-a-field-from-document/246420/7 "2020-09-23T09:57:31Z")

</div>

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