# Boolean query with nested document

**URL:** https://discuss.elastic.co/t/boolean-query-with-nested-document/7920
**Category:** Elasticsearch
**Created:** [May 30, 2012, 7:43pm UTC](https://discuss.elastic.co/t/boolean-query-with-nested-document/7920 "2012-05-30T19:43:33Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![Mohit\_Anchlia](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@Mohit\_Anchlia](https://discuss.elastic.co/u/Mohit_Anchlia)
#### Post date: [May 30, 2012, 7:43pm UTC](https://discuss.elastic.co/t/boolean-query-with-nested-document/7920/1 "2012-05-30T19:43:33Z")

</div>

Currently to search nested fields I do something like:

Is it possible to somehow say "fields.MRSSN1" instead of listing out the  
complete Path like "setModel.forms.forms.fields"?

curl -XGET '[http://dslg1:9200/forms1/object/\_search](http://dslg1:9200/forms1/object/_search)' -d '{  
"query" : {  
"bool" : {  
"must" : {  
"term" : { "setModel.forms.id" : "40" }  
},  
"should" : [  
{  
"field" : { "setModel.forms.forms.fields.L31A" : "L31" }  
},  
{  
"field" : { "setModel.forms.forms.fields.MRSSN1" : "MRS1" }  
}  
],  
"minimum\_number\_should\_match" : 2,  
"boost" : 1.0  
}  
}  
}'

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [June 3, 2012, 9:16am UTC](https://discuss.elastic.co/t/boolean-query-with-nested-document/7920/2 "2012-06-03T09:16:22Z")

</div>

Yes, you can, unless you sue nested mapping (not sure if thats what you  
meant), in which case, you need to wrap the specific field in nested query.

On Wed, May 30, 2012 at 9:43 PM, Mohit Anchlia [mohitanchlia@gmail.com](mailto:mohitanchlia@gmail.com)wrote:

> Currently to search nested fields I do something like:
> 
> Is it possible to somehow say "fields.MRSSN1" instead of listing out the  
> complete Path like "setModel.forms.forms.fields"?
> 
> curl -XGET '[http://dslg1:9200/forms1/object/\_search](http://dslg1:9200/forms1/object/_search)' -d '{  
> "query" : {  
> "bool" : {  
> "must" : {  
> "term" : { "setModel.forms.id" : "40" }  
> },  
> "should" : [  
> {  
> "field" : { "setModel.forms.forms.fields.L31A" : "L31" }  
> },  
> {  
> "field" : { "setModel.forms.forms.fields.MRSSN1" : "MRS1" }  
> }  
> ],  
> "minimum\_number\_should\_match" : 2,  
> "boost" : 1.0  
> }  
> }  
> }'

---

<div class="post-metadata">

### Author: ![Mohit\_Anchlia](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@Mohit\_Anchlia](https://discuss.elastic.co/u/Mohit_Anchlia)
#### Post date: [June 3, 2012, 4:45pm UTC](https://discuss.elastic.co/t/boolean-query-with-nested-document/7920/3 "2012-06-03T16:45:15Z")

</div>

On Sun, Jun 3, 2012 at 2:16 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> Yes, you can, unless you sue nested mapping (not sure if thats what you  
> meant), in which case, you need to wrap the specific field in nested query.
> 
> Could you please give me a short example so that I can visualize what you  
> mean?

> On Wed, May 30, 2012 at 9:43 PM, Mohit Anchlia [mohitanchlia@gmail.com](mailto:mohitanchlia@gmail.com)wrote:
> 
> > Currently to search nested fields I do something like:
> > 
> > Is it possible to somehow say "fields.MRSSN1" instead of listing out the  
> > complete Path like "setModel.forms.forms.fields"?
> > 
> > curl -XGET '[http://dslg1:9200/forms1/object/\_search](http://dslg1:9200/forms1/object/_search)' -d '{  
> > "query" : {  
> > "bool" : {  
> > "must" : {  
> > "term" : { "setModel.forms.id [http://setmodel.forms.id/](http://setmodel.forms.id/)" :  
> > "40" }  
> > },  
> > "should" : [  
> > {  
> > "field" : { "setModel.forms.forms.fields.L31A" : "L31" }  
> > },  
> > {  
> > "field" : { "setModel.forms.forms.fields.MRSSN1" : "MRS1"  
> > }  
> > }  
> > ],  
> > "minimum\_number\_should\_match" : 2,  
> > "boost" : 1.0  
> > }  
> > }  
> > }'

---

<div class="post-metadata">

### Author: ![Mohit\_Anchlia](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@Mohit\_Anchlia](https://discuss.elastic.co/u/Mohit_Anchlia)
#### Post date: [June 7, 2012, 1:59pm UTC](https://discuss.elastic.co/t/boolean-query-with-nested-document/7920/4 "2012-06-07T13:59:55Z")

</div>

On Sun, Jun 3, 2012 at 9:45 AM, Mohit Anchlia [mohitanchlia@gmail.com](mailto:mohitanchlia@gmail.com)wrote:

