Weird aggregations results

Hi,

We're trying to get statistics on our sells and are facing weird results
when using aggregations.

Here's an extract of our mapping:

{
"settings":{
"index":{
"analysis":{
"analyzer":{
"path-analyzer":{
"type":"custom",
"tokenizer":"path-tokenizer"
}
},
"tokenizer":{
"path-tokenizer":{
"type":"path_hierarchy"
}
}
}
}
},
"mappings":{
"order":{
"properties":{
"product":{
"type":"nested",
"properties":{
"id":{
"type":"integer"
},
"price":{
"type":"float"
},
"category":{
"type":"nested",
"properties":{
"path":{
"index_analyzer": "path-analyzer",
"search_analyzer": "keyword", "type":
"string"
}
}
}
}
}
}
}
}
}

This extract describe how our products and the categories they belong to
are stored in an order.

What we're trying to do is to get the best selling products by category.

We're able to sort by category and aggregate products:

{
"query":{
"bool":{
"must":[
[
{
"nested":{
"path":"product",
"filter":{
"nested":{
"path":"product.category",
"filter":{
"bool":{
"must":[
{
"prefix":{
"product.category.path":"livres/thriller"
}
}
]
}
}
}
}
}
}
]
]
}
},
"aggs":{
"produit":{
"nested":{
"path":"product"
},
"aggs":{
"product_id":{
"terms":{
"field":"product.id http://produit.id",
"size":0
},
"aggs":{
"number":{
"sum":{
"field":"product.price"
}
}
}
}
}
}
}
}

As shown in this result:

{
"aggregations":{
"product":{
"doc_count":400,
"product_id":{
"buckets":[
{
"key":430,
"doc_count":95,
"number":{
"value":1450.0
}
}
]
}
}
}
}

The problem is that when we change the category to "books", for example, we
logically find the product 430 but with different numbers:

{
"aggregations":{
"product":{
"doc_count":800,
"product_id":{
"buckets":[
{
"key":430,
"doc_count":100,
"number":{
"value":1500.0
}
}
]
}
}
}
}

The obvious answer would be that in some orders the product 430 is in
"books" but not in "books/thriller" but of course, we checked.

Having explained our situation, I only have one question: does anyone know
why we got these results?

Subsidiary question: we have trouble understanding how ES works and
especially how to debug our request, if you could explain us how you do it,
that would really be greatly appreciated around here. :slight_smile:

Thanks !

--
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/afe61727-8d2d-4f17-a787-b27459e0091e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.