BUG?: faceting on nested-documents (with scope) doesn't take filter on parent-docs into account

I'm banging my head against the wall on trying on faceting on
nested-documents with:

  • a filter on the nested documents
  • a filter on the 'parent' documents

To me the query (at end of post) should just work. Explanation:

  • a queryfilter is created limiting all hits AND facets to only match
    against parent-docs with field rec=80
  • a queryfilter is created limiting all hits AND facets to only match
    against parent-docs which have a nested-doc with ddp.ddpindex = "b" (this
    filter is defined as scope: 'scope_ddp_exists')

Then I'd like to facet on nested field 'ddp.price' using just defined scope
'scope_ddp_exists'.
To my understanding (since facets should already be contrained by 'rec=80')
this should return nested docs:

  • of which the parent is contrained to rec=80
  • of which the nested-doc itself has the field ddpindex='b'

However, the filter " rec=80" isn't taken into account at all.

What's wrong with this filter? It is as if 'scope_ddp_exists' is placed
directly under the global-scope, instead of taking queryfilters set under
scope 'main' into account?
If this is intended, is there any other way to construct the query to facet
on scope 'scope_ddp_exists' while still taking the other (query)-filters
into account?

{
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"and": [
{
"term": {"rec": 80}
},
{
"nested":{
"_scope": "scope_ddp_exists",
"path":"ddp",
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"term":{"ddp.ddpindex":"b"}
}
}
}
}
}
]
}
}
},
"facets": {
"priceslider": {
"terms": {
"field": "ddp.price"
},
"scope": "scope_ddp_exists"
}
}
}

Thanks,
Geert-Jan

--

On Friday, December 21, 2012 12:16:18 PM UTC+1, Geert-Jan Brits wrote:

I'm banging my head against the wall on trying on faceting on
nested-documents with:

  • a filter on the nested documents
  • a filter on the 'parent' documents

To me the query (at end of post) should just work. Explanation:

  • a queryfilter is created limiting all hits AND facets to only match
    against parent-docs with field rec=80
  • a queryfilter is created limiting all hits AND facets to only match
    against parent-docs which have a nested-doc with ddp.ddpindex = "b" (this
    filter is defined as scope: 'scope_ddp_exists')

Then I'd like to facet on nested field 'ddp.price' using just defined
scope 'scope_ddp_exists'.
To my understanding (since facets should already be contrained by
'rec=80') this should return nested docs:

  • of which the parent is contrained to rec=80
  • of which the nested-doc itself has the field ddpindex='b'

However, the filter " rec=80" isn't taken into account at all.

What's wrong with this filter? It is as if 'scope_ddp_exists' is placed
directly under the global-scope, instead of taking queryfilters set under
scope 'main' into account?
If this is intended, is there any other way to construct the query to
facet on scope 'scope_ddp_exists' while still taking the other
(query)-filters into account?

{
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"and": [
{
"term": {"rec": 80}
},
{
"nested":{
"_scope": "scope_ddp_exists",
"path":"ddp",
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"term":{"ddp.ddpindex":"b"}
}
}
}
}
}
]
}
}
},
"facets": {
"priceslider": {
"terms": {
"field": "ddp.price"
},
"scope": "scope_ddp_exists"
}
}
}

Thanks,
Geert-Jan

--

Sorry about still confusing the nomenclature. When talking about the
'parent'-doc I mean the document on top-level which contains the
nested-documents. I'm familiar that this is different than parent-child
relationships

On Friday, December 21, 2012 12:17:27 PM UTC+1, Geert-Jan Brits wrote:

On Friday, December 21, 2012 12:16:18 PM UTC+1, Geert-Jan Brits wrote:

I'm banging my head against the wall on trying on faceting on
nested-documents with:

  • a filter on the nested documents
  • a filter on the 'parent' documents

To me the query (at end of post) should just work. Explanation:

  • a queryfilter is created limiting all hits AND facets to only match
    against parent-docs with field rec=80
  • a queryfilter is created limiting all hits AND facets to only match
    against parent-docs which have a nested-doc with ddp.ddpindex = "b" (this
    filter is defined as scope: 'scope_ddp_exists')

