# Making a field hidden in search \_source

**URL:** <https://discuss.elastic.co/t/making-a-field-hidden-in-search-source/338418>\
**Category:** Elasticsearch\
**Created:** [July 14, 2023, 1:28pm UTC](https://discuss.elastic.co/t/making-a-field-hidden-in-search-source/338418 "2023-07-14T13:28:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aditya\_Teltia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aditya_teltia/32/122447_2.png) [@Aditya\_Teltia](https://discuss.elastic.co/u/Aditya_Teltia)\
**Post date:** [July 14, 2023, 1:28pm UTC](https://discuss.elastic.co/t/making-a-field-hidden-in-search-source/338418/1 "2023-07-14T13:28:55Z")

</div>

I have a index which has TBs of data now I am adding a new field to it say `foo` using ingest pipeline

```auto
http://localhost:9200/_ingest/pipeline/add
{
    "processors" : [{
        "set": {
            "field" : "foo",
            "value" : 1
        }
    }]
}

http://localhost:9200/idx/_settings
{
    "index" : {
        "default_pipeline" : "add"
    }
}

```

but I want this field to be not visible when I do `_search` on that index. Is this possible by setting some mappings ?

```auto
http://localhost:9200/idx/_search

```

The field `foo` should not be included in the `_source` field of the response.

Can I set this in an existing index or some other way to achieve the same.

```auto
{
    "_source" : {
        "exclude" : "foo"
    }
}

```

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [July 14, 2023, 3:22pm UTC](https://discuss.elastic.co/t/making-a-field-hidden-in-search-source/338418/2 "2023-07-14T15:22:40Z")

</div>

Hi @Aditya_Teltia

you can do this two ways:

1 - Exclude field in query search

```auto
{
  "_source": {
    "excludes": ["name"]
  },
  "query": {
    "match_all": {}
  }
}

```

2 - Exclude field in mapping

```auto
 "mappings": {
    "_source": {
      "excludes": [
        "name"
      ]
    }

```

---

<div class="post-metadata">

**Author:** ![Aditya\_Teltia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aditya_teltia/32/122447_2.png) [@Aditya\_Teltia](https://discuss.elastic.co/u/Aditya_Teltia)\
**Post date:** [July 14, 2023, 5:05pm UTC](https://discuss.elastic.co/t/making-a-field-hidden-in-search-source/338418/3 "2023-07-14T17:05:13Z")

</div>

> [@RabBit\_BR](#):
>
> Exclude field in mapping

I am getting this

```auto
{
    "error": {
        "root_cause": [
            {
                "type": "resource_already_exists_exception",
                "reason": "index [source/cqGcvkfWTvSF2od8T-llXg] already exists",
                "index_uuid": "cqGcvkfWTvSF2od8T-llXg",
                "index": "source"
            }
        ],
        "type": "resource_already_exists_exception",
        "reason": "index [source/cqGcvkfWTvSF2od8T-llXg] already exists",
        "index_uuid": "cqGcvkfWTvSF2od8T-llXg",
        "index": "source"
    },
    "status": 400
}

```

Upon doing this

```auto
{
    "mappings" : {
        "_source": {
            "excludes": [
                "name"
            ]
        }
    }
}

```

To cut it down my question is Can we update the mapping of metadata field `_source` ?

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [July 14, 2023, 5:48pm UTC](https://discuss.elastic.co/t/making-a-field-hidden-in-search-source/338418/4 "2023-07-14T17:48:05Z")

</div>

> [@Aditya\_Teltia](#):
>
> To cut it down my question is Can we update the mapping of metadata field `_source` ?

It seems not possible to update the \_source once the index has been created.

One option is to create a new index and migrate the data from the old one to the new one (you can use the reindex api)

The other option is to use exclude in your search queries.

---

<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:** [August 11, 2023, 5:48pm UTC](https://discuss.elastic.co/t/making-a-field-hidden-in-search-source/338418/5 "2023-08-11T17:48:47Z")

</div>

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