简体   繁体   中英

Partial Type Mapping in ElasticSearch

I have a JSON with lots of data. Now all the fields does not have fixed types of data every time. For example some Ids are some time appearing as perfect integer, like 123 , but some time it appears as String , like a123 .

By default, index.mapper.dynamic is true . So type mapping is automatically defined as per data received for first time for indexing (While creating the index for first set of JSON data) . Now let's say, my first set of data is having Id value as 123 , so type of Id is mapped as Integer . So when some data have Id as String , like a123 , then it is throwing exception, as the type is mapped to Integer .

We can turn off dynamic type mapping by putting index.mapper.dynamic: false in elasticsearch.yml . But it will disable type mapping for all fields. I want to have Partial Type Mapping . For some fields, like date , I would like to have type mapping for datetime in specific format.

So my goal is to achieve type mapping only for few fields of JSON data. So if there are 20 fields in JSON, I bother for types of 4 fields, for other 16 fields if they are considered as String, I am OK with that.

Is there any way I can achieve such partial type mapping ? I am using Java client.

Short answer - no.

A bit longer - ElasticSearch is not schema-less - it's dynamic. It means that every field has a type , but this type doesn't need to be specified in advance but can be dynamically determined according to the first value which is encountered. But again - there is no such thing as a field with no mapping. You can't have a field that contains different types of values. If this is something you must have you can just convert all the values of this field to string.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM