# Lucene queries

**URL:** <https://discuss.elastic.co/t/lucene-queries/10726>\
**Category:** Elasticsearch\
**Created:** [February 13, 2013, 2:23pm UTC](https://discuss.elastic.co/t/lucene-queries/10726 "2013-02-13T14:23:29Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![elastray](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@elastray](https://discuss.elastic.co/u/elastray)\
**Post date:** [February 13, 2013, 2:23pm UTC](https://discuss.elastic.co/t/lucene-queries/10726/1 "2013-02-13T14:23:29Z")

</div>

Hi,

I have been reading the documentation and doing a lot of tests but I can not get an answer to this.

I need to integrate an application that uses Lucene as search engine with Elastic Search. I already can write in my Elastic Search cluster, but the searches are much more difficult. I have a lot of complex Lucene queries that I am trying to pass to Elastic Search but they didn't work.

Is it possible to pass directly a Lucene query to Elastic Search? If yes, how? If not, what should I do in order to get that?

Thanks!!!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 13, 2013, 2:30pm UTC](https://discuss.elastic.co/t/lucene-queries/10726/2 "2013-02-13T14:30:42Z")

</div>

I assume that you are using Java.  
Did you look at this?

> **[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 ...

and this?

> **[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 ...

## Does it help?

David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 13 févr. 2013 à 15:23, elastray [adelpozo@xtivia.com](mailto:adelpozo@xtivia.com) a écrit :

> Hi,
> 
> I have been reading the documentation and doing a lot of tests but I can not  
> get an answer to this.
> 
> I need to integrate an application that uses Lucene as search engine with  
> Elastic Search. I already can write in my Elastic Search cluster, but the  
> searches are much more difficult. I have a lot of complex Lucene queries  
> that I am trying to pass to Elastic Search but they didn't work.
> 
> Is it possible to pass directly a Lucene query to Elastic Search? If yes,  
> how? If not, what should I do in order to get that?
> 
> Thanks!!!
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Lucene-queries-tp4029770.html](http://elasticsearch-users.115913.n3.nabble.com/Lucene-queries-tp4029770.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Jerome\_Gagnon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jerome_gagnon/32/2178_2.png) [@Jerome\_Gagnon](https://discuss.elastic.co/u/Jerome_Gagnon)\
**Post date:** [February 13, 2013, 2:37pm UTC](https://discuss.elastic.co/t/lucene-queries/10726/3 "2013-02-13T14:37:31Z")

</div>

You can a use query\_string query.

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Wednesday, February 13, 2013 9:23:29 AM UTC-5, elastray wrote:

> Hi,
> 
> I have been reading the documentation and doing a lot of tests but I can  
> not  
> get an answer to this.
> 
> I need to integrate an application that uses Lucene as search engine with  
> Elastic Search. I already can write in my Elastic Search cluster, but the  
> searches are much more difficult. I have a lot of complex Lucene queries  
> that I am trying to pass to Elastic Search but they didn't work.
> 
> Is it possible to pass directly a Lucene query to Elastic Search? If yes,  
> how? If not, what should I do in order to get that?
> 
> Thanks!!!
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Lucene-queries-tp4029770.html](http://elasticsearch-users.115913.n3.nabble.com/Lucene-queries-tp4029770.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![elastray](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@elastray](https://discuss.elastic.co/u/elastray)\
**Post date:** [February 13, 2013, 2:39pm UTC](https://discuss.elastic.co/t/lucene-queries/10726/4 "2013-02-13T14:39:06Z")

</div>

Hi dadoonet,

and thanks for your response!

You assume well, I am using java. And Jest to talk to Elastic Search cluster.

I am testing that right now, but I am not sure that it is what I am looking for. For what I understand, I think that I have to understand the queries, translate them into Elastic Search nomenclature and then use Jest or the Java API to execute them, isn't it? Is there any other way to do that?

Regards!

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [February 13, 2013, 2:44pm UTC](https://discuss.elastic.co/t/lucene-queries/10726/5 "2013-02-13T14:44:24Z")

</div>

I see. I don't know the JEST API.  
The links I gave are related to Elasticsearch Java client (using transport network layer, 9300-9399 ports and not REST API, 9200-9299 ports).

Whatever the Java client you use, you have to find the right query for your use case.

Have a look at [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/query-dsl/) to find the API that suits you the more.

HTH

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr | @scrutmydocs

Le 13 févr. 2013 à 15:39, elastray [adelpozo@xtivia.com](mailto:adelpozo@xtivia.com) a écrit :

> Hi dadoonet,
> 
> and thanks for your response!
> 
> You assume well, I am using java. And Jest to talk to Elastic Search  
> cluster.
> 
> I am testing that right now, but I am not sure that it is what I am looking  
> for. For what I understand, I think that I have to understand the queries,  
> translate them into Elastic Search nomenclature and then use Jest or the  
> Java API to execute them, isn't it? Is there any other way to do that?
> 
> Regards!
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Lucene-queries-tp4029770p4029773.html](http://elasticsearch-users.115913.n3.nabble.com/Lucene-queries-tp4029770p4029773.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --  
> You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![elastray](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@elastray](https://discuss.elastic.co/u/elastray)\
**Post date:** [February 13, 2013, 2:54pm UTC](https://discuss.elastic.co/t/lucene-queries/10726/6 "2013-02-13T14:54:47Z")

</div>

Thanks Jerome, I already have been reading that, but I don't know how to use it. Right now I am trying to use a Lucene's BooleanQuery and it is being impossible, so I suppose that I would have to read every query and transform it, isn't it?

Regards!

---

<div class="post-metadata">

**Author:** ![Jerome\_Gagnon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jerome_gagnon/32/2178_2.png) [@Jerome\_Gagnon](https://discuss.elastic.co/u/Jerome_Gagnon)\
**Post date:** [February 13, 2013, 3:15pm UTC](https://discuss.elastic.co/t/lucene-queries/10726/7 "2013-02-13T15:15:28Z")

</div>

If you are using a boolean query that already has some clauses in it, you  
could just add a must clause to your query with the querystringquery inside  
containing tjhe lucene query.

Or if you already have a lucene query built, you could simply replace your  
booleanquery with the querystringquery containing the lucene query itself.

On Wednesday, February 13, 2013 9:54:47 AM UTC-5, elastray wrote:

> Thanks Jerome, I already have been reading that, but I don't know how to  
> use  
> it. Right now I am trying to use a Lucene's BooleanQuery and it is being  
> impossible, so I suppose that I would have to read every query and  
> transform  
> it, isn't it?
> 
> Regards!
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Lucene-queries-tp4029770p4029775.html](http://elasticsearch-users.115913.n3.nabble.com/Lucene-queries-tp4029770p4029775.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![elastray](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@elastray](https://discuss.elastic.co/u/elastray)\
**Post date:** [February 13, 2013, 3:23pm UTC](https://discuss.elastic.co/t/lucene-queries/10726/8 "2013-02-13T15:23:05Z")

</div>

Or if you already have a lucene query built, you could simply replace your booleanquery with the querystringquery containing the lucene query itself.

That would be great!! I will try it, but do you have a small example?

Thanks!!!

---

<div class="post-metadata">

**Author:** ![elastray](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@elastray](https://discuss.elastic.co/u/elastray)\
**Post date:** [February 13, 2013, 3:44pm UTC](https://discuss.elastic.co/t/lucene-queries/10726/9 "2013-02-13T15:44:24Z")

</div>

Perhaps I didn't explain myself... I do not have something like "fist AND second", I do have something like this after searching for "test" in the App:

+( +(company:14) +( (+(name:book)) (+(+(name:post) +(user:16 (role:10 groupRole:10-190)))) (+(+(name:file) +(user:16 (role:10 groupRole:10-190))) +(status:0)) ) ) +(content:test description:test properties:test)

Of course, if I send that to Elastic Search it doesn't works, and I do not see how to translate that... I am not really sure about that but looking into the app code it seems that is the Lucene query... does it makes sense?

Thanks!!

---

<div class="post-metadata">

**Author:** ![elastray](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@elastray](https://discuss.elastic.co/u/elastray)\
**Post date:** [February 13, 2013, 4:31pm UTC](https://discuss.elastic.co/t/lucene-queries/10726/10 "2013-02-13T16:31:39Z")

</div>

Anyone knows why that is working with Solr and not with Elastic Search?

Thanks!!!

---

<div class="post-metadata">

**Author:** ![Jerome\_Gagnon](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jerome_gagnon/32/2178_2.png) [@Jerome\_Gagnon](https://discuss.elastic.co/u/Jerome_Gagnon)\
**Post date:** [February 13, 2013, 4:59pm UTC](https://discuss.elastic.co/t/lucene-queries/10726/11 "2013-02-13T16:59:16Z")

</div>

I think this should work if you wrap this around a QueryStringQuery as your  
query, no ? You could try putting it to the q parameter while calling the  
rest API

On Wednesday, February 13, 2013 11:31:39 AM UTC-5, elastray wrote:

> Anyone knows why that is working with Solr and not with Elastic Search?
> 
> Thanks!!!
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/Lucene-queries-tp4029770p4029784.html](http://elasticsearch-users.115913.n3.nabble.com/Lucene-queries-tp4029770p4029784.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![elastray](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@elastray](https://discuss.elastic.co/u/elastray)\
**Post date:** [February 13, 2013, 5:20pm UTC](https://discuss.elastic.co/t/lucene-queries/10726/12 "2013-02-13T17:20:27Z")

</div>

Thanks Jerome!!!

I tried this (using Jest, you know...):

Search search = new Search(Search.createQueryWithBuilder(QueryBuilders.queryString(translatedQuery.toString()).toString()));

where translatedQuery is my original query, and I am not sure if it works but I get something different this time :). And different is good when you are stuck :D.

I will investigate this and let you know if it works!! (first I have to get the facets, and that it is another quest...)

Regards!!

---

<div class="post-metadata">

**Author:** ![elastray](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@elastray](https://discuss.elastic.co/u/elastray)\
**Post date:** [February 15, 2013, 7:50pm UTC](https://discuss.elastic.co/t/lucene-queries/10726/13 "2013-02-15T19:50:43Z")

</div>

Jerome, it worked!!

David, Jerome, just let me know where to send the beers.

Regards!!

---

<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, 2:51am UTC](https://discuss.elastic.co/t/lucene-queries/10726/14 "2017-07-06T02:51:17Z")

</div>


