# How to search for parts of a string in the \_id field in an existing index

**URL:** https://discuss.elastic.co/t/how-to-search-for-parts-of-a-string-in-the-id-field-in-an-existing-index/239622
**Category:** Elasticsearch
**Created:** [July 2, 2020, 11:16am UTC](https://discuss.elastic.co/t/how-to-search-for-parts-of-a-string-in-the-id-field-in-an-existing-index/239622 "2020-07-02T11:16:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![BjornOlavBerg](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@BjornOlavBerg](https://discuss.elastic.co/u/BjornOlavBerg)
#### Post date: [July 2, 2020, 11:16am UTC](https://discuss.elastic.co/t/how-to-search-for-parts-of-a-string-in-the-id-field-in-an-existing-index/239622/1 "2020-07-02T11:16:06Z")

</div>

Hie,

I am working with an existing Elastic Search index, trying to search for a string in the \_id field.

The \_id in this index consists of two concatinated strings, and I need to be able to search for the second part of that string.  
After reading documentation I have found out that I probably should use ngram to search for a substring, but I can't make this work properly.

I have found an example online from someone who was trying to do the same, så I updated my index with the following:

```auto
PUT /"myIndex"
{"settings": {
    "number_of_shards": 1, 
    "analysis": {
        "filter": {
            "partial_filter": { 
                "type": "ngram",
                "min_gram": 2,
                "max_gram": 20
            }
        },
        "analyzer": {
            "partial": {
                "type": "custom",
                "tokenizer": "standard",
                "filter": [
                    "lowercase",
                    "partial_filter" 
                ]
            }
        }
    }
}}

```

And then tried to add this:

```auto
PUT /"index"/_mapping/type2
{
    "type2": {
        "properties": {
            "_id": {
                "type": "string",
                "analyzer": "partial"
            }
        }
    }
}

```

That gives me an exception: "Rejecting mapping update to [bci\_report\_provider\_s\_dev-"myIndex"] as the final mapping would have more than 1 type: [type2, bci-report]"

How can I resolve this, and is there another way to be able to de a partial search on the \_id field?

Thanks a lot in advance!

Bjørn Olav Berg

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [July 6, 2020, 7:12am UTC](https://discuss.elastic.co/t/how-to-search-for-parts-of-a-string-in-the-id-field-in-an-existing-index/239622/2 "2020-07-06T07:12:25Z")

</div>

I would recommend storing the id within the document.

---

<div class="post-metadata">

### Author: ![BjornOlavBerg](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@BjornOlavBerg](https://discuss.elastic.co/u/BjornOlavBerg)
#### Post date: [July 6, 2020, 9:17am UTC](https://discuss.elastic.co/t/how-to-search-for-parts-of-a-string-in-the-id-field-in-an-existing-index/239622/3 "2020-07-06T09:17:48Z")

</div>

Thanks for your reply. That wolud be the best solution and we will do that in the future, but we have an existing database with many millions of instances, which we need to search through.

Do you know if it is possible and if so, how, to copy the \_id value to another field. I have tried to add a copy\_to clause for the \_id field, but am getting the message that the \_id field cannot be defined twice in the index.

Thanks again!

Bjørn Olav Berg

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [July 6, 2020, 9:24am UTC](https://discuss.elastic.co/t/how-to-search-for-parts-of-a-string-in-the-id-field-in-an-existing-index/239622/4 "2020-07-06T09:24:02Z")

</div>

As far as know that is not possible.

---

<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 3, 2020, 9:24am UTC](https://discuss.elastic.co/t/how-to-search-for-parts-of-a-string-in-the-id-field-in-an-existing-index/239622/5 "2020-08-03T09:24:05Z")

</div>

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