> On Sun, Jun 3, 2012 at 2:16 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > Yes, you can, unless you sue nested mapping (not sure if thats what you  
> > meant), in which case, you need to wrap the specific field in nested query.
> > 
> > Could you please give me a short example so that I can visualize what you  
> > mean?

Is there any chance you could give me some pointers here?

> > On Wed, May 30, 2012 at 9:43 PM, Mohit Anchlia [mohitanchlia@gmail.com](mailto:mohitanchlia@gmail.com)wrote:
> > 
> > > Currently to search nested fields I do something like:
> > > 
> > > Is it possible to somehow say "fields.MRSSN1" instead of listing out the  
> > > complete Path like "setModel.forms.forms.fields"?
> > > 
> > > curl -XGET '[http://dslg1:9200/forms1/object/\_search](http://dslg1:9200/forms1/object/_search)' -d '{  
> > > "query" : {  
> > > "bool" : {  
> > > "must" : {  
> > > "term" : { "setModel.forms.id [http://setmodel.forms.id/](http://setmodel.forms.id/)"  
> > > : "40" }  
> > > },  
> > > "should" : [  
> > > {  
> > > "field" : { "setModel.forms.forms.fields.L31A" : "L31" }  
> > > },  
> > > {  
> > > "field" : { "setModel.forms.forms.fields.MRSSN1" :  
> > > "MRS1" }  
> > > }  
> > > ],  
> > > "minimum\_number\_should\_match" : 2,  
> > > "boost" : 1.0  
> > > }  
> > > }  
> > > }'

---

