# How to delete a field from an index while reindexing?

**URL:** <https://discuss.elastic.co/t/how-to-delete-a-field-from-an-index-while-reindexing/156613>\
**Category:** Elasticsearch\
**Created:** [November 14, 2018, 9:32am UTC](https://discuss.elastic.co/t/how-to-delete-a-field-from-an-index-while-reindexing/156613 "2018-11-14T09:32:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![i333](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@i333](https://discuss.elastic.co/u/i333)\
**Post date:** [November 14, 2018, 9:32am UTC](https://discuss.elastic.co/t/how-to-delete-a-field-from-an-index-while-reindexing/156613/1 "2018-11-14T09:32:56Z")

</div>

I have an index that I want to reindex and change its `dynamic` type from mapping to strict, but then it complains that a field doesn't exist in the new index mapping. How can I delete the field from the old index so that reindexing works?

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [November 14, 2018, 11:31am UTC](https://discuss.elastic.co/t/how-to-delete-a-field-from-an-index-while-reindexing/156613/2 "2018-11-14T11:31:24Z")

</div>

You can use an [ingest pipeline](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html) for this. An ingest pipeline pre-processes a document, before it is indexed. In this case, you can use a pipeline that uses [the `remove` processor](https://www.elastic.co/guide/en/elasticsearch/reference/current/remove-processor.html) (which removes a field from your documents).

The first step would be to define your pipeline. Let's say you want to remove the `foo` field, then your pipeline would look like this:

```auto
PUT _ingest/pipeline/my_pipeline
{
  "description": "Removes the 'foo' field", 
  "processors": [
    {
      "remove": {
        "field": "foo"
      }
    }
  ]
}

```

Now, you can reindex your data and apply this `my_pipeline` pipeline to your documents as those get reindexed:

```auto
POST _reindex
{
  "source": {
    "index": "my_old_index"
  },
  "dest": {
    "index": "my_new_index",
    "pipeline": "my_pipeline"
  }
}

```

---

<div class="post-metadata">

**Author:** ![i333](https://avatars.discourse-cdn.com/v4/letter/i/8491ac/32.png) [@i333](https://discuss.elastic.co/u/i333)\
**Post date:** [November 14, 2018, 8:43pm UTC](https://discuss.elastic.co/t/how-to-delete-a-field-from-an-index-while-reindexing/156613/3 "2018-11-14T20:43:04Z")

</div>

I get an error `reason:"field [foo] not present as part of path [foo]"`. That field exists in about half the documents but not all of them. Can the ingest pipeline still work in this case?

---

<div class="post-metadata">

**Author:** ![Jaspreet\_Singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaspreet_singh/32/58296_2.png) [@Jaspreet\_Singh](https://discuss.elastic.co/u/Jaspreet_Singh)\
**Post date:** [November 14, 2018, 8:58pm UTC](https://discuss.elastic.co/t/how-to-delete-a-field-from-an-index-while-reindexing/156613/4 "2018-11-14T20:58:21Z")

</div>

@abdon Is there a way to do this via `_update_by_query`where the query is a `match_all` query?

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [November 14, 2018, 9:58pm UTC](https://discuss.elastic.co/t/how-to-delete-a-field-from-an-index-while-reindexing/156613/5 "2018-11-14T21:58:21Z")

</div>

@i333 Yes, as [the docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/remove-processor.html) explain, you can set `ignore_missing` to `true`:

```auto
PUT _ingest/pipeline/my_pipeline
{
  "description": "Removes the 'foo' field",
  "processors": [
    {
      "remove": {
        "field": "foo",
        "ignore_missing": true
      }
    }
  ]
}

```

This requires that you are on version 6.4 or later

---

<div class="post-metadata">

**Author:** ![abdon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abdon/32/9195_2.png) [@abdon](https://discuss.elastic.co/u/abdon)\
**Post date:** [November 14, 2018, 10:00pm UTC](https://discuss.elastic.co/t/how-to-delete-a-field-from-an-index-while-reindexing/156613/6 "2018-11-14T22:00:56Z")

</div>

@Jaspreet_Singh Yes, you can also use an ingest pipeline with `_update_by_query`:

```auto
POST my_index/_update_by_query?pipeline=my_pipeline

```

---

<div class="post-metadata">

**Author:** ![Jaspreet\_Singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaspreet_singh/32/58296_2.png) [@Jaspreet\_Singh](https://discuss.elastic.co/u/Jaspreet_Singh)\
**Post date:** [November 15, 2018, 3:32pm UTC](https://discuss.elastic.co/t/how-to-delete-a-field-from-an-index-while-reindexing/156613/7 "2018-11-15T15:32:21Z")

</div>

@abdon Very interesting, thanks for sharing.

---

<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:** [December 13, 2018, 3:32pm UTC](https://discuss.elastic.co/t/how-to-delete-a-field-from-an-index-while-reindexing/156613/8 "2018-12-13T15:32:24Z")

</div>

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