# Elasticsearch6.2.1 remove field

**URL:** <https://discuss.elastic.co/t/elasticsearch6-2-1-remove-field/232558>\
**Category:** Elasticsearch\
**Created:** [May 14, 2020, 6:27am UTC](https://discuss.elastic.co/t/elasticsearch6-2-1-remove-field/232558 "2020-05-14T06:27:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jerry-chen-315](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jerry-chen-315/32/34699_2.png) [@jerry-chen-315](https://discuss.elastic.co/u/jerry-chen-315)\
**Post date:** [May 14, 2020, 6:27am UTC](https://discuss.elastic.co/t/elasticsearch6-2-1-remove-field/232558/1 "2020-05-14T06:27:17Z")

</div>

Is there any method remove field from some docs when don't know doc id or don't specified doc id? Like higher version provide delete\_by\_query API.

---

<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:** [May 14, 2020, 7:35am UTC](https://discuss.elastic.co/t/elasticsearch6-2-1-remove-field/232558/2 "2020-05-14T07:35:13Z")

</div>

If you mean remove from the mapping, it's not possible.  
If you mean remove from documents, update by query should help.

You should also upgrade your cluster to at least 6.8 or 7.7.

---

<div class="post-metadata">

**Author:** ![jerry-chen-315](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jerry-chen-315/32/34699_2.png) [@jerry-chen-315](https://discuss.elastic.co/u/jerry-chen-315)\
**Post date:** [May 14, 2020, 8:27am UTC](https://discuss.elastic.co/t/elasticsearch6-2-1-remove-field/232558/3 "2020-05-14T08:27:20Z")

</div>

> [@dadoonet](#):
>
> update by query

`I also found update_by_query api, but i am poor at English,so I cann't get full meaning from the official document, Could you please give me some example?`

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [May 15, 2020, 9:36am UTC](https://discuss.elastic.co/t/elasticsearch6-2-1-remove-field/232558/4 "2020-05-15T09:36:43Z")

</div>

Hi @jerry-chen-315

Here a simple example that may help you to understand the update\_by\_query:

First create 3 documents:

```
POST example/doc/1
{
  "field1": 123,
  "field2": 456
}

POST example/doc/2
{
  "field1": 123,
  "field2": 456
}

POST example/doc/3
{
  "field1": 987,
  "field2": 456
}

```

Check that you have your 3 documents, with 2 of them (id 1 and 2) with field1 equal to 123

```
GET example/doc/_search

```

Now let's say that you want to remove the field1 for all the document that have field1 == 123.

```
POST example/doc/_update_by_query
{
  "query":{"term": {"field1": 123}},
  "script": {
    "source": "ctx._source.remove('field1');",
    "lang": "painless"
  }
}

```

It will return a json response with updated == 2

Then you can check your data by running this:

```
GET example/doc/_search

```

if everything is fine you will have your 3 documents and the doc 1 and 2 will have only field2, document id 3 will keep his 2 fields.

More about update\_by\_query:  
[https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-update-by-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.8/docs-update-by-query.html)  
One similar question on stackoverflow:

> <https://stackoverflow.com/questions/56649273/elasticsearch-delete-field-from-all-documents-where-it-exists-with-painless>

---

<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:** [June 12, 2020, 9:45am UTC](https://discuss.elastic.co/t/elasticsearch6-2-1-remove-field/232558/5 "2020-06-12T09:45:11Z")

</div>

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