How to count?

Hello

I want to analysis " who read the how many books?"

When bookid is duplicate, I don't want to count.

POST /bookdatas/_search
{
"size": 0,
"facets": {
"ips_stats": {
"terms_stats": {
"key_field": "userId",
"value_field": "duration",
"size": 5
},
"facet_filter": {
"fquery": {
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"query_string": {
"query": ""(Google)bbb@gmail.com""
}
}
]
}
}
}
}
}
}
}
}
}

result
"facets": {
"ips_stats": {
"_type": "terms_stats",
"missing": 0,
"terms": [
{
"term": "(Google)bbb@gmail.com",
"count": 64,
"total_count": 3,
"min": 2,
"max": 139436,
"total": 140733,
"mean": 46911
},

userId prdId duration chapId(Google)bbb@gmail.com010020244421
(Google)bbb@gmail.com01002024441394361(Google)bbb@gmail.com010020244412951
A user only read a book, but count is three.

Can you give me a suggestion??

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/6e865a48-54ad-4f95-aa60-732598d35de8%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

I mean like mysql query

select count( distinct id ) from tablename;

Thanks

Nick Chang於 2014年2月27日星期四UTC+8下午2時51分39秒寫道:

Hello

I want to analysis " who read the how many books?"

When bookid is duplicate, I don't want to count.

POST /bookdatas/_search
{
"size": 0,
"facets": {
"ips_stats": {
"terms_stats": {
"key_field": "userId",
"value_field": "duration",
"size": 5
},
"facet_filter": {
"fquery": {
"query": {
"filtered": {
"query": {
"bool": {
"should": [
{
"query_string": {
"query": ""(Google)bbb@gmail.com""
}
}
]
}
}
}
}
}
}
}
}
}

result
"facets": {
"ips_stats": {
"_type": "terms_stats",
"missing": 0,
"terms": [
{
"term": "(Google)bbb@gmail.com",
"count": 64,
"total_count": 3,
"min": 2,
"max": 139436,
"total": 140733,
"mean": 46911
},

userId prdId duration chapId(Google)bbb@gmail.com010020244421(Google)
bbb@gmail.com01002024441394361(Google)bbb@gmail.com010020244412951
A user only read a book, but count is three.

Can you give me a suggestion??

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/8accddc1-9c11-459b-b384-f2b430af39ac%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Field collapsing is coming in a future version of ES. For now, you can use
a terms facet and the all_terms option:

{
"query" : {
"match_all" : { }
},
"facets" : {
"tag" : {
"terms" : {
"field" : "distinctid",
"all_terms" : true
}
}
}
}

And then in the result, just count the total number of entries in the terms
array.

--
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/7aafecc3-2f7f-4537-a5c2-c7fd38c4b2b6%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hello Binh

Thanks.

It's my query

{
"query" : {
"bool": {
"must": [
{"query_string": {
"query": ""(Google)bbb@gmail.com""
}}
],
"must": [
{"query_string": {
"query": "ReadingLog.ChapLog"
}}
]
}
},
"facets" : {
"tag" : {
"terms" : {
"field" : "prdId",
"all_terms" : true
}
}
},
"size": 0
}

But result
"facets": {
"tag": {
"_type": "terms",
"missing": 0,
"total": 3,
"other": 0,
"terms": [
{
"term": "0100202444",
"count": 3

Not count:1.
Maybe I lose some pattern, Do you have any suggest??

Thanks

Binh Ly於 2014年2月27日星期四UTC+8下午8時58分51秒寫道:

Field collapsing is coming in a future version of ES. For now, you can use
a terms facet and the all_terms option:

{
"query" : {
"match_all" : { }
},
"facets" : {
"tag" : {
"terms" : {
"field" : "distinctid",
"all_terms" : true
}
}
}
}

And then in the result, just count the total number of entries in the
terms array.

--
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/e115cc35-260a-4db2-819a-ee239d1a2c6e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Your distinct count should be the size of the terms array:

facets.tag.terms.length

--
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/878d7653-591e-47a6-ac74-f3f6b4e92067%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.