Is there a way to limit nested objects by something in the outer objects
and then do a facet on the nested objects?
What I tried was:
(1) Filter for a list of nested of objects that match on two fields in
the nested object.
(2) The nested objects are limited to those that match a query or filter
on the outer object by being part of query on the outer object.
I thought if I
(3) added a scope to nested query,
and
(4) Built a facet on the nested objects scope.
I'd get exactly what I needed.
This approach doesn't work, because the outer filter or query (2) does
NOT affect the documents found in nested scope for the facet (3)
Here is a cut down verion of my query to show what I am talking about.
{
"query" : {
"filtered" : {
"query" : {
"nested" : {
"filter" : { <--------- (1) filter for only the nested I wanted, it
works great.
"and" : {
"filters" : [ {
"terms" : {
"MyNested.field1" : [ "X" ],
}
}, {
"terms" : {
"MyNested.field2" : [ "a", “b”, “c” ],
"execution" : "and"
}
} ]
}
},
"path" : "MyNested",
"_scope" : "MyNestedScope" <---- (3) scoped for faceting
}
},
"filter" : { <------- (2) but limited to those that are nested within
matching outer objects, it also works great.
"terms" : {
"accessControl" : [“TheUserID" ]
}
}
}
},
"facets" : {
"SubPathFacet" : {
…
},
"scope" : "MyNestedScope" <--- (4) use of scope of nested objects to do
stats on the matching nested objects.
}
},
}
Note I have to use either nested or child because the child/nested
object has to match 2 fields for this to work.
Since I can't seem to limit the nested objects to those that are in
matching outer objects, it seems my scheme to build a facet based on
specially built nested objects is impossible.
I can't see how a facet on nested objects would ever be useful unless
the only facet one needed was the totals of all nested objects.
Am I missing something? Is there some way I can facet on nested objects
that are narrowed/limited by a query or filter on the outer objects?
Do I have to change to child objects instead and upgrade to 19.10 ? Then
I can use "has_parent" to solve this problem?
-Paul
--