# How to execute Lucene query inside Elasticsearch

**URL:** https://discuss.elastic.co/t/how-to-execute-lucene-query-inside-elasticsearch/200626
**Category:** Elasticsearch
**Created:** [September 23, 2019, 5:49am UTC](https://discuss.elastic.co/t/how-to-execute-lucene-query-inside-elasticsearch/200626 "2019-09-23T05:49:09Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![saimaz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/saimaz/32/54699_2.png) [@saimaz](https://discuss.elastic.co/u/saimaz)
#### Post date: [September 23, 2019, 5:49am UTC](https://discuss.elastic.co/t/how-to-execute-lucene-query-inside-elasticsearch/200626/1 "2019-09-23T05:49:09Z")

</div>

Hey there,

I'm writing an Elasticsearch plugin. Can someone direct me to the right place how to execute a Lucene query in the Query Builder or Rescoring part from a plugin?

The reason for a Lucene is because I want to apply ML data model in the shard for the number of documents filtered by a query. I know there are existing plugins for that but none of them really works in my business case.

Is there any way to access Lucene from custom query builder (from a plugin):

```
public class MyCustomQueryPlugin extends Plugin implements SearchPlugin {	
   @Override
   public List<QuerySpec<?>> getQueries() {

       return singletonList(
               new QuerySpec<>(MyCustomQueryBuilder.NAME, MyCustomQueryBuilder::new, MyCustomQueryBuilder::fromXContent)
       );
   }
}
```

---

<div class="post-metadata">

### Author: ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)
#### Post date: [October 4, 2019, 3:36am UTC](https://discuss.elastic.co/t/how-to-execute-lucene-query-inside-elasticsearch/200626/2 "2019-10-04T03:36:48Z")

</div>

Registering your own query builder means you will have a custom query type you can run, where the Query produced by the query builder is a Lucene construct. Anything should be possible from there. Can you further describe what you are trying to accomplish?

---

<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: [November 1, 2019, 3:37am UTC](https://discuss.elastic.co/t/how-to-execute-lucene-query-inside-elasticsearch/200626/3 "2019-11-01T03:37:00Z")

</div>

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