# What's wrong with this query? (has\_parent + bool)

**URL:** https://discuss.elastic.co/t/whats-wrong-with-this-query-has-parent-bool/16297
**Category:** Elasticsearch
**Created:** [March 11, 2014, 7:56pm UTC](https://discuss.elastic.co/t/whats-wrong-with-this-query-has-parent-bool/16297 "2014-03-11T19:56:08Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Robin\_Boutros](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robin_boutros/32/1727_2.png) [@Robin\_Boutros](https://discuss.elastic.co/u/Robin_Boutros)
#### Post date: [March 11, 2014, 7:56pm UTC](https://discuss.elastic.co/t/whats-wrong-with-this-query-has-parent-bool/16297/1 "2014-03-11T19:56:08Z")

</div>

I get this error: Parse Failure [No parser for element [parent\_type]]

Here's the query:

{  
:query=\>  
{:bool=\>{  
:must=\>  
[{:term=\>{:verified=\>{:term=\>true}}},  
{:term=\>{:archetype=\>{:term=\>0}}}]  
},  
:has\_parent=\> {  
:parent\_type=\>"player",  
:query=\>{:bool=\>{:must=\>[{:term=\>{:online=\>{:term=\>true}}}]}}  
}  
},  
:sort=\>[{:scrawled\_at=\>"desc"}],  
:facets=\> {...},  
:size=\>15,  
:from=\>0  
}

What's wrong with it? The has\_parent clause is nested in the query properly.  
Is it the presence of the bool query that is a problem? Because a simple {:query  
=\> { :has\_parent: {...} }}works fine.

I also managed to make it work by placing the has\_parent clause in a filter  
instead of the query. But I want the has\_parent clause to affect facet  
counts. So I think what I would need would be a filtered\_query?

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/0af06fc1-ca80-4906-9d6f-9db045f96257%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/0af06fc1-ca80-4906-9d6f-9db045f96257%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)
#### Post date: [March 11, 2014, 9:06pm UTC](https://discuss.elastic.co/t/whats-wrong-with-this-query-has-parent-bool/16297/2 "2014-03-11T21:06:52Z")

</div>

If you want to AND the has\_parent to your bool criteria, simply move it  
into the must array and it will work fine. The DSL should be something like  
this:

{  
"query": {  
"bool": {  
"must": [  
{ "term": { "verified": "true" } },  
{ "term": { "archetype": "0" } },  
{  
"has\_parent": { ... }  
}  
]  
}  
}  
}

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/82c78944-e18d-4e15-81c8-b97fa19d1845%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/82c78944-e18d-4e15-81c8-b97fa19d1845%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Robin\_Boutros](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/robin_boutros/32/1727_2.png) [@Robin\_Boutros](https://discuss.elastic.co/u/Robin_Boutros)
#### Post date: [March 11, 2014, 9:19pm UTC](https://discuss.elastic.co/t/whats-wrong-with-this-query-has-parent-bool/16297/3 "2014-03-11T21:19:24Z")

</div>

Ok! I'll try it, thanks.

Am I correct when I say that I should move things like `{ "term": { "verified": "true" } }` to filters? They will affect facet counts if they  
are inside a filtered query, right?

{  
:filtered=\> {

```
 :query => {

     :bool => { ... }

 },

 :filter => {

     :and => {

         :term=>{:verified=>{:term=>true}},

         ....

     }         

 }

```

}

}

On Tuesday, March 11, 2014 5:06:52 PM UTC-4, Binh Ly wrote:

> If you want to AND the has\_parent to your bool criteria, simply move it  
> into the must array and it will work fine. The DSL should be something like  
> this:
> 
> {  
> "query": {  
> "bool": {  
> "must": [  
> { "term": { "verified": "true" } },  
> { "term": { "archetype": "0" } },  
> {  
> "has\_parent": { ... }  
> }  
> ]  
> }  
> }  
> }

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/8219b357-da5a-4224-8ba6-78a214f4868b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8219b357-da5a-4224-8ba6-78a214f4868b%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

### Author: ![Binh\_Ly\_2](https://avatars.discourse-cdn.com/v4/letter/b/d07c76/32.png) [@Binh\_Ly\_2](https://discuss.elastic.co/u/Binh_Ly_2)
#### Post date: [March 11, 2014, 9:37pm UTC](https://discuss.elastic.co/t/whats-wrong-with-this-query-has-parent-bool/16297/4 "2014-03-11T21:37:55Z")

</div>

Yes you are correct. Everything within the top-level query (which includes  
a filtered query) will affect all the facets by default.

--  
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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/19ca58f6-bd0a-4afc-89f7-60954a73d6b8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/19ca58f6-bd0a-4afc-89f7-60954a73d6b8%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:44am UTC](https://discuss.elastic.co/t/whats-wrong-with-this-query-has-parent-bool/16297/5 "2017-07-06T01:44:06Z")

</div>


