# Efficient filtering in custom plugin

**URL:** <https://discuss.elastic.co/t/efficient-filtering-in-custom-plugin/289697>\
**Category:** Elasticsearch\
**Created:** [November 19, 2021, 2:40pm UTC](https://discuss.elastic.co/t/efficient-filtering-in-custom-plugin/289697 "2021-11-19T14:40:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjanuszkiewicz-tt](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mjanuszkiewicz-tt](https://discuss.elastic.co/u/mjanuszkiewicz-tt)\
**Post date:** [November 19, 2021, 2:40pm UTC](https://discuss.elastic.co/t/efficient-filtering-in-custom-plugin/289697/1 "2021-11-19T14:40:37Z")

</div>

Hello,

I'm writing a custom plugin that allows filtering/scoring using an external service. The overhead of calling the service is relatively high: filtering a single document takes 80ms, filtering 10k documents takes 100ms. I therefore want to avoid performing single-document calls.

For a simple query/filter this is easy - I can collect all data from a segment and do a batch call to the service.

But if I want to process the data using `post_filter`/`rescore` it doesn't work - I'm not able to get information about which documents were hits before I need to call the service.

Does anyone have any ideas on how I could solve this?

---

<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:** [December 17, 2021, 2:40pm UTC](https://discuss.elastic.co/t/efficient-filtering-in-custom-plugin/289697/2 "2021-12-17T14:40:52Z")

</div>

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