Hi,
I'm trying to run facet on nested objects but at the moment I'm not getting the results I'm after.
In the below query you can see the main query which is suppose to count the number of users which have at least one nested object(buying event) between 2013-10-01 and 2013-10-10 AND also have a TV as one of the products in that event.
On the facet side I'm looking to get the same result, only have it done by facet - that way I can get the counts for all products between the dates (not just TV), without running the main query for each of them (the way my system works now)
What I'm expecting to get is the same count for the main query ("total": 284070) and for the facet calculation (term": "TV","count": 535445) which is not the case at the moment.
I believe it's giving me the total count of nested objects(events) that match the condition, instead of the total unique users which I'm after.
Does anyone know what I'm doing wrong here?
*When setting the range on a single day, the results are the same as expected.
seems like when running on multiple day range, some users are counted more than once.
Thanks in advanced,
curl-XPOST'http: //XXXXX: 9200/sample/_search?pretty=true'-d'{
"size": 0,
"query": {
"nested": {
"query": {
"bool": {
"must": [{
"term": {
"events.products.product": "TV"
}
},
{
"range": {
"events.event_time": {
"from": "2013-10-01",
"to": "2013-10-10",
"include_lower": true,
"include_upper": true
}
}
}]
}
},
"path": "events"
}
},
"facets": {
"tags": {
"terms": {
"field": "product",
"size": 200
},
"nested": "events",
"facet_filter": {
"range": {
"events.event_time": {
"from": "2013-10-01",
"to": "2013-10-10",
"include_lower": true,
"include_upper": true
}
}
}
}
}
}'{
"took": 96,
"timed_out": false,
"_shards": {
"total": 20,
"successful": 20,
"failed": 0
},
"hits": {
"total": 284070,
"max_score": 4.171436,
"hits": []
},
"facets": {
"tags": {
"_type": "terms",
"missing": 0,
"total": 13036875,
"other": 1901080,
"terms": [{
"term": "TV",
"count": 535445
},
{
"term": "DISHWASHER",
"count": 375003
},
{
"term": "RADIO",
"count": 316831
},
.....
mapping:
{
"user": {
"_ttl": {
"enabled": true
},
"properties": {
"name": {
"type": "string"
},
"events": {
"type": "nested",
"properties": {
"event_time": {
"type": "Date"
},
"products": {
"properties": {
"product": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}
}