<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: [June 7, 2012, 2:13pm UTC](https://discuss.elastic.co/t/boolean-query-with-nested-document/7920/5 "2012-06-07T14:13:55Z")

</div>

> ```
> Could you please give me a short example so that I can
> visualize what you mean?
> 
> ```
> 
> Is there any chance you could give me some pointers here?

Have you looked at the examples in the docs? What have you tried? What  
didn't work?

---

<div class="post-metadata">

### Author: ![Mohit\_Anchlia](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@Mohit\_Anchlia](https://discuss.elastic.co/u/Mohit_Anchlia)
#### Post date: [June 7, 2012, 2:18pm UTC](https://discuss.elastic.co/t/boolean-query-with-nested-document/7920/6 "2012-06-07T14:18:37Z")

</div>

On Thu, Jun 7, 2012 at 7:13 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:

> > ```
> > Could you please give me a short example so that I can
> > visualize what you mean?
> > 
> > ```
> > 
> > Is there any chance you could give me some pointers here?
> 
> Have you looked at the examples in the docs? What have you tried? What  
> didn't work?

But with related to which topic. I don't understand what exactly Shay was  
referring to? Is it related to Mapping? if yes then which type of mapping?  
I've tried nested but didn't seem to work.

---

<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: [June 7, 2012, 2:27pm UTC](https://discuss.elastic.co/t/boolean-query-with-nested-document/7920/7 "2012-06-07T14:27:13Z")

</div>

> But with related to which topic. I don't understand what exactly Shay  
> was referring to? Is it related to Mapping? if yes then which type of  
> mapping? I've tried nested but didn't seem to work.

it's really difficult to point you in the right direction without  
knowing exactly what you're trying to do and what didn't work.

Have a read of this page [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help) which gives  
advice for how to ask a good question. The key is: We're all short on  
time, so make it easy for people to answer.

clint

---

<div class="post-metadata">

### Author: ![Mohit\_Anchlia](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@Mohit\_Anchlia](https://discuss.elastic.co/u/Mohit_Anchlia)
#### Post date: [June 7, 2012, 2:33pm UTC](https://discuss.elastic.co/t/boolean-query-with-nested-document/7920/8 "2012-06-07T14:33:18Z")

</div>

On Thu, Jun 7, 2012 at 7:27 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:

> > But with related to which topic. I don't understand what exactly Shay  
> > was referring to? Is it related to Mapping? if yes then which type of  
> > mapping? I've tried nested but didn't seem to work.
> 
> it's really difficult to point you in the right direction without  
> knowing exactly what you're trying to do and what didn't work.
> 
> Have a read of this page [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help) which gives  
> advice for how to ask a good question. The key is: We're all short on  
> time, so make it easy for people to answer.
> 
> clint

Did you get chance to look at my initial post? Is this not clear enough? If  
not then what's not clear in this description.

* * *

Currently to search nested fields I do something like:

Is it possible to somehow say "fields.MRSSN1" instead of listing out the  
complete Path like "setModel.forms.forms.fields"?

curl -XGET '[http://dslg1:9200/forms1/object/\_search](http://dslg1:9200/forms1/object/_search)' -d '{  
"query" : {  
"bool" : {  
"must" : {  
"term" : { "setModel.forms.id" : "40" }  
},  
"should" : [  
{  
"field" : { "setModel.forms.forms.fields.L31A" : "L31" }  
},  
{  
"field" : { "setModel.forms.forms.fields.MRSSN1" : "MRS1" }  
}  
],  
"minimum\_number\_should\_match" : 2,  
"boost" : 1.0  
}  
}  
}'

---

<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: [June 7, 2012, 2:41pm UTC](https://discuss.elastic.co/t/boolean-query-with-nested-document/7920/9 "2012-06-07T14:41:41Z")

</div>

> Did you get chance to look at my initial post? Is this not clear  
> enough? If not then what's not clear in this description.

I looked at your original post. Shay's response was "not sure if that is  
what you meant", which implies that the post isn't clear.

You use the term "nested" but then you don't use nested queries in your  
example.

So reposting the same post doesn't make it any clearer. Read this

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

clint

> * * *
> 
> Currently to search nested fields I do something like:
> 
> Is it possible to somehow say "fields.MRSSN1" instead of listing out  
> the complete Path like "setModel.forms.forms.fields"?
> 
> curl -XGET '[http://dslg1:9200/forms1/object/\_search](http://dslg1:9200/forms1/object/_search)' -d '{  
> "query" : {  
> "bool" : {  
> "must" : {  
> "term" : { "setModel.forms.id" : "40" }  
> },  
> "should" : [  
> {  
> "field" : { "setModel.forms.forms.fields.L31A" :  
> "L31" }  
> },  
> {  
> "field" : { "setModel.forms.forms.fields.MRSSN1" :  
> "MRS1" }  
> }  
> ],  
> "minimum\_number\_should\_match" : 2,  
> "boost" : 1.0  
> }  
> }  
> }'

---

<div class="post-metadata">

### Author: ![Mohit\_Anchlia](https://avatars.discourse-cdn.com/v4/letter/m/848f3c/32.png) [@Mohit\_Anchlia](https://discuss.elastic.co/u/Mohit_Anchlia)
#### Post date: [June 7, 2012, 2:49pm UTC](https://discuss.elastic.co/t/boolean-query-with-nested-document/7920/10 "2012-06-07T14:49:53Z")

</div>

On Thu, Jun 7, 2012 at 7:41 AM, Clinton Gormley [clint@traveljury.com](mailto:clint@traveljury.com)wrote:

> > Did you get chance to look at my initial post? Is this not clear  
> > enough? If not then what's not clear in this description.
> 
> I looked at your original post. Shay's response was "not sure if that is  
> what you meant", which implies that the post isn't clear.
> 
> You use the term "nested" but then you don't use nested queries in your  
> example.
> 
> So reposting the same post doesn't make it any clearer. Read this  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/help)

Well that is what I am asking 🙂 What do I need to do to make it is such  
that I can say fields.MSR11 instead of giving the full path.  
clint

> > * * *
> > 
> > Currently to search nested fields I do something like:
> > 
> > Is it possible to somehow say "fields.MRSSN1" instead of listing out  
> > the complete Path like "setModel.forms.forms.fields"?
> > 
> > curl -XGET '[http://dslg1:9200/forms1/object/\_search](http://dslg1:9200/forms1/object/_search)' -d '{  
> > "query" : {  
> > "bool" : {  
> > "must" : {  
> > "term" : { "setModel.forms.id [http://setmodel.forms.id/](http://setmodel.forms.id/)"  
> > : "40" }  
> > },  
> > "should" : [  
> > {  
> > "field" : { "setModel.forms.forms.fields.L31A" :  
> > "L31" }  
> > },  
> > {  
> > "field" : { "setModel.forms.forms.fields.MRSSN1" :  
> > "MRS1" }  
> > }  
> > ],  
> > "minimum\_number\_should\_match" : 2,  
> > "boost" : 1.0  
> > }  
> > }  
> > }'

---

<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: [June 7, 2012, 2:52pm UTC](https://discuss.elastic.co/t/boolean-query-with-nested-document/7920/11 "2012-06-07T14:52:54Z")

</div>

> Well that is what I am asking 🙂 What do I need to do to make it is  
> such that I can say fields.MSR11 instead of giving the full path.  
> clint

Nothing. It just works.

I can't guess what you're doing wrong, so if you're not going to give an  
example showing what you tried and how it doesn't work, then I don't  
have the time to help you.

> ```
> > ----
> >
> > Currently to search nested fields I do something like:
> >
> > Is it possible to somehow say "fields.MRSSN1" instead of
> listing out
> > the complete Path like "setModel.forms.forms.fields"?
> >
> > curl -XGET 'http://dslg1:9200/forms1/object/_search' -d '{
> > "query" : {
> > "bool" : {
> > "must" : {
> > "term" : { "setModel.forms.id" : "40" }
> > },
> > "should" : [
> > {
> > "field" :
> { "setModel.forms.forms.fields.L31A" :
> > "L31" }
> > },
> > {
> > "field" :
> { "setModel.forms.forms.fields.MRSSN1" :
> > "MRS1" }
> > }
> > ],
> > "minimum_number_should_match" : 2,
> > "boost" : 1.0
> > }
> > }
> > }'
> >
> 
> ```

---

<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:25am UTC](https://discuss.elastic.co/t/boolean-query-with-nested-document/7920/12 "2017-07-06T03:25:21Z")

</div>


