# ElasticSearch lucene queries VERSUS ElasticSearch query string

**URL:** https://discuss.elastic.co/t/elasticsearch-lucene-queries-versus-elasticsearch-query-string/10453
**Category:** Elasticsearch
**Created:** [January 22, 2013, 4:13pm UTC](https://discuss.elastic.co/t/elasticsearch-lucene-queries-versus-elasticsearch-query-string/10453 "2013-01-22T16:13:11Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)
#### Post date: [January 22, 2013, 4:13pm UTC](https://discuss.elastic.co/t/elasticsearch-lucene-queries-versus-elasticsearch-query-string/10453/1 "2013-01-22T16:13:11Z")

</div>

Hi,

I tried running Elastic search queries, in the Lucene-query format and also  
in the query string format.  
I found that the lucene queries were considerably faster than the  
query-string queries, approx. 4 times faster. Can some one pls throw light  
on why is it so

Thanks,  
John

--

---

<div class="post-metadata">

### Author: ![mattweber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattweber/32/44940_2.png) [@mattweber](https://discuss.elastic.co/u/mattweber)
#### Post date: [January 22, 2013, 4:16pm UTC](https://discuss.elastic.co/t/elasticsearch-lucene-queries-versus-elasticsearch-query-string/10453/2 "2013-01-22T16:16:29Z")

</div>

What do you mean by "lucene-query" format? The Elasticsearch Query String  
Query accepts lucene query syntax, ie. "this AND that OR whatever". Were  
you talking about using that format vs. crafting the underlying query  
objects

BOOLEAN

On Tue, Jan 22, 2013 at 8:13 AM, john [john2roll2@gmail.com](mailto:john2roll2@gmail.com) wrote:

> Hi,
> 
> I tried running Elastic search queries, in the Lucene-query format and  
> also in the query string format.  
> I found that the lucene queries were considerably faster than the  
> query-string queries, approx. 4 times faster. Can some one pls throw light  
> on why is it so
> 
> Thanks,  
> John
> 
> --

--

---

<div class="post-metadata">

### Author: ![mattweber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattweber/32/44940_2.png) [@mattweber](https://discuss.elastic.co/u/mattweber)
#### Post date: [January 22, 2013, 4:17pm UTC](https://discuss.elastic.co/t/elasticsearch-lucene-queries-versus-elasticsearch-query-string/10453/3 "2013-01-22T16:17:54Z")

</div>

Didn't get to finish that:

BOOLEAN  
MUST this  
MUST that  
SHOULD whatever

?

On Tue, Jan 22, 2013 at 8:16 AM, Matt Weber [matt.weber@gmail.com](mailto:matt.weber@gmail.com) wrote:

> What do you mean by "lucene-query" format? The Elasticsearch Query String  
> Query accepts lucene query syntax, ie. "this AND that OR whatever". Were  
> you talking about using that format vs. crafting the underlying query  
> objects
> 
> BOOLEAN
> 
> On Tue, Jan 22, 2013 at 8:13 AM, john [john2roll2@gmail.com](mailto:john2roll2@gmail.com) wrote:
> 
> > Hi,
> > 
> > I tried running Elastic search queries, in the Lucene-query format and  
> > also in the query string format.  
> > I found that the lucene queries were considerably faster than the  
> > query-string queries, approx. 4 times faster. Can some one pls throw light  
> > on why is it so
> > 
> > Thanks,  
> > John
> > 
> > --

--

---

<div class="post-metadata">

### Author: ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)
#### Post date: [January 22, 2013, 6:13pm UTC](https://discuss.elastic.co/t/elasticsearch-lucene-queries-versus-elasticsearch-query-string/10453/4 "2013-01-22T18:13:44Z")

</div>

By lucene query format i mean using the java API for Elasticsearch. The  
API allows to build query as a combination of queries and filters, the way  
you mentioned below.  
Before that i was query strings.

On Tuesday, January 22, 2013 10:17:54 AM UTC-6, Matt Weber wrote:

> Didn't get to finish that:
> 
> BOOLEAN  
> MUST this  
> MUST that  
> SHOULD whatever
> 
> ?
> 
> On Tue, Jan 22, 2013 at 8:16 AM, Matt Weber \<[matt....@gmail.com](mailto:matt....@gmail.com)\<javascript:\>
> 
> > wrote:
> 
> > What do you mean by "lucene-query" format? The Elasticsearch Query  
> > String Query accepts lucene query syntax, ie. "this AND that OR whatever".  
> > Were you talking about using that format vs. crafting the underlying query  
> > objects
> > 
> > BOOLEAN
> > 
> > On Tue, Jan 22, 2013 at 8:13 AM, john \<[john2...@gmail.com](mailto:john2...@gmail.com) \<javascript:\>\>wrote:
> > 
> > > Hi,
> > > 
> > > I tried running Elastic search queries, in the Lucene-query format and  
> > > also in the query string format.  
> > > I found that the lucene queries were considerably faster than the  
> > > query-string queries, approx. 4 times faster. Can some one pls throw light  
> > > on why is it so
> > > 
> > > Thanks,  
> > > John
> > > 
> > > --

--

---

<div class="post-metadata">

### Author: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [January 22, 2013, 6:23pm UTC](https://discuss.elastic.co/t/elasticsearch-lucene-queries-versus-elasticsearch-query-string/10453/5 "2013-01-22T18:23:24Z")

</div>

On Tue, 2013-01-22 at 10:13 -0800, john wrote:

> By lucene query format i mean using the java API for Elasticsearch.  
> The API allows to build query as a combination of queries and filters,  
> the way you mentioned below.  
> Before that i was query strings.

It'd be a lot easier to figure out what you were comparing if you  
provided the code

clint

> On Tuesday, January 22, 2013 10:17:54 AM UTC-6, Matt Weber wrote:  
> Didn't get to finish that:
> 
> ```
> BOOLEAN
> MUST this
> MUST that
> SHOULD whatever
>     
>     
> ?
>     
>     
> On Tue, Jan 22, 2013 at 8:16 AM, Matt Weber
> <matt....@gmail.com> wrote:
> What do you mean by "lucene-query" format? The
> ElasticSearch Query String Query accepts lucene query
> syntax, ie. "this AND that OR whatever". Were you
> talking about using that format vs. crafting the
> underlying query objects 
>             
>             
> BOOLEAN
>             
>             
>             
>             
> On Tue, Jan 22, 2013 at 8:13 AM, john
> <john2...@gmail.com> wrote:
> Hi,
>                     
>                     
> I tried running Elastic search queries, in the
> Lucene-query format and also in the query
> string format.
> I found that the lucene queries were
> considerably faster than the query-string
> queries, approx. 4 times faster. Can some one
> pls throw light on why is it so
>                     
>                     
> Thanks,
> John
> 
> ```

--

---

<div class="post-metadata">

### Author: ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)
#### Post date: [January 30, 2013, 9:42pm UTC](https://discuss.elastic.co/t/elasticsearch-lucene-queries-versus-elasticsearch-query-string/10453/6 "2013-01-30T21:42:15Z")

</div>

Clint, Sorry for replying so late. Had gone on a vacation.

This is what i mean by Elasticsearch query string:

{"fields":["X.price","X.name","X.marketValue","X.salePrice"],"from":0,"size":10,"sort":[{"X.price.alphanum":"asc"}],"filter":{"query":{"query\_string":{"default\_operator":"AND","query":"X.Y:false  
AND X.marketplace:false AND X.active:true AND X.Z:false AND  
X.startDate:[1910-01-01 TO 2013-01-29] AND X.end:true AND (((X.name:floor\*  
OR X.manufacturer:floor\* OR X.desc:floor\* OR X.desc:floor\* OR  
X.futures.feature:floor\* OR X.details.value:floor\*)))"}}}}

And this is what i mean by Lucene queries. And the queries created oin the  
manner below are a lot faster than i i were to create a query string for  
the same conditions.  
{  
"from": 0,  
"size": 10,  
"query": {  
"bool": {  
"must": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"term": {  
"X.id": "\*"  
}  
}  
}  
}  
}  
},  
"fields": [  
"X.id",  
],  
"sort": [  
{  
"X.id": {  
"order": "asc"  
}  
}  
]  
}

John

On Tuesday, 22 January 2013 12:23:24 UTC-6, Clinton Gormley wrote:

> On Tue, 2013-01-22 at 10:13 -0800, john wrote:
> 
> > By lucene query format i mean using the java API for Elasticsearch.  
> > The API allows to build query as a combination of queries and filters,  
> > the way you mentioned below.  
> > Before that i was query strings.
> 
> It'd be a lot easier to figure out what you were comparing if you  
> provided the code
> 
> clint
> 
> > On Tuesday, January 22, 2013 10:17:54 AM UTC-6, Matt Weber wrote:  
> > Didn't get to finish that:
> > 
> > ```
> > BOOLEAN 
> > MUST this 
> > MUST that 
> > SHOULD whatever 
> >     
> >     
> > ? 
> >     
> >     
> > On Tue, Jan 22, 2013 at 8:16 AM, Matt Weber 
> > <matt....@gmail.com> wrote: 
> > What do you mean by "lucene-query" format? The 
> > ElasticSearch Query String Query accepts lucene query 
> > syntax, ie. "this AND that OR whatever". Were you 
> > talking about using that format vs. crafting the 
> > underlying query objects 
> >             
> >             
> > BOOLEAN 
> >             
> >             
> >             
> >             
> > On Tue, Jan 22, 2013 at 8:13 AM, john 
> > <john2...@gmail.com> wrote: 
> > Hi, 
> >                     
> >                     
> > I tried running Elastic search queries, in the 
> > Lucene-query format and also in the query 
> > string format. 
> > I found that the lucene queries were 
> > considerably faster than the query-string 
> > queries, approx. 4 times faster. Can some one 
> > pls throw light on why is it so 
> >                     
> >                     
> > Thanks, 
> > John 
> > 
> > ```

--  
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: ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)
#### Post date: [January 30, 2013, 10:11pm UTC](https://discuss.elastic.co/t/elasticsearch-lucene-queries-versus-elasticsearch-query-string/10453/7 "2013-01-30T22:11:14Z")

</div>

Ignoring the differences in the query itself (e.g. they query different  
things), I believe the performance difference is more related to your  
filter choice. In the top query, you are using a "Query Filter", which  
just wraps a query with a filter so you can cache the returned results.  
This can be useful if you hit the same query over and over, where it makes  
sense to just save the output instead of processing the request. However,  
you don't gain any filter search-time performance. You are effectively  
running a really big query string against all the docs.

The lower query uses a "Filtered Query", which first takes your corpus of  
documents and discards those that don't match the filter. Whatever  
leftover is then searched with your query. This is very fast because the  
filters are cached in memory, so you quickly reduce the size of documents  
that need to be analyzed with your query.

Perhaps I'm misunderstanding your question. Curious to see what Clint says.

-Zach

On Wednesday, January 30, 2013 4:42:15 PM UTC-5, john wrote:

> Clint, Sorry for replying so late. Had gone on a vacation.
> 
> This is what i mean by Elasticsearch query string:
> 
> {"fields":["X.price","X.name","X.marketValue","X.salePrice"],"from":0,"size":10,"sort":[{"X.price.alphanum":"asc"}],"filter":{"query":{"query\_string":{"default\_operator":"AND","query":"X.Y:false  
> AND X.marketplace:false AND X.active:true AND X.Z:false AND  
> X.startDate:[1910-01-01 TO 2013-01-29] AND X.end:true AND (((X.name:floor\*  
> OR X.manufacturer:floor\* OR X.desc:floor\* OR X.desc:floor\* OR  
> X.futures.feature:floor\* OR X.details.value:floor\*)))"}}}}
> 
> And this is what i mean by Lucene queries. And the queries created oin the  
> manner below are a lot faster than i i were to create a query string for  
> the same conditions.  
> {  
> "from": 0,  
> "size": 10,  
> "query": {  
> "bool": {  
> "must": {  
> "filtered": {  
> "query": {  
> "match\_all": {}  
> },  
> "filter": {  
> "term": {  
> "X.id": "\*"  
> }  
> }  
> }  
> }  
> }  
> },  
> "fields": [  
> "X.id",  
> ],  
> "sort": [  
> {  
> "X.id": {  
> "order": "asc"  
> }  
> }  
> ]  
> }
> 
> John
> 
> On Tuesday, 22 January 2013 12:23:24 UTC-6, Clinton Gormley wrote:
> 
> > On Tue, 2013-01-22 at 10:13 -0800, john wrote:
> > 
> > > By lucene query format i mean using the java API for Elasticsearch.  
> > > The API allows to build query as a combination of queries and filters,  
> > > the way you mentioned below.  
> > > Before that i was query strings.
> > 
> > It'd be a lot easier to figure out what you were comparing if you  
> > provided the code
> > 
> > clint
> > 
> > > On Tuesday, January 22, 2013 10:17:54 AM UTC-6, Matt Weber wrote:  
> > > Didn't get to finish that:
> > > 
> > > ```
> > > BOOLEAN 
> > > MUST this 
> > > MUST that 
> > > SHOULD whatever 
> > >     
> > >     
> > > ? 
> > >     
> > >     
> > > On Tue, Jan 22, 2013 at 8:16 AM, Matt Weber 
> > > <matt....@gmail.com> wrote: 
> > > What do you mean by "lucene-query" format? The 
> > > ElasticSearch Query String Query accepts lucene query 
> > > syntax, ie. "this AND that OR whatever". Were you 
> > > talking about using that format vs. crafting the 
> > > underlying query objects 
> > >             
> > >             
> > > BOOLEAN 
> > >             
> > >             
> > >             
> > >             
> > > On Tue, Jan 22, 2013 at 8:13 AM, john 
> > > <john2...@gmail.com> wrote: 
> > > Hi, 
> > >                     
> > >                     
> > > I tried running Elastic search queries, in the 
> > > Lucene-query format and also in the query 
> > > string format. 
> > > I found that the lucene queries were 
> > > considerably faster than the query-string 
> > > queries, approx. 4 times faster. Can some one 
> > > pls throw light on why is it so 
> > >                     
> > >                     
> > > Thanks, 
> > > John 
> > > 
> > > ```

--  
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: ![john\_2](https://avatars.discourse-cdn.com/v4/letter/j/dc4da7/32.png) [@john\_2](https://discuss.elastic.co/u/john_2)
#### Post date: [January 30, 2013, 10:27pm UTC](https://discuss.elastic.co/t/elasticsearch-lucene-queries-versus-elasticsearch-query-string/10453/8 "2013-01-30T22:27:40Z")

</div>

You're right the lower queries are hell lot faster. approx 4 times faster  
than the top query. I just wanted to know what makes them different and why  
the lower ones are aster.  
The top queries have to be created manually and the lower ones using the  
Java API for Elasticsearch.

On Wednesday, 30 January 2013 16:11:14 UTC-6, Zachary Tong wrote:

> Ignoring the differences in the query itself (e.g. they query different  
> things), I believe the performance difference is more related to your  
> filter choice. In the top query, you are using a "Query Filter", which  
> just wraps a query with a filter so you can cache the returned results.  
> This can be useful if you hit the same query over and over, where it makes  
> sense to just save the output instead of processing the request. However,  
> you don't gain any filter search-time performance. You are effectively  
> running a really big query string against all the docs.
> 
> The lower query uses a "Filtered Query", which first takes your corpus of  
> documents and discards those that don't match the filter. Whatever  
> leftover is then searched with your query. This is very fast because the  
> filters are cached in memory, so you quickly reduce the size of documents  
> that need to be analyzed with your query.
> 
> Perhaps I'm misunderstanding your question. Curious to see what Clint  
> says.
> 
> -Zach
> 
> On Wednesday, January 30, 2013 4:42:15 PM UTC-5, john wrote:
> 
> > Clint, Sorry for replying so late. Had gone on a vacation.
> > 
> > This is what i mean by Elasticsearch query string:
> > 
> > {"fields":["X.price","X.name","X.marketValue","X.salePrice"],"from":0,"size":10,"sort":[{"X.price.alphanum":"asc"}],"filter":{"query":{"query\_string":{"default\_operator":"AND","query":"X.Y:false  
> > AND X.marketplace:false AND X.active:true AND X.Z:false AND  
> > X.startDate:[1910-01-01 TO 2013-01-29] AND X.end:true AND (((X.name:floor\*  
> > OR X.manufacturer:floor\* OR X.desc:floor\* OR X.desc:floor\* OR  
> > X.futures.feature:floor\* OR X.details.value:floor\*)))"}}}}
> > 
> > And this is what i mean by Lucene queries. And the queries created oin  
> > the manner below are a lot faster than i i were to create a query string  
> > for the same conditions.  
> > {  
> > "from": 0,  
> > "size": 10,  
> > "query": {  
> > "bool": {  
> > "must": {  
> > "filtered": {  
> > "query": {  
> > "match\_all": {}  
> > },  
> > "filter": {  
> > "term": {  
> > "X.id": "\*"  
> > }  
> > }  
> > }  
> > }  
> > }  
> > },  
> > "fields": [  
> > "X.id",  
> > ],  
> > "sort": [  
> > {  
> > "X.id": {  
> > "order": "asc"  
> > }  
> > }  
> > ]  
> > }
> > 
> > John
> > 
> > On Tuesday, 22 January 2013 12:23:24 UTC-6, Clinton Gormley wrote:
> > 
> > > On Tue, 2013-01-22 at 10:13 -0800, john wrote:
> > > 
> > > > By lucene query format i mean using the java API for Elasticsearch.  
> > > > The API allows to build query as a combination of queries and filters,  
> > > > the way you mentioned below.  
> > > > Before that i was query strings.
> > > 
> > > It'd be a lot easier to figure out what you were comparing if you  
> > > provided the code
> > > 
> > > clint
> > > 
> > > > On Tuesday, January 22, 2013 10:17:54 AM UTC-6, Matt Weber wrote:  
> > > > Didn't get to finish that:
> > > > 
> > > > ```
> > > > BOOLEAN 
> > > > MUST this 
> > > > MUST that 
> > > > SHOULD whatever 
> > > >     
> > > >     
> > > > ? 
> > > >     
> > > >     
> > > > On Tue, Jan 22, 2013 at 8:16 AM, Matt Weber 
> > > > <matt....@gmail.com> wrote: 
> > > > What do you mean by "lucene-query" format? The 
> > > > ElasticSearch Query String Query accepts lucene query 
> > > > syntax, ie. "this AND that OR whatever". Were you 
> > > > talking about using that format vs. crafting the 
> > > > underlying query objects 
> > > >             
> > > >             
> > > > BOOLEAN 
> > > >             
> > > >             
> > > >             
> > > >             
> > > > On Tue, Jan 22, 2013 at 8:13 AM, john 
> > > > <john2...@gmail.com> wrote: 
> > > > Hi, 
> > > >                     
> > > >                     
> > > > I tried running Elastic search queries, in the 
> > > > Lucene-query format and also in the query 
> > > > string format. 
> > > > I found that the lucene queries were 
> > > > considerably faster than the query-string 
> > > > queries, approx. 4 times faster. Can some one 
> > > > pls throw light on why is it so 
> > > >                     
> > > >                     
> > > > Thanks, 
> > > > John 
> > > > 
> > > > ```

--  
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: ![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: [January 31, 2013, 3:23am UTC](https://discuss.elastic.co/t/elasticsearch-lucene-queries-versus-elasticsearch-query-string/10453/9 "2013-01-31T03:23:12Z")

</div>

QueryString is a Query. It's analyzed for each field involve. And score is computed.  
TermFilter is a Filter. It's not analyzed. No scoring phase.

+1 for Zachary wrote about caching.

That's for the what mainly explain the speed difference between the two.

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 30 janv. 2013 à 23:27, john [john2roll2@gmail.com](mailto:john2roll2@gmail.com) a écrit :

You're right the lower queries are hell lot faster. approx 4 times faster than the top query. I just wanted to know what makes them different and why the lower ones are aster.  
The top queries have to be created manually and the lower ones using the Java API for Elasticsearch.

On Wednesday, 30 January 2013 16:11:14 UTC-6, Zachary Tong wrote:

> Ignoring the differences in the query itself (e.g. they query different things), I believe the performance difference is more related to your filter choice. In the top query, you are using a "Query Filter", which just wraps a query with a filter so you can cache the returned results. This can be useful if you hit the same query over and over, where it makes sense to just save the output instead of processing the request. However, you don't gain any filter search-time performance. You are effectively running a really big query string against all the docs.
> 
> The lower query uses a "Filtered Query", which first takes your corpus of documents and discards those that don't match the filter. Whatever leftover is then searched with your query. This is very fast because the filters are cached in memory, so you quickly reduce the size of documents that need to be analyzed with your query.
> 
> Perhaps I'm misunderstanding your question. Curious to see what Clint says.
> 
> -Zach
> 
> On Wednesday, January 30, 2013 4:42:15 PM UTC-5, john wrote:
> 
> > Clint, Sorry for replying so late. Had gone on a vacation.
> > 
> > This is what i mean by Elasticsearch query string:
> > 
> > {"fields":["X.price","X.name","X.marketValue","X.salePrice"],"from":0,"size":10,"sort":[{"X.price.alphanum":"asc"}],"filter":{"query":{"query\_string":{"default\_operator":"AND","query":"X.Y:false AND X.marketplace:false AND X.active:true AND X.Z:false AND X.startDate:[1910-01-01 TO 2013-01-29] AND X.end:true AND (((X.name:floor\* OR X.manufacturer:floor\* OR X.desc:floor\* OR X.desc:floor\* OR X.futures.feature:floor\* OR X.details.value:floor\*)))"}}}}
> > 
> > And this is what i mean by Lucene queries. And the queries created oin the manner below are a lot faster than i i were to create a query string for the same conditions.  
> > {  
> > "from": 0,  
> > "size": 10,  
> > "query": {  
> > "bool": {  
> > "must": {  
> > "filtered": {  
> > "query": {  
> > "match\_all": {}  
> > },  
> > "filter": {  
> > "term": {  
> > "X.id": "\*"  
> > }  
> > }  
> > }  
> > }  
> > }  
> > },  
> > "fields": [  
> > "X.id",  
> > ],  
> > "sort": [  
> > {  
> > "X.id": {  
> > "order": "asc"  
> > }  
> > }  
> > ]  
> > }
> > 
> > John
> > 
> > On Tuesday, 22 January 2013 12:23:24 UTC-6, Clinton Gormley wrote:
> > 
> > > On Tue, 2013-01-22 at 10:13 -0800, john wrote:
> > > 
> > > > By lucene query format i mean using the java API for Elasticsearch.  
> > > > The API allows to build query as a combination of queries and filters,  
> > > > the way you mentioned below.  
> > > > Before that i was query strings.
> > > 
> > > It'd be a lot easier to figure out what you were comparing if you  
> > > provided the code
> > > 
> > > clint
> > > 
> > > > On Tuesday, January 22, 2013 10:17:54 AM UTC-6, Matt Weber wrote:  
> > > > Didn't get to finish that:
> > > > 
> > > > ```
> > > > BOOLEAN 
> > > > MUST this 
> > > > MUST that 
> > > > SHOULD whatever 
> > > >     
> > > >     
> > > > ? 
> > > >     
> > > >     
> > > > On Tue, Jan 22, 2013 at 8:16 AM, Matt Weber 
> > > > <matt....@gmail.com> wrote: 
> > > > What do you mean by "lucene-query" format? The 
> > > > ElasticSearch Query String Query accepts lucene query 
> > > > syntax, ie. "this AND that OR whatever". Were you 
> > > > talking about using that format vs. crafting the 
> > > > underlying query objects 
> > > >             
> > > >             
> > > > BOOLEAN 
> > > >             
> > > >             
> > > >             
> > > >             
> > > > On Tue, Jan 22, 2013 at 8:13 AM, john 
> > > > <john2...@gmail.com> wrote: 
> > > > Hi, 
> > > >                     
> > > >                     
> > > > I tried running Elastic search queries, in the 
> > > > Lucene-query format and also in the query 
> > > > string format. 
> > > > I found that the lucene queries were 
> > > > considerably faster than the query-string 
> > > > queries, approx. 4 times faster. Can some one 
> > > > pls throw light on why is it so 
> > > >                     
> > > >                     
> > > > Thanks, 
> > > > John 
> > > > 
> > > > ```

--  
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: ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)
#### Post date: [January 31, 2013, 9:03am UTC](https://discuss.elastic.co/t/elasticsearch-lucene-queries-versus-elasticsearch-query-string/10453/10 "2013-01-31T09:03:24Z")

</div>

On Wed, 2013-01-30 at 14:27 -0800, john wrote:

> You're right the lower queries are hell lot faster. approx 4 times  
> faster than the top query. I just wanted to know what makes them  
> different and why the lower ones are aster.  
> The top queries have to be created manually and the lower ones using  
> the Java API for Elasticsearch.

I've rewritten your query\_string query to use filters, each of which  
will be cached. See how this one performs.

(Note, wildcards are not an optimal way to query large amounts of data.  
Much better to use edge ngrams)

curl -XGET '[http://127.0.0.1:9200/\_all/\_search?pretty=1](http://127.0.0.1:9200/_all/_search?pretty=1)' -d '  
{  
"query" : {  
"filtered" : {  
"filter" : {  
"and" : [  
{  
"term" : {  
"X.Y" : 0  
}  
},  
{  
"term" : {  
"X.Z" : 0  
}  
},  
{  
"X.active" : 1  
},  
{  
"term" : {  
"X.end" : 1  
}  
},  
{  
"term" : {  
"X.marketplace" : 0  
}  
},  
{  
"range" : {  
"X.startDate" : {  
"lte" : "2013-01-29",  
"gte" : "1910-01-01"  
}  
}  
}  
]  
},  
"query" : {  
"multi\_match" : {  
"fields" : [  
"X.name",  
"X.manufacturer",  
"X.desc",  
"X.futures.feature",  
"X.details.value"  
],  
"query" : "floor",  
"type" : "phrase\_prefix"  
}  
}  
}  
}  
}  
'  
clint

--  
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: ![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:53am UTC](https://discuss.elastic.co/t/elasticsearch-lucene-queries-versus-elasticsearch-query-string/10453/11 "2017-07-06T02:53:48Z")

</div>


