How can i achieve this result using facet?

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/12d36c7e-cf36-4419-af04-b1b8b2b8aba9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

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.

Thanks you Hannes. It resolved my issue.

On Friday, December 13, 2013 6:10:29 PM UTC+5:30, Hannes Korte wrote:

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/f084e8d5-5f26-4af2-9aaf-69a55a1ec768%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.