# Plugin - How to intercept a shard query phase and reject?

**URL:** <https://discuss.elastic.co/t/plugin-how-to-intercept-a-shard-query-phase-and-reject/248108>\
**Category:** Elasticsearch\
**Created:** [September 10, 2020, 5:32am UTC](https://discuss.elastic.co/t/plugin-how-to-intercept-a-shard-query-phase-and-reject/248108 "2020-09-10T05:32:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![araniera](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@araniera](https://discuss.elastic.co/u/araniera)\
**Post date:** [September 10, 2020, 5:32am UTC](https://discuss.elastic.co/t/plugin-how-to-intercept-a-shard-query-phase-and-reject/248108/1 "2020-09-10T05:32:00Z")

</div>

Hello, am toying with a plugin and am trying to add some behavior where I can intercept a query happening at the shard level.

This can be done it seems through the SearchOperationListener with the onPreQueryPhase and onQueryPhase.

I'd like to be able to do some validations inside these and reject the shard query phase based on those validations. i.e. if so and so is true fail this specific shard search.

It seems the exceptions thrown from inside the listeners are caught and logged as warnings and silently ignored otherwise. Is there a way to fail the shard query phase from inside these hooks or is there a better way to do this?

Thanks

---

<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:** [October 8, 2020, 5:32am UTC](https://discuss.elastic.co/t/plugin-how-to-intercept-a-shard-query-phase-and-reject/248108/2 "2020-10-08T05:32:18Z")

</div>

Closed on October 8, 2020, 5:32am UTC

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