# Adding Custom Fields to an Elasticsearch Index

**URL:** <https://discuss.elastic.co/t/adding-custom-fields-to-an-elasticsearch-index/334794>\
**Category:** Elasticsearch\
**Created:** [May 31, 2023, 11:29am UTC](https://discuss.elastic.co/t/adding-custom-fields-to-an-elasticsearch-index/334794 "2023-05-31T11:29:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abeer\_Islam](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abeer_islam/32/121641_2.png) [@Abeer\_Islam](https://discuss.elastic.co/u/Abeer_Islam)\
**Post date:** [May 31, 2023, 11:29am UTC](https://discuss.elastic.co/t/adding-custom-fields-to-an-elasticsearch-index/334794/1 "2023-05-31T11:29:09Z")

</div>

Hi,  
I want to add custom fields (Year, Yearly Week, Week, Month, Exist (a boolean value)) and their corresponding values into an ES index using API. SInce, I am running the OpenDistro for Elasticsearch version which doesn't have the Add field in Kibana under Index Pattern settings.  
So, I tried using Elasticsearch PUT, POST APIs for updating mappings for adding the custom fields and their corresponding values. But both the custom fields and values didn't appear in the Index although the added fields did appear in the Index Pattern setting under Stack Management of the particular Index to which the custom fields were added and when the "Hide missing fields" option was unchecked only then the custom fields appeared in the index.

Following different APIs were used:

```auto
PUT vulns
{
  "mappings": {
    "numeric_detection": true
  }
}

PUT vulns/_doc/1
{
  "my_float": "120.00", 
  "my_integer": "100" 
}

```

```auto
PUT /vulns/_doc/1
{
   "title": "This doc adds a new field",
   "stash": { "new_field": "Success!" }
}

```

```auto
POST vulns/_doc
{
  "Year": 2023,
  "Week": 20,
  "Yearly_Week": 202305,
  "Month": 5,
  "Exist": true
}

```

```auto
PUT _index_template/template-1
{
  "index_patterns": ["vulns*"],
  "template": {
    "mappings": {
      "properties": {
        "Year": {
          "type": "integer"
        },
        "Week": {
          "type": "integer"
        },
        "Yearly_Week": {
          "type": "integer"
        },
        "Month": {
          "type": "integer"
        },
        "Exist": {
          "type": "boolean"
        }
      }
    }
  }
}

POST vulns/_doc
{
  "Year": 2023,
  "Week": 20,
  "Yearly_Week": 202305,
  "Month": 5,
  "Exist": true
}

```

```auto
POST vulns/_bulk
{ "index" : {} }
{ "Year": 2023, "Week": 20, "Yearly_Week": 202305, "Month": 5, "Exist": true, "Exit": false }

```

I tried all of the above-mentioned methods but still failed to achieve my goal. Kindly suggest me a way using which I can easily add custom fields and their corresponding values to an Index.

Thanks & Regards

---

<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:** [May 31, 2023, 11:29am UTC](https://discuss.elastic.co/t/adding-custom-fields-to-an-elasticsearch-index/334794/2 "2023-05-31T11:29:10Z")

</div>

OpenSearch/OpenDistro are AWS run products and differ from the original Elasticsearch and Kibana products that Elastic builds and maintains. You may need to contact them directly for further assistance.

(This is an automated response from your friendly Elastic bot. Please report this post if you have any suggestions or concerns :elasticheart: )

---

<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 28, 2023, 11:29am UTC](https://discuss.elastic.co/t/adding-custom-fields-to-an-elasticsearch-index/334794/3 "2023-06-28T11:29:16Z")

</div>

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