# Is reindexing to a new index necessary after updating settings and mappings to support a multi-field in elasticsearch?

**URL:** <https://discuss.elastic.co/t/is-reindexing-to-a-new-index-necessary-after-updating-settings-and-mappings-to-support-a-multi-field-in-elasticsearch/319260>\
**Category:** Elasticsearch\
**Tags:** reindex\
**Created:** [November 18, 2022, 4:40am UTC](https://discuss.elastic.co/t/is-reindexing-to-a-new-index-necessary-after-updating-settings-and-mappings-to-support-a-multi-field-in-elasticsearch/319260 "2022-11-18T04:40:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karthik\_Amar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karthik_amar/32/111447_2.png) [@Karthik\_Amar](https://discuss.elastic.co/u/Karthik_Amar)\
**Post date:** [November 18, 2022, 4:40am UTC](https://discuss.elastic.co/t/is-reindexing-to-a-new-index-necessary-after-updating-settings-and-mappings-to-support-a-multi-field-in-elasticsearch/319260/1 "2022-11-18T04:40:02Z")

</div>

Please consider the scenario.

_ **Existing System** _

1. I have an index named `contacts_index` with 100 documents.
2. Each document has property named `city` with some text value in it.
3. Index has `settings` as the following

```auto
    {
      "analyzer": {
        "city_analyzer": {
          "filter": [
            "lowercase"
          ],
          "tokenizer": "city_tokenizer"
        },
        "search_analyzer": {
          "filter": [
            "lowercase"
          ],
          "tokenizer": "keyword"
        }
      },
      "tokenizer": {
        "city_tokenizer": {
          "token_chars": [
            "letter"
          ],
          "min_gram": "2",
          "type": "ngram",
          "max_gram": "30"
        }
      }
    }

```

1. The index has the following mapping for city field to support `matching sub-text search`.

```auto
    {
       "city" : {
              "type" : "text",
              "analyzer" : "city_analyzer",
              "search_analyzer" : "search_analyzer"
            }
    }

```

_ **Proposed System** _

Now we want to perform autocomplete on city field. for example for city with value `Seattle`. We want to get the document when the user types `s, se, sea, seat, seatt, seattl, seattle` but Only when they query with the above prefix text. For example not when they type eattle. etc..

We have planned to attain this with the help of one more multi-field for city property with different of type text and different analyzer.

To attain this we have done the following.

1. Updated the settings to support autocomplete

```auto
    PUT /staging-contacts-index-v4.0/_settings?preserve_existing=true
    {
      "analysis": {
        "analyzer": {
          "autocomplete_analyzer": {
            "filter": [
              "lowercase"
            ],
            "tokenizer": "autocomplete_tokenizer"
          }
        },
        "tokenizer": {
          "autocomplete_tokenizer": {
            "token_chars": [
              "letter"
            ],
            "min_gram": "1",
            "type": "edge_ngram",
            "max_gram": "100"
          }
        }
      }
    }

```

1. Update the mapping of `city` field with multi-field `autocomplete` to support autocomplete

```auto
    {
       "city" : {
              "type" : "text",
              "fields" : {
                "autocomplete" : {
                  "type" : "text",
                  "analyzer" : "autocomplete_analyzer",
                  "search_analyzer" : "search_analyzer"
                }
              },
              "analyzer" : "city_analyzer",
              "search_analyzer" : "search_analyzer"
            }
    }

```

_ **Findings** _

1. For `any new document` that will be newly created after updating autocomplete multi-field settings, autocomplete search is working as expected

2. For `existing documents`, if the value of city field `changes`, for example `seattle to chicago,` the document is fetched when making autocomplete search.

3. We are planning to make use of [update api](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html) to fetch and update the existing 100 documents so that autocomplete works for existing documents as well. However while trying to use the update api, we are getting  
`{"result" : "noop"}`  
And the autocomplete search is not working.

I can infer that since the values were not changing, elasticsearch not creating tokens for autocomplete field.

_ **Question** _

From the research we have done, there are two options to make sure the `existing 100 documents` can perform autocomplete search.

1. Use [Reindex](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-reindex.html) api for existing 100 documents.
2. Fetch all 100 documents and Use document [Index](https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html) api to update the existing 100 documents which will create all the tokens in the process.

Which option is preferable and why?

Thanks for taking time to read through.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [November 18, 2022, 4:43am UTC](https://discuss.elastic.co/t/is-reindexing-to-a-new-index-necessary-after-updating-settings-and-mappings-to-support-a-multi-field-in-elasticsearch/319260/2 "2022-11-18T04:43:20Z")

</div>

Use reindex as it's a single call to do it.

---

<div class="post-metadata">

**Author:** ![Karthik\_Amar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karthik_amar/32/111447_2.png) [@Karthik\_Amar](https://discuss.elastic.co/u/Karthik_Amar)\
**Post date:** [November 18, 2022, 9:14am UTC](https://discuss.elastic.co/t/is-reindexing-to-a-new-index-necessary-after-updating-settings-and-mappings-to-support-a-multi-field-in-elasticsearch/319260/3 "2022-11-18T09:14:25Z")

</div>

Okay @warkolm . Thank you for taking time to reply. 100 Documents i gave here as an example, The cluster has 4 nodes with 70 million documents of size 1.3 TB. You still recommend the same?

---

<div class="post-metadata">

**Author:** ![defalt](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/defalt/32/71379_2.png) [@defalt](https://discuss.elastic.co/u/defalt)\
**Post date:** [November 18, 2022, 10:29am UTC](https://discuss.elastic.co/t/is-reindexing-to-a-new-index-necessary-after-updating-settings-and-mappings-to-support-a-multi-field-in-elasticsearch/319260/4 "2022-11-18T10:29:47Z")

</div>

Reindex API is made for this scenario. There is nothing that would work better than this.

---

<div class="post-metadata">

**Author:** ![Karthik\_Amar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karthik_amar/32/111447_2.png) [@Karthik\_Amar](https://discuss.elastic.co/u/Karthik_Amar)\
**Post date:** [November 20, 2022, 12:57am UTC](https://discuss.elastic.co/t/is-reindexing-to-a-new-index-necessary-after-updating-settings-and-mappings-to-support-a-multi-field-in-elasticsearch/319260/5 "2022-11-20T00:57:21Z")

</div>

Okay @defalt . Thank you for clarifying.

---

<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 18, 2022, 12:58am UTC](https://discuss.elastic.co/t/is-reindexing-to-a-new-index-necessary-after-updating-settings-and-mappings-to-support-a-multi-field-in-elasticsearch/319260/6 "2022-12-18T00:58:18Z")

</div>

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