# Hooking into search request execution

**URL:** <https://discuss.elastic.co/t/hooking-into-search-request-execution/6381>\
**Category:** Elasticsearch\
**Created:** [January 14, 2012, 8:34am UTC](https://discuss.elastic.co/t/hooking-into-search-request-execution/6381 "2012-01-14T08:34:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![otisg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/otisg/32/492_2.png) [@otisg](https://discuss.elastic.co/u/otisg)\
**Post date:** [January 14, 2012, 8:34am UTC](https://discuss.elastic.co/t/hooking-into-search-request-execution/6381/1 "2012-01-14T08:34:17Z")

</div>

Hi,

In a different thread Shay wrote:

> Elasticsearch execution is a bit different. Because all is segment based and collector based,  
> there are not different "stages" of search, all is done while the query executes.

So is there no way for one to "hook into" the search request  
execution?  
For example, right now we are working on a project with Solr and  
building a SearchComponent that takes the query, analyzes it in a  
certain way, takes some data out of it, executes some Java code to  
transform the extracted data into something else and essentially  
rewrites the query a bit. Implementation details are irrelevant - the  
key is that I can write some custom Java code that extends Solr's  
SearchComponent, declare this new component of mine in solrconfig.xml  
and include it in the request flow. In this case, I'd put it before  
the component that does the actually querying, but we've also built  
components that came after the query component in this component  
chain.

This was discussed in

> **[Google Groups](https://groups.google.com/access-error?continue=https:%2F%2Fgroups.google.com%2Fg%2Felasticsearch%2Fc%2F0NvV6nlfqKQ)**

...but there was no clear answer... and I'd love to know if Shay has  
any plans around this for ES. I, obviously, find hitting this  
repeatedly and I'm probably not alone.

## Thanks, Otis

Sematext is hiring world-wide-- [Jobs](http://sematext.com/about/jobs.html)

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [January 14, 2012, 4:01pm UTC](https://discuss.elastic.co/t/hooking-into-search-request-execution/6381/2 "2012-01-14T16:01:00Z")

</div>

First, this has nothing to do with my comment on the other thread.

For your use case, you can plug your own query parser into elasticsearch so  
it will be part of the query DSL, and then do whatever you want there.  
which at the end generates a Query. There are other specific points where  
you want to plug your own custom specific logic. Another option is to  
actually expose your own endpoint and slice and dice the search request  
however you want (the solr protocol plugin that was written by the  
community on github is a good example).

But, as a design decision, I personally don't believe that such logic  
belong in elasticsearch (on a project level, not a generic plugin). You are  
abusing it to try and put code there where it actually belongs in your app  
layer. Its much simpler to manage code as part of your app layer than  
having to manage code that is running in elasticsearch. Obviously, every  
use case has its exception, but be weary that now you introduced another  
dependency which is not elasticsearch API, but elasticsearch codebase,  
instead of doing it yourself.

-shay.banon

On Sat, Jan 14, 2012 at 10:34 AM, Otis Gospodnetic \<  
[otis.gospodnetic@gmail.com](mailto:otis.gospodnetic@gmail.com)\> wrote:

> Hi,
> 
> In a different thread Shay wrote:
> 
> > Elasticsearch execution is a bit different. Because all is segment based  
> > and collector based,  
> > there are not different "stages" of search, all is done while the query  
> > executes.
> 
> So is there no way for one to "hook into" the search request  
> execution?  
> For example, right now we are working on a project with Solr and  
> building a SearchComponent that takes the query, analyzes it in a  
> certain way, takes some data out of it, executes some Java code to  
> transform the extracted data into something else and essentially  
> rewrites the query a bit. Implementation details are irrelevant - the  
> key is that I can write some custom Java code that extends Solr's  
> SearchComponent, declare this new component of mine in solrconfig.xml  
> and include it in the request flow. In this case, I'd put it before  
> the component that does the actually querying, but we've also built  
> components that came after the query component in this component  
> chain.
> 
> This was discussed in
> 
> [http://groups.google.com/group/elasticsearch/browse\_thread/thread/d0dbd5ea795fa8a4/5dfa56829a94ff60](http://groups.google.com/group/elasticsearch/browse_thread/thread/d0dbd5ea795fa8a4/5dfa56829a94ff60)
> 
> ...but there was no clear answer... and I'd love to know if Shay has  
> any plans around this for ES. I, obviously, find hitting this  
> repeatedly and I'm probably not alone.
> 
> ## Thanks, Otis
> 
> Sematext is hiring world-wide-- [Jobs - Sematext](http://sematext.com/about/jobs.html)

---

<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 6, 2017, 3:42am UTC](https://discuss.elastic.co/t/hooking-into-search-request-execution/6381/3 "2017-07-06T03:42:45Z")

</div>


