# Storing booleans as '0' and '1'

**URL:** <https://discuss.elastic.co/t/storing-booleans-as-0-and-1/63181>\
**Category:** Elasticsearch\
**Created:** [October 17, 2016, 10:36am UTC](https://discuss.elastic.co/t/storing-booleans-as-0-and-1/63181 "2016-10-17T10:36:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul2](https://avatars.discourse-cdn.com/v4/letter/p/df705f/32.png) [@paul2](https://discuss.elastic.co/u/paul2)\
**Post date:** [October 17, 2016, 10:36am UTC](https://discuss.elastic.co/t/storing-booleans-as-0-and-1/63181/1 "2016-10-17T10:36:13Z")

</div>

Hi, I want to store booleans as '1's and '0's. Is this possible? I've tried storing them as strings but elasticsearch infered they were boolean value.

Thanks

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [October 17, 2016, 5:02pm UTC](https://discuss.elastic.co/t/storing-booleans-as-0-and-1/63181/2 "2016-10-17T17:02:52Z")

</div>

Hi,

What exactly do you mean by "store" them? If you don't provide a [Mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html) elasticsearch will try to infer the field type of fields it doesn't know yet. Values like 0/1/true/false are treated as ["boolean"](https://www.elastic.co/guide/en/elasticsearch/reference/current/boolean.html) if not explicitely specified. Regardless, if you index new documents with that said field, the "\_source" of that document will always reflect the original JSON you used at index time, so if you have indexed a boolean field as `"foo" : 1`, `"foo": "1"` or `"foo": true`, this will always reflect in the docs "\_source". Under the hood, booleans are stored as 1-char bytes in Lucene, so nothing to do there.

Or do you want to store them as Strings for some other reason?

---

<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, 10:11pm UTC](https://discuss.elastic.co/t/storing-booleans-as-0-and-1/63181/3 "2017-07-05T22:11:42Z")

</div>


