# Register and call query in ElasticSearch

**URL:** <https://discuss.elastic.co/t/register-and-call-query-in-elasticsearch/9457>\
**Category:** Elasticsearch\
**Created:** [October 24, 2012, 1:20pm UTC](https://discuss.elastic.co/t/register-and-call-query-in-elasticsearch/9457 "2012-10-24T13:20:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaynier](https://avatars.discourse-cdn.com/v4/letter/j/3da27b/32.png) [@jmaynier](https://discuss.elastic.co/u/jmaynier)\
**Post date:** [October 24, 2012, 1:20pm UTC](https://discuss.elastic.co/t/register-and-call-query-in-elasticsearch/9457/1 "2012-10-24T13:20:58Z")

</div>

Is it possible to register query (like the percolate process) and call them  
by name to execute them.  
I am building an application that will let the user save search query  
associated with a label. I would like to save the query generated by the  
filter in ES.

If I save the query in an index, I have to call ES first to retrieve the  
query, extract the field containing the query and then call ES again to  
execute it. Can I do it in one call ?

The other solution is to register queries (labels with \_percolator with an  
identifier of the user:  
/\_percolate/transaction/user1\_label1

{  
"userId": "user1",  
"query":{  
"term":{"field1":"foo" }  
}  
}

and when there is a new document use the percolator in a non indexing mode  
(filtered per userId) to retrieve which query match, and then update the  
document by adding a field "label":["user1\_label1", "user1\_label2"] and  
finaly index the document. SO the labelling is done at indexing time.

What do you think ?  
Thanks in advance.

--

---

<div class="post-metadata">

**Author:** ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)\
**Post date:** [October 24, 2012, 7:01pm UTC](https://discuss.elastic.co/t/register-and-call-query-in-elasticsearch/9457/2 "2012-10-24T19:01:47Z")

</div>

Hello Jecom,

If you don't need scoring, you can used filtered aliases:

> **[Elastic — The Search AI Company](https://www.elastic.co)**
>
> Power insights and outcomes with The Elastic Search AI Platform. See into your data and find answers that matter with enterprise solutions designed to help you accelerate time to insight. Try Elastic ...

But I think the logic would always be pretty similar: queries should  
be retrieved from somewhere, then ran.

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Wed, Oct 24, 2012 at 4:20 PM, Jecom [jmaynier@eco2market.com](mailto:jmaynier@eco2market.com) wrote:

> Is it possible to register query (like the percolate process) and call them  
> by name to execute them.  
> I am building an application that will let the user save search query  
> associated with a label. I would like to save the query generated by the  
> filter in ES.
> 
> If I save the query in an index, I have to call ES first to retrieve the  
> query, extract the field containing the query and then call ES again to  
> execute it. Can I do it in one call ?
> 
> The other solution is to register queries (labels with \_percolator with an  
> identifier of the user:  
> /\_percolate/transaction/user1\_label1
> 
> {  
> "userId": "user1",  
> "query":{  
> "term":{"field1":"foo" }  
> }  
> }
> 
> and when there is a new document use the percolator in a non indexing mode  
> (filtered per userId) to retrieve which query match, and then update the  
> document by adding a field "label":["user1\_label1", "user1\_label2"] and  
> finaly index the document. SO the labelling is done at indexing time.
> 
> What do you think ?  
> Thanks in advance.
> 
> --

--

---

<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:07am UTC](https://discuss.elastic.co/t/register-and-call-query-in-elasticsearch/9457/3 "2017-07-06T03:07:22Z")

</div>