Then I'd like to facet on nested field 'ddp.price' using just defined
scope 'scope_ddp_exists'.
To my understanding (since facets should already be contrained by
'rec=80') this should return nested docs:

  • of which the parent is contrained to rec=80
  • of which the nested-doc itself has the field ddpindex='b'

However, the filter " rec=80" isn't taken into account at all.

What's wrong with this filter? It is as if 'scope_ddp_exists' is placed
directly under the global-scope, instead of taking queryfilters set under
scope 'main' into account?
If this is intended, is there any other way to construct the query to
facet on scope 'scope_ddp_exists' while still taking the other
(query)-filters into account?

{
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"and": [
{
"term": {"rec": 80}
},
{
"nested":{
"_scope": "scope_ddp_exists",
"path":"ddp",
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"term":{"ddp.ddpindex":"b"}
}
}
}
}
}
]
}
}
},
"facets": {
"priceslider": {
"terms": {
"field": "ddp.price"
},
"scope": "scope_ddp_exists"
}
}
}

Thanks,
Geert-Jan

--

It's a known
issue https://github.com/elasticsearch/elasticsearch/issues/2398

On Friday, December 21, 2012 6:31:08 AM UTC-5, Geert-Jan Brits wrote:

Sorry about still confusing the nomenclature. When talking about the
'parent'-doc I mean the document on top-level which contains the
nested-documents. I'm familiar that this is different than parent-child
relationships

On Friday, December 21, 2012 12:17:27 PM UTC+1, Geert-Jan Brits wrote:

On Friday, December 21, 2012 12:16:18 PM UTC+1, Geert-Jan Brits wrote:

I'm banging my head against the wall on trying on faceting on
nested-documents with:

  • a filter on the nested documents
  • a filter on the 'parent' documents

To me the query (at end of post) should just work. Explanation:

  • a queryfilter is created limiting all hits AND facets to only match
    against parent-docs with field rec=80
  • a queryfilter is created limiting all hits AND facets to only match
    against parent-docs which have a nested-doc with ddp.ddpindex = "b" (this
    filter is defined as scope: 'scope_ddp_exists')

Then I'd like to facet on nested field 'ddp.price' using just defined
scope 'scope_ddp_exists'.
To my understanding (since facets should already be contrained by
'rec=80') this should return nested docs:

  • of which the parent is contrained to rec=80
  • of which the nested-doc itself has the field ddpindex='b'

However, the filter " rec=80" isn't taken into account at all.

What's wrong with this filter? It is as if 'scope_ddp_exists' is placed
directly under the global-scope, instead of taking queryfilters set under
scope 'main' into account?
If this is intended, is there any other way to construct the query to
facet on scope 'scope_ddp_exists' while still taking the other
(query)-filters into account?

{
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"and": [
{
"term": {"rec": 80}
},
{
"nested":{
"_scope": "scope_ddp_exists",
"path":"ddp",
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"term":{"ddp.ddpindex":"b"}
}
}
}
}
}
]
}
}
},
"facets": {
"priceslider": {
"terms": {
"field": "ddp.price"
},
"scope": "scope_ddp_exists"
}
}
}

Thanks,
Geert-Jan

--

Ahh somehow glad I'm not going insane. Something that would trivially solve
my use-case (and would be of much use in general imo) , thinking out loud
here, would be to be able to set '_scope' on 'container-filters' such and
'bool' as well as 'and' as long as that container-filter contains a
nested-filter as one of it's elements.
This would allow for creating arbitrary complex filters when faceting on
nested documents.

2012/12/21 Igor Motov imotov@gmail.com

It's a known issue
https://github.com/elasticsearch/elasticsearch/issues/2398

On Friday, December 21, 2012 6:31:08 AM UTC-5, Geert-Jan Brits wrote:

Sorry about still confusing the nomenclature. When talking about the
'parent'-doc I mean the document on top-level which contains the
nested-documents. I'm familiar that this is different than parent-child
relationships

On Friday, December 21, 2012 12:17:27 PM UTC+1, Geert-Jan Brits wrote:

On Friday, December 21, 2012 12:16:18 PM UTC+1, Geert-Jan Brits wrote:

I'm banging my head against the wall on trying on faceting on
nested-documents with:

  • a filter on the nested documents
  • a filter on the 'parent' documents

