What's wrong with this query? (has_parent + bool)


(Robin Boutros) #1

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


(Binh Ly-2) #2

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


(Robin Boutros) #3

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


(Binh Ly-2) #4

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


(system) #5