# Bitwise operations in elasticsearch without script?

**URL:** <https://discuss.elastic.co/t/bitwise-operations-in-elasticsearch-without-script/40320>\
**Category:** Elasticsearch\
**Created:** [January 28, 2016, 6:05am UTC](https://discuss.elastic.co/t/bitwise-operations-in-elasticsearch-without-script/40320 "2016-01-28T06:05:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ArivazhaganJ](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@ArivazhaganJ](https://discuss.elastic.co/u/ArivazhaganJ)\
**Post date:** [January 28, 2016, 6:05am UTC](https://discuss.elastic.co/t/bitwise-operations-in-elasticsearch-without-script/40320/1 "2016-01-28T06:05:01Z")

</div>

I am using elasticsearch 1.5.1. I want to perform bit wise operations on my documents in elasticsearch.

Bitwise equivalent in elasticsearch as in SQL: [https://msdn.microsoft.com/en-us/library/ms176122.aspx](https://msdn.microsoft.com/en-us/library/ms176122.aspx)

I do not want to use any scripting languages as it is not preferred. can some one provide some example on performing bit wise operations?

I tried looking out for various examples in internet but could not find any sample code /query in elasticsearch.

---

<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:** [January 28, 2016, 4:29pm UTC](https://discuss.elastic.co/t/bitwise-operations-in-elasticsearch-without-script/40320/2 "2016-01-28T16:29:25Z")

</div>

> [@ArivazhaganJ](#):
>
> I do not want to use any scripting languages as it is not preferred. can some one provide some example on performing bit wise operations?

I don't believe there is a way to do generic bitwise stuff without scripts. On the other hand, depending on what you want to do you rewrite it to a range query or a bool query with multiple range queries in the `should` clause. That is likely to be more efficient in some cases than a script because it can use the terms dictionary instead of doc values.

Its likely possible for you to implement more queries to do bitwise stuff against the terms dictionary in a plugin but that is a reasonably involved project all on its own. If you want to learn and you desperately need the speed its something you can think about.

---

<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:20pm UTC](https://discuss.elastic.co/t/bitwise-operations-in-elasticsearch-without-script/40320/3 "2017-07-05T23:20:45Z")

</div>


