Facet count on nested documents

Hi!

I have a problem with facets on nested documents.

Here is my code (PHP):
https://gist.github.com/2929265
The populate() method creates the mapping and indexes documents.
The search method returns results.

My mapping:
https://gist.github.com/2929280
My PHP code creates 5000 players and 100-200 balls per player.

My query:
https://gist.github.com/2929285
The "and" filter is not really useful, but it allows to combine filters on
the root documents and the nested documents.
Currently, filter are only applied on nested documents.
There are 3 facets: 1 on the root documents, 2 on the nested documents.

Result:
https://gist.github.com/2929312
The results and the first facet are ok, but the others facets aren't.
The "count" values are not what i expected: too high.
It counts the number of matching nested documents, instead of the number of
documents with matching nested documents.

Do you have a idea to solve my problem?

I found a solution, but it causes really bad performances...

I changed my mapping, and added "include_in_root" : true on nested documents
New mapping: https://gist.github.com/2929319
I also changed facets, the "nested" option is not
required: https://gist.github.com/2929321

Result:
https://gist.github.com/2929324
Facets counts are now ok,
but the execution time is awful: 8559ms!!!!!
And it takes a lot of memory.

The performance problem is bound to the "geo_distance" filter.
If I disable it, the execution time is ok.
But of course, this filter is essential for me :stuck_out_tongue:

I tried to enable the cache on the "geo_distance" filter, but it changes
nothing :frowning:

Can you help me?

Up? :smiley:

On Thursday, June 14, 2012 11:43:28 AM UTC+2, Pierre Durand wrote:

Hi!

I have a problem with facets on nested documents.

Here is my code (PHP):
https://gist.github.com/2929265
The populate() method creates the mapping and indexes documents.
The search method returns results.

My mapping:
https://gist.github.com/2929280
My PHP code creates 5000 players and 100-200 balls per player.

My query:
https://gist.github.com/2929285
The "and" filter is not really useful, but it allows to combine filters on
the root documents and the nested documents.
Currently, filter are only applied on nested documents.
There are 3 facets: 1 on the root documents, 2 on the nested documents.

Result:
https://gist.github.com/2929312
The results and the first facet are ok, but the others facets aren't.
The "count" values are not what i expected: too high.
It counts the number of matching nested documents, instead of the number
of documents with matching nested documents.

Do you have a idea to solve my problem?

I found a solution, but it causes really bad performances...

I changed my mapping, and added "include_in_root" : true on nested
documents
New mapping: https://gist.github.com/2929319
I also changed facets, the "nested" option is not required:
https://gist.github.com/2929321

Result:
https://gist.github.com/2929324
Facets counts are now ok,
but the execution time is awful: 8559ms!!!!!
And it takes a lot of memory.

The performance problem is bound to the "geo_distance" filter.
If I disable it, the execution time is ok.
But of course, this filter is essential for me :stuck_out_tongue:

I tried to enable the cache on the "geo_distance" filter, but it changes
nothing :frowning:

Can you help me?