To me the query (at end of post) should just work. Explanation:

  • a queryfilter is created limiting all hits AND facets to only match
    against parent-docs with field rec=80
  • a queryfilter is created limiting all hits AND facets to only match
    against parent-docs which have a nested-doc with ddp.ddpindex = "b" (this
    filter is defined as scope: 'scope_ddp_exists')

Then I'd like to facet on nested field 'ddp.price' using just defined
scope 'scope_ddp_exists'.
To my understanding (since facets should already be contrained by
'rec=80') this should return nested docs:

  • of which the parent is contrained to rec=80
  • of which the nested-doc itself has the field ddpindex='b'

However, the filter " rec=80" isn't taken into account at all.

What's wrong with this filter? It is as if 'scope_ddp_exists' is
placed directly under the global-scope, instead of taking queryfilters set
under scope 'main' into account?
If this is intended, is there any other way to construct the query to
facet on scope 'scope_ddp_exists' while still taking the other
(query)-filters into account?

{
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"and": [
{
"term": {"rec": 80}
},
{
"nested":{
"_scope": "scope_ddp_exists",
"path":"ddp",
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"term":{"ddp.ddpindex":"b"}
}
}
}
}
}
]
}
}
},
"facets": {
"priceslider": {
"terms": {
"field": "ddp.price"
},
"scope": "scope_ddp_exists"
}
}
}

Thanks,
Geert-Jan

--

--

Another approach would be

and return the matched nested-document and 'merge' it in the doc at
top-level.
Afterwards facet on the fields of the merged nested doc as if they are
properties of the parent.

Incredibly powerful, since sorting, filtering, faceting, returning fields,
could just be done without the client even caring if the fields are from a
matched nested doc or from the main doc itself..
Oh well, pie in the skie at this moment I guess.

2012/12/21 Geert-Jan Brits gbrits@gmail.com

Ahh somehow glad I'm not going insane. Something that would trivially
solve my use-case (and would be of much use in general imo) , thinking out
loud here, would be to be able to set '_scope' on 'container-filters' such
and 'bool' as well as 'and' as long as that container-filter contains a
nested-filter as one of it's elements.
This would allow for creating arbitrary complex filters when faceting on
nested documents.

2012/12/21 Igor Motov imotov@gmail.com

It's a known issue
https://github.com/elasticsearch/elasticsearch/issues/2398

On Friday, December 21, 2012 6:31:08 AM UTC-5, Geert-Jan Brits wrote:

Sorry about still confusing the nomenclature. When talking about the
'parent'-doc I mean the document on top-level which contains the
nested-documents. I'm familiar that this is different than parent-child
relationships

On Friday, December 21, 2012 12:17:27 PM UTC+1, Geert-Jan Brits wrote:

On Friday, December 21, 2012 12:16:18 PM UTC+1, Geert-Jan Brits wrote:

I'm banging my head against the wall on trying on faceting on
nested-documents with:

  • a filter on the nested documents
  • a filter on the 'parent' documents

To me the query (at end of post) should just work. Explanation:

  • a queryfilter is created limiting all hits AND facets to only match
    against parent-docs with field rec=80
  • a queryfilter is created limiting all hits AND facets to only match
    against parent-docs which have a nested-doc with ddp.ddpindex = "b" (this
    filter is defined as scope: 'scope_ddp_exists')

Then I'd like to facet on nested field 'ddp.price' using just defined
scope 'scope_ddp_exists'.
To my understanding (since facets should already be contrained by
'rec=80') this should return nested docs:

  • of which the parent is contrained to rec=80
  • of which the nested-doc itself has the field ddpindex='b'

However, the filter " rec=80" isn't taken into account at all.

What's wrong with this filter? It is as if 'scope_ddp_exists' is
placed directly under the global-scope, instead of taking queryfilters set
under scope 'main' into account?
If this is intended, is there any other way to construct the query to
facet on scope 'scope_ddp_exists' while still taking the other
(query)-filters into account?

{
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"and": [
{
"term": {"rec": 80}
},
{
"nested":{
"_scope": "scope_ddp_exists",
"path":"ddp",
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"term":{"ddp.ddpindex":"b"}
}
}
}
}
}
]
}
}
},
"facets": {
"priceslider": {
"terms": {
"field": "ddp.price"
},
"scope": "scope_ddp_exists"
}
}
}

Thanks,
Geert-Jan

--

--