A facet on specific embedded docs


(Nick Hoffman) #1

Hi guys. With documents like this:

{ title: "grimlock", tags: [ {name: "character", value: "grimlock"}, {name:
"series", value: "original"} ] }

{ title: "megatron", tags: [ {name: "character", value: "megatron"}, {name:
"series", value: "original"} ] }

How can I build a facet on "tags.value" where "tags.name" is "character"?
For example, I'd like to get "grimlock" and "megatron", but not "original".

The best I've been able to do so far is below. However, it returns
"original" and "megatron", instead of just "megatron".

curl 'localhost:9200/test/items/_search?pretty=1' -d '
{
size: 0,

facets: {
tags: {
terms: {
field: "tags.value",
params: { target: "title", value: "megatron" },
script: "doc[target].value == value"
}
}
}
}'

Outputs:

"facets" : {
"tags" : {
...snip...
"terms" : [
{ "term" : "original", "count" : 1 },
{ "term" : "megatron", "count" : 1 }
]

Thanks for your help, everyone.
Nick


(Jan Fiedler) #2

I believe that you need to look at 'nested objects' (aka parent / child)
for your 'tags'. I have not used it myself yet so I am not 100% sure it
will provide all the faceting capabilities you need (but I think they
should).


(Shay Banon) #3

Yea, nested is the way to go, so each element in the array will be treated as its own "document". Parent/Child is a different feature :).

On Sunday, February 5, 2012 at 12:24 PM, Jan Fiedler wrote:

I believe that you need to look at 'nested objects' (aka parent / child) for your 'tags'. I have not used it myself yet so I am not 100% sure it will provide all the faceting capabilities you need (but I think they should).


(Nick Hoffman) #4

Thanks guys. Nested documents makes perfect sense.


(posejavier) #5

Hi Nick,
I have the same problem but still didnt find the solution.
What I did is to index the field as type "nested" and afterwards I applied the script to the facets (basically the same script as you posted).
The problem is that I still do not receive the filtered facets (I get all the facets like if the field would be not nested)
How did you solve the problem?


(Nick Hoffman) #6

On Thursday, 3 May 2012 05:53:06 UTC-4, jp50045 wrote:

Hi Nick,
I have the same problem but still didnt find the solution.
What I did is to index the field as type "nested" and afterwards I applied
the script to the facets (basically the same script as you posted).
The problem is that I still do not receive the filtered facets (I get all
the facets like if the field would be not nested)
How did you solve the problem?

Actually, I haven't solved it yet. We delayed the feature that caused me to
look into this.

When you find a solution, please do post it here!

Cheers,
Nick


(system) #7