# Added new field in elasticsearch

**URL:** https://discuss.elastic.co/t/added-new-field-in-elasticsearch/69651
**Category:** Elasticsearch
**Created:** [December 21, 2016, 8:57am UTC](https://discuss.elastic.co/t/added-new-field-in-elasticsearch/69651 "2016-12-21T08:57:19Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![anonymous4](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anonymous4](https://discuss.elastic.co/u/anonymous4)
#### Post date: [December 21, 2016, 8:57am UTC](https://discuss.elastic.co/t/added-new-field-in-elasticsearch/69651/1 "2016-12-21T08:57:19Z")

</div>

Hi,

I have added new field in the existing index using-  
POST honeypot/\_mapping/type  
{  
"properties" :  
{  
"extract\_only\_url" :  
{  
"type":"string",  
"index" :"not\_analyzed"  
}  
}  
}

Now when i try to access this index using python -

res = es.search(index = 'honeypot',size=honeyport\_doc\_count, body={"query": {"match\_all": {}}})  
print res

In the above response, newly added field is not visible in printing 'res'. I need to update this newly added field using python script.

---

<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: [December 21, 2016, 9:30am UTC](https://discuss.elastic.co/t/added-new-field-in-elasticsearch/69651/2 "2016-12-21T09:30:38Z")

</div>

You did not change previous documents but only the mapping.

---

<div class="post-metadata">

### Author: ![anonymous4](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anonymous4](https://discuss.elastic.co/u/anonymous4)
#### Post date: [December 21, 2016, 9:46am UTC](https://discuss.elastic.co/t/added-new-field-in-elasticsearch/69651/3 "2016-12-21T09:46:36Z")

</div>

@dadoonet can you please tell me how to do that?

---

<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: [December 21, 2016, 10:04am UTC](https://discuss.elastic.co/t/added-new-field-in-elasticsearch/69651/4 "2016-12-21T10:04:45Z")

</div>

Reindex your documents.

If you index

```auto
{
  "foo": "bar"
}

```

Then update the mapping by adding a new field `res` there is no chance that your document have been updated magically.

It will come back as you indexed it:

```auto
{
  "foo": "bar"
}

```

---

<div class="post-metadata">

### Author: ![anonymous4](https://avatars.discourse-cdn.com/v4/letter/a/c2a13f/32.png) [@anonymous4](https://discuss.elastic.co/u/anonymous4)
#### Post date: [December 21, 2016, 10:16am UTC](https://discuss.elastic.co/t/added-new-field-in-elasticsearch/69651/5 "2016-12-21T10:16:20Z")

</div>

@dadoonet This is what i am asking, Basically i added new field in elasticsearch mapping but how can i add new field in all documents syntactically.  
Reindexing basically copy all the document from old index to new index but how the new field will be added in documents?  
if \_update\_by\_query works for this,then how to write that?

---

<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: [December 21, 2016, 10:38am UTC](https://discuss.elastic.co/t/added-new-field-in-elasticsearch/69651/6 "2016-12-21T10:38:47Z")

</div>

How elasticsearch can know what is the value you want to set for this field?

You must provide it.

The best option IMO is to reindex all your data:

- from the source. If the data is coming from your database, read its value and provide it to elasticsearch
- using [reindex API](https://www.elastic.co/guide/en/elasticsearch/reference/5.1/docs-reindex.html) and [ingest features](https://www.elastic.co/guide/en/elasticsearch/reference/current/ingest.html).

Something like:

```auto
PUT _ingest/pipeline/my-pipeline-id
{
  "processors" : [
    {
      "set" : {
        "field": "foo",
        "value": "bar"
      }
    }
  ]
}
POST _reindex
{
  "source": {
    "index": "oldindex"
  },
  "dest": {
    "index": "newindex",
    "pipeline": "my-pipeline-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: [January 18, 2017, 10:38am UTC](https://discuss.elastic.co/t/added-new-field-in-elasticsearch/69651/7 "2017-01-18T10:38:49Z")

</div>

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