Hi,
from your question it is not completely clear what exactly you want to
do. If you want to have the distinct action counts for a specific
product, then you can use the simple faceting approach:
"facets": {
"actions": {
"terms": {
"field": "Action",
"size": 10
},
"facet_filter": {
"term": {
"Product_ID": "123"
}
}
}
}
This gives a result like this:
"facets": {
"actions": {
"_type": "terms",
"missing": 0,
"total": 3,
"other": 0,
"terms": [
{
"term": "added",
"count": 2
},
{
"term": "purchased",
"count": 1
}
]
}
}
But if you want to get the distinct action counts for all different
products in your index at once, you can use a new feature called
aggregations. For this to work you have to use ES 1.0, which is still
beta. I tested the following search request with ES 1.0.0.beta2:
"aggregations": {
"productIds": {
"terms": {
"field": "Product_ID"
},
"aggregations": {
"actions": {
"terms": {
"field": "Action"
}
}
}
}
}
Which produces this:
"aggregations": {
"productIds": {
"buckets": [
{
"key": 123,
"doc_count": 3,
"actions": {
"buckets": [
{
"key": "added",
"doc_count": 2
},
{
"key": "purchased",
"doc_count": 1
}
]
}
},
{
"key": 124,
"doc_count": 2,
"actions": {
"buckets": [
{
"key": "removed",
"doc_count": 1
},
{
"key": "added",
"doc_count": 1
}
]
}
}
]
}
}
Hope, that helps! Good luck!
Hannes
On 13.12.2013 07:45, abhi patel wrote:
data is
Action : "added" Product_ID : 123
Action : "added" Product_ID : 124
Action : "removed" Product_ID : 124
Action : "purchased" Product_ID : 123
Action : "added" Product_ID : 123
How can i achieve below sort of output using facet query or any other
elasticsearch query?
term : 123
{
added : 2 times(count num. of times 123 product is added)
removed : 0 times
}
--
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/52AB003D.9050709%40hkorte.com.
For more options, visit https://groups.google.com/groups/opt_out.