# Custom filter based on a BitSet for performing a TermsQuery like filtering

**URL:** <https://discuss.elastic.co/t/custom-filter-based-on-a-bitset-for-performing-a-termsquery-like-filtering/34189>\
**Category:** Elasticsearch\
**Created:** [November 9, 2015, 7:17pm UTC](https://discuss.elastic.co/t/custom-filter-based-on-a-bitset-for-performing-a-termsquery-like-filtering/34189 "2015-11-09T19:17:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![swamirajamohan](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@swamirajamohan](https://discuss.elastic.co/u/swamirajamohan)\
**Post date:** [November 9, 2015, 7:17pm UTC](https://discuss.elastic.co/t/custom-filter-based-on-a-bitset-for-performing-a-termsquery-like-filtering/34189/1 "2015-11-09T19:17:54Z")

</div>

Disclaimer: I am an ElasticSearch newbie.

I am looking at working on a custom implementation of a **TermsQuery like filter** that will key off a **BitSet** that will house match/should not match encoded as bits and the index of the bitset serving as the document identifier. I would like to know how I can feed such a bitset at querytime and get ElasticSearch to filter out documents based on this BitSet.

I am looking at using the above approach to perform ACL Filtering on indexed documents (to avoid having to index acls which change far too frequently)

The bitset itself will represent a user's access to a set of documents.

The corpus itself will hold at most a million entries and as such the bitset would be a size of that range ( 1 million or so).

I have a vague understanding that Lucene uses BitSets for filters albeit at a segment level. How would I implement such a BitSet filter which will operate at an Index level?

It would be great if someone can throw some pointers as to how this can be achieved

Thanks  
Swami

---

<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:39pm UTC](https://discuss.elastic.co/t/custom-filter-based-on-a-bitset-for-performing-a-termsquery-like-filtering/34189/2 "2017-07-05T23:39:42Z")

</div>


