Term facet : Grouping of multiple field

This is my data in elasticsearch

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

I want to find number of times product added or removed per product_ID.

I have used term_facet for grouping by product_ID.

My query is

curl -XGET 'http://localhost:9200/logstash-2013.12.04/_search?pretty=true'
-d '{
"query" : {
"terms" :{"activity" : ["added","removed"]}
},
"facets" : {
"productID" : {
"terms" : {
"field" : "product_ID"
}
}
}
}'

But it shows combined count of added and removed like for *produc id 123 *it
shows count = 2.

I want like, for product id 123 it should show like *added = 2 *and removed
=0
.

Am I missing something in my facet query or some other query will work?

--
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/46534a7e-f519-4d04-bb5b-59961f5b0b96%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

If the structure is stored as nested type then you can do a nested query.

"query": {
"nested": {
"path": "your path",
"query": {
"bool": {
"must": [
{
"match": {
"your path.Action": {
"query": "added"
}
}
},
{
"match": {
"your path.Product_ID ": {
"query": "123"
}
}
}
]
}
}
}
}

Then do a facet on this

On Wednesday, 11 December 2013 15:38:10 UTC+5:30, abhi patel wrote:

This is my data in elasticsearch

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

I want to find number of times product added or removed per product_ID.

I have used term_facet for grouping by product_ID.

My query is

curl -XGET 'http://localhost:9200/logstash-2013.12.04/_search?pretty=true'
-d '{
"query" : {
"terms" :{"activity" : ["added","removed"]}
},
"facets" : {
"productID" : {
"terms" : {
"field" : "product_ID"
}
}
}
}'

But it shows combined count of added and removed like for *produc id 123 *it
shows count = 2.

I want like, for product id 123 it should show like *added = 2 *and removed
=0
.

Am I missing something in my facet query or some other query will work?

--
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/058be085-84f4-4abf-81b7-b8d4f082c1df%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Thanks paul. Can you just brief what is path means?

On Wednesday, December 11, 2013 4:00:02 PM UTC+5:30, paul wrote:

If the structure is stored as nested type then you can do a nested query.

"query": {
"nested": {
"path": "your path",
"query": {
"bool": {
"must": [
{
"match": {
"your path.Action": {
"query": "added"
}
}
},
{
"match": {
"your path.Product_ID ": {
"query": "123"
}
}
}
]
}
}
}
}

Then do a facet on this

On Wednesday, 11 December 2013 15:38:10 UTC+5:30, abhi patel wrote:

This is my data in elasticsearch

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

I want to find number of times product added or removed per product_ID.

I have used term_facet for grouping by product_ID.

My query is

curl -XGET 'http://localhost:9200/logstash-2013.12.04/_search?pretty=true'
-d '{
"query" : {
"terms" :{"activity" : ["added","removed"]}
},
"facets" : {
"productID" : {
"terms" : {
"field" : "product_ID"
}
}
}
}'

But it shows combined count of added and removed like for *produc id 123
*it shows count = 2.

I want like, for product id 123 it should show like *added = 2 *and removed
=0
.

Am I missing something in my facet query or some other query will work?

--
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/b4a46391-f465-41e9-9b24-389092567dd9%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

For the data below

{
"name":"ABC",
"results":[
{
"Action":"added",
"Product_ID":124
},
{
"Action":"added",
"Product_ID":123
},
{
"Action":"removed",
"Product_ID":123
},
{
"Action":"removed",
"Product_ID":124
}
]
}
path is results

On Wednesday, 11 December 2013 16:04:39 UTC+5:30, abhi patel wrote:

Thanks paul. Can you just brief what is path means?

On Wednesday, December 11, 2013 4:00:02 PM UTC+5:30, paul wrote:

If the structure is stored as nested type then you can do a nested query.

"query": {
"nested": {
"path": "your path",
"query": {
"bool": {
"must": [
{
"match": {
"your path.Action": {
"query": "added"
}
}
},
{
"match": {
"your path.Product_ID ": {
"query": "123"
}
}
}
]
}
}
}
}

Then do a facet on this

On Wednesday, 11 December 2013 15:38:10 UTC+5:30, abhi patel wrote:

This is my data in elasticsearch

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

I want to find number of times product added or removed per product_ID.

I have used term_facet for grouping by product_ID.

My query is

curl -XGET '
http://localhost:9200/logstash-2013.12.04/_search?pretty=true' -d '{
"query" : {
"terms" :{"activity" : ["added","removed"]}
},
"facets" : {
"productID" : {
"terms" : {
"field" : "product_ID"
}
}
}
}'

