# Data Types ignored when adding new document?

**URL:** <https://discuss.elastic.co/t/data-types-ignored-when-adding-new-document/69499>\
**Category:** Elasticsearch\
**Created:** [December 19, 2016, 9:56pm UTC](https://discuss.elastic.co/t/data-types-ignored-when-adding-new-document/69499 "2016-12-19T21:56:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![west415](https://avatars.discourse-cdn.com/v4/letter/w/919ad9/32.png) [@west415](https://discuss.elastic.co/u/west415)\
**Post date:** [December 19, 2016, 9:56pm UTC](https://discuss.elastic.co/t/data-types-ignored-when-adding-new-document/69499/1 "2016-12-19T21:56:18Z")

</div>

Hi,

I'm using elasticsearch 5.1.1.

I created custom mapping and on one of my fields I have this (below). My goal being the "active" field should only allow a true/false value.

```
 "properties": {
      "active": {
      "type": "boolean"
     },
  }

```

If I then create a new document and populate the active field with a value say "r2452tgfw" (a non-Boolean value) or something, it allows the document to be created. Maybe that's just how it is or maybe I'm missing something, but is there a way to prevent a document from being indexed if one tries to put data in a field that is of a different data type? I'm expecting some sort of validation to happen I suppose.

---

<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:** [December 19, 2016, 10:11pm UTC](https://discuss.elastic.co/t/data-types-ignored-when-adding-new-document/69499/2 "2016-12-19T22:11:47Z")

</div>

Have a look at [coerce](https://www.elastic.co/guide/en/elasticsearch/reference/current/coerce.html). I'm not 100% sure it effects booleans but it is a fairly important read anyway even if it turns out not to be what is up.

---

<div class="post-metadata">

**Author:** ![west415](https://avatars.discourse-cdn.com/v4/letter/w/919ad9/32.png) [@west415](https://discuss.elastic.co/u/west415)\
**Post date:** [December 20, 2016, 12:06am UTC](https://discuss.elastic.co/t/data-types-ignored-when-adding-new-document/69499/3 "2016-12-20T00:06:25Z")

</div>

Thanks for the reply @nik9000. After performing a test, it does not seem to affect booleans though, but it was a helpful read.

---

<div class="post-metadata">

**Author:** ![west415](https://avatars.discourse-cdn.com/v4/letter/w/919ad9/32.png) [@west415](https://discuss.elastic.co/u/west415)\
**Post date:** [December 20, 2016, 12:15am UTC](https://discuss.elastic.co/t/data-types-ignored-when-adding-new-document/69499/4 "2016-12-20T00:15:26Z")

</div>

I'm guessing this is why booleans are treated differently:

> Boolean fields accept JSON true and false values, but can also accept strings and numbers which are interpreted as either true or false:

> **[Boolean datatype | Elasticsearch Guide \[2.1\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/2.1/boolean.html)**

---

<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:** [December 20, 2016, 12:27am UTC](https://discuss.elastic.co/t/data-types-ignored-when-adding-new-document/69499/5 "2016-12-20T00:27:05Z")

</div>

Yeah, I just dug through the code again. We have a lot of weird leniency around booleans. There is a proposal to make them properly strict:

> <https://github.com/elastic/elasticsearch/pull/22200>

I commented on it, even. But our "these six things mean false, everything else is true" way of doing it keeps slipping my mind.

So, at this point there is no way to be strict about booleans.

---

<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:** [January 17, 2017, 12:27am UTC](https://discuss.elastic.co/t/data-types-ignored-when-adding-new-document/69499/6 "2017-01-17T00:27:25Z")

</div>

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