# Adding a New field to index

**URL:** <https://discuss.elastic.co/t/adding-a-new-field-to-index/305408>\
**Category:** Elasticsearch\
**Created:** [May 23, 2022, 1:42pm UTC](https://discuss.elastic.co/t/adding-a-new-field-to-index/305408 "2022-05-23T13:42:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![icgncl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/icgncl/32/97769_2.png) [@icgncl](https://discuss.elastic.co/u/icgncl)\
**Post date:** [May 23, 2022, 1:42pm UTC](https://discuss.elastic.co/t/adding-a-new-field-to-index/305408/1 "2022-05-23T13:42:48Z")

</div>

I want to add a new field to my index which includes more than 20m documents. I have dictionary like this Template : [Catalog\_id : {Keyword: Sold Count}]

```auto
Sold Counts = {1234: {Apple:50}, 3242: {Banana:20}, 3423: {Apple:23}, ...}

```

In the index, there are many documents which share the same catalog\_id. According to each document's catalog\_id, I want to add a new field.  
`_id: 12323423423, catalog_id: 1234, name: '....', **Sold Count: [Apple,50]** `

What is the best way to insert a new field in this situtation?

---

<div class="post-metadata">

**Author:** ![icgncl](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/icgncl/32/97769_2.png) [@icgncl](https://discuss.elastic.co/u/icgncl)\
**Post date:** [May 24, 2022, 10:26am UTC](https://discuss.elastic.co/t/adding-a-new-field-to-index/305408/3 "2022-05-24T10:26:22Z")

</div>

```auto
POST test/_update_by_query
{
  "query": {
    "term": {
      "catalog_id": 12345
    }
  },
  "script" : {
    "source": "ctx._source.topics = HERE WHAT TO PUT",
    "lang": "painless"
  }
}

```

I have found update by query function, but I need to fulfill topics field as [rank\_feature](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-rank-feature-query.html). How can I do it? For example : {"milk":500}

> rank\_feature

---

<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 21, 2022, 10:26am UTC](https://discuss.elastic.co/t/adding-a-new-field-to-index/305408/4 "2022-06-21T10:26:33Z")

</div>

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