# Which query is the best for standard searching?

**URL:** <https://discuss.elastic.co/t/which-query-is-the-best-for-standard-searching/8194>\
**Category:** Elasticsearch\
**Created:** [June 22, 2012, 12:49pm UTC](https://discuss.elastic.co/t/which-query-is-the-best-for-standard-searching/8194 "2012-06-22T12:49:57Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![Rafal\_Kuc\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rafal_kuc_3/32/799_2.png) [@Rafal\_Kuc\_3](https://discuss.elastic.co/u/Rafal_Kuc_3)\
**Post date:** [July 5, 2012, 9:25pm UTC](https://discuss.elastic.co/t/which-query-is-the-best-for-standard-searching/8194/21 "2012-07-05T21:25:00Z")

</div>

Hello!

First of all I would suggest creating a separate thread for your  
question Shaun. It's easier to find answers for others, when new  
thread is created for each question.

So, let's stick to the original question - an example query. I won't  
give you a general example, but lets say that your user entered the  
'daily notice' text into the search box and you want to get results  
with phrase queries and stuff like that. We would like at least 50% of  
the terms entered into the search box to be found. Also you would like  
'name' field to be more valuable than 'description' field (this are  
the only fields you are searching). In addition to that, you want the  
query to return only results from a 'category' named 'books' (so you  
have category field in your index). The example query may look like  
this:

{  
"query": {  
"query\_string" : {  
"query": "daily notice",  
"fields" : ["description", "name^100"],  
"minimum\_should\_match": "50%",  
"use\_dis\_max": true,  
"tie\_breaker": 0.9,  
"auto\_generate\_phrase\_queries": true  
},  
"filter" : {  
"and": {  
"filters": [ {  
"term" : { "category" : "books"}  
} ]  
}  
}  
}  
}

Of course, as you may already noticed, the same thing can be done in  
multiple ways in ElasticSearch. The above is just an example you can  
start with and further expand and change to match your needs.

Hope that helps, at least a bit.

--  
Regards,  
Rafał Kuć  
Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch - ElasticSearch

Hi Marcin

You're not alone; i've found the query DSL quite difficult to understand.

This is what i have for my search so far. It's basically a wildcard text search which is then filtered to restrict access based on some  
of the document properties.

Perhaps this is even more basic than you're looking for. I'm only just starting out with ES and have never used Lucene before.  
I imagine what i have done would be considered absolutely terrible by those "in the know".

> <https://gist.github.com/therto/3053914>

I'd be very grateful if someone who has a good understanding of the ES query DSL could take a look at that gist and provide some feedback about the way i've done it and possibly show me how to improve it and/or some alternative implementations.

A tutorial about the DSL structure would be good (for totally new users) but i have not seen anything very helpful to me yet.  
It's just been lots of head-scratching and trial-&-error so far. 🙂

cheers

- shaun

--  
shaun etherton  
Sent with Sparrow

On Thursday, 5 July 2012 at 9:52 PM, Marcin Oleszkiewicz wrote:  
at the moment I know (thanks to Rafał) how should I build such query

1. BOOLEAN query with OR that will find all docs with at least one term
2. PHRASE\_QUERY to boost documents with words close to each other (using sloop)
3. BOOSTING QUERY to boost that have all terms in the field
4. use some language plugin

how to combine it to a query, it's kinda hard fo a newbie

---

<div class="post-metadata">

**Author:** ![Marcin\_Oleszkiewicz](https://avatars.discourse-cdn.com/v4/letter/m/b5e925/32.png) [@Marcin\_Oleszkiewicz](https://discuss.elastic.co/u/Marcin_Oleszkiewicz)\
**Post date:** [July 6, 2012, 9:07am UTC](https://discuss.elastic.co/t/which-query-is-the-best-for-standard-searching/8194/22 "2012-07-06T09:07:46Z")

</div>

Rafa could you show how I should build the query you have decsribed to me  
before?

---

<div class="post-metadata">

**Author:** ![Shaun\_Etherton](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaun_etherton/32/2540_2.png) [@Shaun\_Etherton](https://discuss.elastic.co/u/Shaun_Etherton)\
**Post date:** [July 6, 2012, 1:20pm UTC](https://discuss.elastic.co/t/which-query-is-the-best-for-standard-searching/8194/23 "2012-07-06T13:20:23Z")

</div>

Hi, You're right.

Sorry, I wasn't trying to hijack the thread, just trying to help the OP with an example that's working for my simple use-case. I'll create a new thread and ask for some tips there. 🙂

Cheers --  
Shaun

On Friday, 6 July 2012 at 6:55, Rafał Kuć wrote:

> Hello!
> 
> First of all I would suggest creating a separate thread for your  
> question Shaun. It's easier to find answers for others, when new  
> thread is created for each question.
> 
> So, let's stick to the original question - an example query. I won't  
> give you a general example, but lets say that your user entered the  
> 'daily notice' text into the search box and you want to get results  
> with phrase queries and stuff like that. We would like at least 50% of  
> the terms entered into the search box to be found. Also you would like  
> 'name' field to be more valuable than 'description' field (this are  
> the only fields you are searching). In addition to that, you want the  
> query to return only results from a 'category' named 'books' (so you  
> have category field in your index). The example query may look like  
> this:
> 
> {  
> "query": {  
> "query\_string" : {  
> "query": "daily notice",  
> "fields" : ["description", "name^100"],  
> "minimum\_should\_match": "50%",  
> "use\_dis\_max": true,  
> "tie\_breaker": 0.9,  
> "auto\_generate\_phrase\_queries": true  
> },  
> "filter" : {  
> "and": {  
> "filters": [ {  
> "term" : { "category" : "books"}  
> } ]  
> }  
> }  
> }  
> }
> 
> Of course, as you may already noticed, the same thing can be done in  
> multiple ways in Elasticsearch. The above is just an example you can  
> start with and further expand and change to match your needs.
> 
> Hope that helps, at least a bit.
> 
> --  
> Regards,  
> Rafał Kuć  
> Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch - Elasticsearch
> 
> Hi Marcin
> 
> You're not alone; i've found the query DSL quite difficult to understand.
> 
> This is what i have for my search so far. It's basically a wildcard text search which is then filtered to restrict access based on some  
> of the document properties.
> 
> Perhaps this is even more basic than you're looking for. I'm only just starting out with ES and have never used Lucene before.  
> I imagine what i have done would be considered absolutely terrible by those "in the know".
> 
> [https://gist.github.com/3053914](https://gist.github.com/3053914)
> 
> I'd be very grateful if someone who has a good understanding of the ES query DSL could take a look at that gist and provide some feedback about the way i've done it and possibly show me how to improve it and/or some alternative implementations.
> 
> A tutorial about the DSL structure would be good (for totally new users) but i have not seen anything very helpful to me yet.  
> It's just been lots of head-scratching and trial-&-error so far. 🙂
> 
> cheers
> 
> - shaun
> 
> --  
> shaun etherton  
> Sent with Sparrow
> 
> On Thursday, 5 July 2012 at 9:52 PM, Marcin Oleszkiewicz wrote:  
> at the moment I know (thanks to Rafał) how should I build such query
> 
> 1. BOOLEAN query with OR that will find all docs with at least one term
> 2. PHRASE\_QUERY to boost documents with words close to each other (using sloop)
> 3. BOOSTING QUERY to boost that have all terms in the field
> 4. use some language plugin
> 
> how to combine it to a query, it's kinda hard fo a newbie

---

<div class="post-metadata">

**Author:** ![Shaun\_Etherton](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaun_etherton/32/2540_2.png) [@Shaun\_Etherton](https://discuss.elastic.co/u/Shaun_Etherton)\
**Post date:** [July 6, 2012, 1:25pm UTC](https://discuss.elastic.co/t/which-query-is-the-best-for-standard-searching/8194/24 "2012-07-06T13:25:58Z")

</div>

For me, this example & description of the requirement is very very helpful - thank you!

On Friday, 6 July 2012 at 6:55, Rafał Kuć wrote:

> Hello!
> 
> First of all I would suggest creating a separate thread for your  
> question Shaun. It's easier to find answers for others, when new  
> thread is created for each question.
> 
> So, let's stick to the original question - an example query. I won't  
> give you a general example, but lets say that your user entered the  
> 'daily notice' text into the search box and you want to get results  
> with phrase queries and stuff like that. We would like at least 50% of  
> the terms entered into the search box to be found. Also you would like  
> 'name' field to be more valuable than 'description' field (this are  
> the only fields you are searching). In addition to that, you want the  
> query to return only results from a 'category' named 'books' (so you  
> have category field in your index). The example query may look like  
> this:
> 
> {  
> "query": {  
> "query\_string" : {  
> "query": "daily notice",  
> "fields" : ["description", "name^100"],  
> "minimum\_should\_match": "50%",  
> "use\_dis\_max": true,  
> "tie\_breaker": 0.9,  
> "auto\_generate\_phrase\_queries": true  
> },  
> "filter" : {  
> "and": {  
> "filters": [ {  
> "term" : { "category" : "books"}  
> } ]  
> }  
> }  
> }  
> }
> 
> Of course, as you may already noticed, the same thing can be done in  
> multiple ways in Elasticsearch. The above is just an example you can  
> start with and further expand and change to match your needs.
> 
> Hope that helps, at least a bit.
> 
> --  
> Regards,  
> Rafał Kuć  
> Sematext :: [http://sematext.com/](http://sematext.com/) :: Solr - Lucene - Nutch - Elasticsearch
> 
> Hi Marcin
> 
> You're not alone; i've found the query DSL quite difficult to understand.
> 
> This is what i have for my search so far. It's basically a wildcard text search which is then filtered to restrict access based on some  
> of the document properties.
> 
> Perhaps this is even more basic than you're looking for. I'm only just starting out with ES and have never used Lucene before.  
> I imagine what i have done would be considered absolutely terrible by those "in the know".
> 
> [https://gist.github.com/3053914](https://gist.github.com/3053914)
> 
> I'd be very grateful if someone who has a good understanding of the ES query DSL could take a look at that gist and provide some feedback about the way i've done it and possibly show me how to improve it and/or some alternative implementations.
> 
> A tutorial about the DSL structure would be good (for totally new users) but i have not seen anything very helpful to me yet.  
> It's just been lots of head-scratching and trial-&-error so far. 🙂
> 
> cheers
> 
> - shaun
> 
> --  
> shaun etherton  
> Sent with Sparrow
> 
> On Thursday, 5 July 2012 at 9:52 PM, Marcin Oleszkiewicz wrote:  
> at the moment I know (thanks to Rafał) how should I build such query
> 
> 1. BOOLEAN query with OR that will find all docs with at least one term
> 2. PHRASE\_QUERY to boost documents with words close to each other (using sloop)
> 3. BOOSTING QUERY to boost that have all terms in the field
> 4. use some language plugin
> 
> how to combine it to a query, it's kinda hard fo a newbie

---

<div class="post-metadata">

**Author:** ![Sebastien\_Lorber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sebastien_lorber/32/2551_2.png) [@Sebastien\_Lorber](https://discuss.elastic.co/u/Sebastien_Lorber)\
**Post date:** [July 6, 2012, 1:35pm UTC](https://discuss.elastic.co/t/which-query-is-the-best-for-standard-searching/8194/25 "2012-07-06T13:35:21Z")

</div>

Hello,

I hope it will help some of you.  
I'm quite new to ES and also find it difficult.

You'll find my Java implementation + mapping + unit test of some complex  
query.

This query permits to get highlights. The unit test works, but i'm not even  
sure it's the good way to do, or if it scales well.

---

<div class="post-metadata">

**Author:** ![Sebastien\_Lorber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sebastien_lorber/32/2551_2.png) [@Sebastien\_Lorber](https://discuss.elastic.co/u/Sebastien_Lorber)\
**Post date:** [July 6, 2012, 1:36pm UTC](https://discuss.elastic.co/t/which-query-is-the-best-for-standard-searching/8194/26 "2012-07-06T13:36:39Z")

</div>

Oups i forgot the link!!!

> <https://gist.github.com/slorber/3053540>
>
> There are more than three files. show original

On Friday, July 6, 2012 3:35:21 PM UTC+2, Sébastien Lorber wrote:

> Hello,
> 
> I hope it will help some of you.  
> I'm quite new to ES and also find it difficult.
> 
> You'll find my Java implementation + mapping + unit test of some complex  
> query.
> 
> This query permits to get highlights. The unit test works, but i'm not  
> even sure it's the good way to do, or if it scales well.

---

<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:21am UTC](https://discuss.elastic.co/t/which-query-is-the-best-for-standard-searching/8194/27 "2017-07-06T03:21:16Z")

</div>

Closed on July 6, 2017, 3:21am UTC



[Previous page](https://discuss.elastic.co/t/which-query-is-the-best-for-standard-searching/8194.md?page=1)
