# \[CLOSED\] IllegalArgumentException when index/mapping creation involves Keyword field

**URL:** https://discuss.elastic.co/t/closed-illegalargumentexception-when-index-mapping-creation-involves-keyword-field/146729
**Category:** Elasticsearch
**Created:** [August 30, 2018, 3:02pm UTC](https://discuss.elastic.co/t/closed-illegalargumentexception-when-index-mapping-creation-involves-keyword-field/146729 "2018-08-30T15:02:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![shiouming](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@shiouming](https://discuss.elastic.co/u/shiouming)
#### Post date: [August 30, 2018, 3:02pm UTC](https://discuss.elastic.co/t/closed-illegalargumentexception-when-index-mapping-creation-involves-keyword-field/146729/1 "2018-08-30T15:02:17Z")

</div>

[CLOSED] It was my mistake, there are other code that called **save()** prior to **init()**. Changing the order fixes this exception.

* * *

I'm completely new to ES, trying out **ES 6.2.3** with **ES DSL 6.2.1** (official client lib for Python). Referring to documentation, I defined below model by using Document.

```
class Company(Document):
    hq_country_iso = Keyword()
    co_name = Text()

    class Index:
        name = 'company'

    def save(self, **kwargs):
        return super(Company, self).save(**kwargs)

```

When calling **Company.init()** of Document API to create index, ES throws below exception. However, the index is still created and I'm able store data into ES (I haven't try production mode though). If I remove the hq\_country\_iso KEYWORD field or change it as TEXT field, this exception will go away. I'd tried following but have no luck:

- ensured that the index doesn't exist (the word **current\_type** in error msg is beyond my comprehension)
- cleared cache
- restarted ES

Any clue what could be causing this? Thanks.

```
[2018-08-30T21:32:48,405][DEBUG][o.e.a.a.i.m.p.TransportPutMappingAction] [wm_PvYm] failed to put mappings on indices [[[company/-MEgVBzSSY6GmizoYSJgdg]]], type [doc]

java.lang.IllegalArgumentException: mapper [hq_country_iso] of different type, current_type [text], merged_type [keyword]

at org.elasticsearch.index.mapper.FieldMapper.doMerge(FieldMapper.java:354) ~[elasticsearch-6.2.3.jar:6.2.3]

at org.elasticsearch.index.mapper.TextFieldMapper.doMerge(TextFieldMapper.java:372) ~[elasticsearch-6.2.3.jar:6.2.3]

at org.elasticsearch.index.mapper.FieldMapper.merge(FieldMapper.java:340) ~[elasticsearch-6.2.3.jar:6.2.3]

at org.elasticsearch.index.mapper.FieldMapper.merge(FieldMapper.java:52) ~[elasticsearch-6.2.3.jar:6.2.3]

at org.elasticsearch.index.mapper.ObjectMapper.doMerge(ObjectMapper.java:477) ~[elasticsearch-6.2.3.jar:6.2.3]

at org.elasticsearch.index.mapper.RootObjectMapper.doMerge(RootObjectMapper.java:277) ~[elasticsearch-6.2.3.jar:6.2.3]

at org.elasticsearch.index.mapper.ObjectMapper.merge(ObjectMapper.java:449) ~[elasticsearch-6.2.3.jar:6.2.3]

at org.elasticsearch.index.mapper.RootObjectMapper.merge(RootObjectMapper.java:272) ~[elasticsearch-6.2.3.jar:6.2.3]

at org.elasticsearch.index.mapper.Mapping.merge(Mapping.java:89) ~[elasticsearch-6.2.3.jar:6.2.3]

at org.elasticsearch.index.mapper.DocumentMapper.merge(DocumentMapper.java:304) ~[elasticsearch-6.2.3.jar:6.2.3]

at org.elasticsearch.cluster.metadata.MetaDataMappingService$PutMappingExecutor.applyRequest(MetaDataMappingService.java:267) ~[elasticsearch-6.2.3.jar:6.2.3]

at org.elasticsearch.cluster.metadata.MetaDataMappingService$PutMappingExecutor.execute(MetaDataMappingService.java:230) ~[elasticsearch-6.2.3.jar:6.2.3]

at org.elasticsearch.cluster.service.MasterService.executeTasks(MasterService.java:643) ~[elasticsearch-6.2.3.jar:6.2.3]
```

---

<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: [September 27, 2018, 3:02pm UTC](https://discuss.elastic.co/t/closed-illegalargumentexception-when-index-mapping-creation-involves-keyword-field/146729/2 "2018-09-27T15:02:29Z")

</div>

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