But it shows combined count of added and removed like for *produc id
123 *it shows count = 2.

I want like, for product id 123 it should show like *added = 2 *and removed
=0
.

Am I missing something in my facet query or some other query will work?

--
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/f4776c36-1d12-4889-9c2e-9f97c1554be6%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Got It.. Actually I have imported above data through logstash and mapping
is created automatically by logstash which is not nested type.
Any other way to get desired output?

On Wednesday, December 11, 2013 4:11:23 PM UTC+5:30, paul wrote:

For the data below

{
"name":"ABC",
"results":[
{
"Action":"added",
"Product_ID":124
},
{
"Action":"added",
"Product_ID":123
},
{
"Action":"removed",
"Product_ID":123
},
{
"Action":"removed",
"Product_ID":124
}
]
}
path is results

On Wednesday, 11 December 2013 16:04:39 UTC+5:30, abhi patel wrote:

Thanks paul. Can you just brief what is path means?

On Wednesday, December 11, 2013 4:00:02 PM UTC+5:30, paul wrote:

If the structure is stored as nested type then you can do a nested query.

"query": {
"nested": {
"path": "your path",
"query": {
"bool": {
"must": [
{
"match": {
"your path.Action": {
"query": "added"
}
}
},
{
"match": {
"your path.Product_ID ": {
"query": "123"
}
}
}
]
}
}
}
}

Then do a facet on this

On Wednesday, 11 December 2013 15:38:10 UTC+5:30, abhi patel wrote:

This is my data in elasticsearch

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

I want to find number of times product added or removed per product_ID.

I have used term_facet for grouping by product_ID.

My query is

curl -XGET '
http://localhost:9200/logstash-2013.12.04/_search?pretty=true' -d '{
"query" : {
"terms" :{"activity" : ["added","removed"]}
},
"facets" : {
"productID" : {
"terms" : {
"field" : "product_ID"
}
}
}
}'

But it shows combined count of added and removed like for *produc id
123 *it shows count = 2.

I want like, for product id 123 it should show like *added = 2 *and removed
=0
.

Am I missing something in my facet query or some other query will work?

--
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/2005be02-3c3f-4d1e-a79f-e67938f1190b%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

You may want to use Term Script Facets -

Vaidik Kapoor
vaidikkapoor.info

On 11 December 2013 16:24, abhi patel abhiage@gmail.com wrote:

Got It.. Actually I have imported above data through logstash and mapping
is created automatically by logstash which is not nested type.
Any other way to get desired output?

On Wednesday, December 11, 2013 4:11:23 PM UTC+5:30, paul wrote:

For the data below

{
"name":"ABC",
"results":[
{
"Action":"added",
"Product_ID":124
},
{
"Action":"added",
"Product_ID":123
},
{
"Action":"removed",
"Product_ID":123
},
{
"Action":"removed",
"Product_ID":124
}
]
}
path is results

On Wednesday, 11 December 2013 16:04:39 UTC+5:30, abhi patel wrote:

Thanks paul. Can you just brief what is path means?

On Wednesday, December 11, 2013 4:00:02 PM UTC+5:30, paul wrote:

If the structure is stored as nested type then you can do a nested
query.

"query": {
"nested": {
"path": "your path",
"query": {
"bool": {
"must": [
{
"match": {
"your path.Action": {
"query": "added"
}
}
},
{
"match": {
"your path.Product_ID ": {
"query": "123"
}
}
}
]
}
}
}
}

Then do a facet on this

On Wednesday, 11 December 2013 15:38:10 UTC+5:30, abhi patel wrote:

This is my data in elasticsearch

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

I want to find number of times product added or removed per product_ID.

I have used term_facet for grouping by product_ID.

My query is

curl -XGET 'http://localhost:9200/logstash-2013.12.04/_search?
pretty=true' -d '{
"query" : {
"terms" :{"activity" : ["added","removed"]}
},
"facets" : {
"productID" : {
"terms" : {
"field" : "product_ID"
}
}
}
}'

But it shows combined count of added and removed like for *produc id
123 *it shows count = 2.

I want like, for product id 123 it should show like *added = 2 *and
removed =0.

Am I missing something in my facet query or some other query will work?

--
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/2005be02-3c3f-4d1e-a79f-e67938f1190b%40googlegroups.com
.

For more options, visit https://groups.google.com/groups/opt_out.

--
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/CACWtv5%3D1Ohjsj6bBS6y6ZbUP-os_Cz7uzwLxPsZUGSZ-YpOh-w%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.