# Elasticsearch picks wrong data type

**URL:** <https://discuss.elastic.co/t/elasticsearch-picks-wrong-data-type/41054>\
**Category:** Elasticsearch\
**Created:** [February 5, 2016, 11:53am UTC](https://discuss.elastic.co/t/elasticsearch-picks-wrong-data-type/41054 "2016-02-05T11:53:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kavita\_Kanojiya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kavita_kanojiya/32/7604_2.png) [@Kavita\_Kanojiya](https://discuss.elastic.co/u/Kavita_Kanojiya)\
**Post date:** [February 5, 2016, 11:53am UTC](https://discuss.elastic.co/t/elasticsearch-picks-wrong-data-type/41054/1 "2016-02-05T11:53:22Z")

</div>

I have an active record object which looks like:

# ResourceGroup id: 1, boolean\_col1: true, boolean\_col2: false

Both of the boolean columns were added at different time. When boolean\_col1 was added, elasticsearch picked up proper BOOLEAN data type. Later on, when boolean\_col2 was added, it picked up LONG data type.

However, I didnt implicitly mention the data type for the columns in my code base.  
Here, I delete whole index from elasticsearch and reindex whole records, now it picked up proper data-type (BOOLEAN).

BELOW is the code to declare searchkick:

searchkick callbacks: false, merge\_mappings: true, mappings: {  
_default_: {  
dynamic\_templates: [],  
properties: {  
term: {  
type: 'string',  
index: 'not\_analyzed'  
},  
}  
}  
}

I am puzzled how different data type was picked up ?

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [February 5, 2016, 1:31pm UTC](https://discuss.elastic.co/t/elasticsearch-picks-wrong-data-type/41054/2 "2016-02-05T13:31:54Z")

</div>

Tip: Wrap code blocks in ``` and they'll show up easier to read. Like on github.

Tip 2: You are much more likely to get specific help if you can reproduce the problem with curl and bash. Its the only way you can be sure everyone knows what you did. Personally all I know about searchkick is that it is a ruby library that can talk to Elasticsearch so I'm having to make a lot of guesses.

> [@Kavita\_Kanojiya](#):
>
> I am puzzled how different data type was picked up ?

By chance does searchkick spit out `0` and `1` instead of `false` and `true` sometimes? As useful as the automatic schema inference stuff is in Elasticsearch I tend to want to configure everything myself. I set `dynamic: false` and manually add the new fields. I treat Elasticsearch's mapping like a relational schema and make building it the responsibility of my application's maintenance scripts. You'll have to index all the documents with the new field again after modifying the mapping.

You can avoid that with templates like you are doing. I've not done it myself but I'm sure you should be able to set up a template to match that `boolean_`prefix you have. [Here](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html) are the docs.

---

<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:** [July 5, 2017, 11:18pm UTC](https://discuss.elastic.co/t/elasticsearch-picks-wrong-data-type/41054/3 "2017-07-05T23:18:32Z")

</div>


