# Cannot change similarity with put\_mapping: conflict with existing mapping

**URL:** https://discuss.elastic.co/t/cannot-change-similarity-with-put-mapping-conflict-with-existing-mapping/206653
**Category:** Elasticsearch
**Created:** [November 5, 2019, 5:40pm UTC](https://discuss.elastic.co/t/cannot-change-similarity-with-put-mapping-conflict-with-existing-mapping/206653 "2019-11-05T17:40:19Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![winklefr](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@winklefr](https://discuss.elastic.co/u/winklefr)
#### Post date: [November 5, 2019, 5:40pm UTC](https://discuss.elastic.co/t/cannot-change-similarity-with-put-mapping-conflict-with-existing-mapping/206653/1 "2019-11-05T17:40:19Z")

</div>

Hello,

I recently set up an elastic search cluster. I have created an index with some text field. I managed to add a new text field using the put\_mapping API.

But I cannot update the related similarity. I get the following error message, regarding of the filed I try to work on:  
`RequestError(400, 'illegal_argument_exception', 'Mapper for [test] conflicts with existing mapping:\n[mapper [test] has different [similarity]]')`

I use elasticsearch 7.4.1and elasticsearch-py 7.0.5 (but I get the same error if I do it with a curl -XPUT).

Here is my index structure after creation

 ![test_index2](https://us1.discourse-cdn.com/elastic/original/3X/5/8/58502e26a686096c1359170d1dc17ad4098e08d1.png)

and after adding a test field and defining a similarity that I want to use

 ![test_index2_up](https://us1.discourse-cdn.com/elastic/original/3X/2/8/281f58bec0f0bee1ebb926c08dffc3bfa1f60cea.png)

I did the following code to insert the field and define the similarity:

```
request_test = {
    "properties": 
    {"test": {'type': 'text'}
    }
}

request_settings = {
  "settings" : {
        "index" : {
            "similarity" : {
              "my_similarity" : {
                "type" : "DFI",
                "independence_measure" : "saturated"
              }
            }
        }
    }
}

es.indices.close('test_index2')
es.indices.put_settings(request_settings,'test_index2')
es.indices.put_mapping(body=request_test,index='test_index2')
es.indices.open('test_index2')

```

So this works just fine. But when I try to force my\_similarity for a field (any of them), I get the error, even though "similarity" is supposes to be a mapping parameter ([https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-params.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-params.html))

Here is the code I use:

```
request_mapping = {
    "properties": {'test': {'type': 'text', 'similarity': 'my_similarity'}}
} 
es.indices.close('test_index2')
es.indices.put_mapping(body=request_mapping,index='test_index2')
es.indices.open('test_index2')

```

(and it is actually the same if I use BM25)

I get the following error:

`RequestError(400, 'illegal_argument_exception', 'Mapper for [test] conflicts with existing mapping:\n[mapper [test] has different [similarity]]')`

And I get the same error if I use the following command in a term:

`curl -H "Content-Type: application/json" -XPUT http://127.0.0.1:9200/test_index2/_mapping -d '{"propertie...'`

So there is obviously something that I don't understand, since it is said that is it possible to update the similarity, but I get an error saying it can't…

Many thanks for all the help you can provide.

---

<div class="post-metadata">

### Author: ![winklefr](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@winklefr](https://discuss.elastic.co/u/winklefr)
#### Post date: [November 6, 2019, 9:55am UTC](https://discuss.elastic.co/t/cannot-change-similarity-with-put-mapping-conflict-with-existing-mapping/206653/2 "2019-11-06T09:55:20Z")

</div>

Hello all,

Interesting thing that I just tested:

If I create my test field with

```
request_test = {
    "properties": 
    {"test": {'type': 'text', 'similarity': 'my_similarity'}
    }
}

```

it just works fine (at least there is no conflict). Which leads me to believe that similarity cannot be changed once fixed on a field in an index, thus requiring a new index/reindexing.

Am I correct ?

Many thanks

---

<div class="post-metadata">

### Author: ![winklefr](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@winklefr](https://discuss.elastic.co/u/winklefr)
#### Post date: [November 6, 2019, 10:40am UTC](https://discuss.elastic.co/t/cannot-change-similarity-with-put-mapping-conflict-with-existing-mapping/206653/3 "2019-11-06T10:40:11Z")

</div>

I also tried by reindexing (creating new index and explicitly set the similarity to what I want in some fields and then importing data with reindex API), and it obviously worked.

So I just need a confirmation that we can't change a similarity once the field is created.

Thanks

---

<div class="post-metadata">

### Author: ![winklefr](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@winklefr](https://discuss.elastic.co/u/winklefr)
#### Post date: [November 11, 2019, 4:27pm UTC](https://discuss.elastic.co/t/cannot-change-similarity-with-put-mapping-conflict-with-existing-mapping/206653/4 "2019-11-11T16:27:30Z")

</div>

Hello everyone, no one for this issue?

Thanks

---

<div class="post-metadata">

### Author: ![Glen\_Smith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/glen_smith/32/111656_2.png) [@Glen\_Smith](https://discuss.elastic.co/u/Glen_Smith)
#### Post date: [November 11, 2019, 11:56pm UTC](https://discuss.elastic.co/t/cannot-change-similarity-with-put-mapping-conflict-with-existing-mapping/206653/5 "2019-11-11T23:56:51Z")

</div>

Hello,

You are correct. You can only configure the similarity for a field when creating the field.

---

<div class="post-metadata">

### Author: ![winklefr](https://avatars.discourse-cdn.com/v4/letter/w/3e96dc/32.png) [@winklefr](https://discuss.elastic.co/u/winklefr)
#### Post date: [November 13, 2019, 2:48pm UTC](https://discuss.elastic.co/t/cannot-change-similarity-with-put-mapping-conflict-with-existing-mapping/206653/6 "2019-11-13T14:48:52Z")

</div>

Hello,

Many thanks for your answer. I managed to change it by reindexing, but also I figured out how to change the default similarity on all fields of an existing index. Wich is fine for me.

I had some trooble when I wanted to change multiple times the similarity: in the put\_settings request, I had to set to "None" (as coding in Python) the options of the previous similarity in order to erase them, otherwise it would'nt change and return an error code (saying the previous options where irregular for the new similarity).

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: [December 11, 2019, 2:48pm UTC](https://discuss.elastic.co/t/cannot-change-similarity-with-put-mapping-conflict-with-existing-mapping/206653/7 "2019-12-11T14:48:55Z")

</div>

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