Problem with terms facet multi fields?


(Nick Chang) #1

Hello

Why does not like Mysql count(DISTINCT userId, prdId) ??

{
"facets": {
"book": {
"terms": {
"fields": [
"userId","prdId"
],
"size": 10,
"order": "count"
}
}
},
"size": 0
}

result :
"facets": {
"book": {
"_type": "terms",
"missing": 299410,
"total": 1765354,
"other": 1483806,
"terms": [
{
"term": "(Facebook)abc@gmail.com",
"count": 119710
},
{
"term": "guest",
"count": 76341
},
{
"term": "0100051552",
"count": 18563
},

Is't my misunderstanding?? or I lost other parameter??

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/529a0f7d-5b1a-4f5a-b76e-6fc7b920dcb6%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Binh Ly-2) #2

The terms facet will use a combo of term values from all the fields as if
it was a single field. What you want to do is probably a script that
combines userId and prodId, and then does a terms facet on the full combo.
Assuming that userId and prodId are full single tokens (i.e. for example
not_analyzed"), you can do something like this:

{
"facets": {
"user_prod": {
"terms": {
"script": "doc['userId'].value.toString() +
doc['prodId'].value.toString()"
}
}
}
}

And if you want the total distinct count, you will need to turn on
all_terms and then count the number of terms returned in the facet 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/18c32f65-00ed-4adf-bb8f-9d8c157b72a6%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(Nick Chang) #3

Thanks Binh

But, In elasticsearch, How to count the number of terms returned in the
facet array?

I found the doc. Not include facet array length function.

Do you have any suggest??

Thanks again.

Binh Ly於 2014年3月4日星期二UTC+8上午4時16分42秒寫道:

The terms facet will use a combo of term values from all the fields as if
it was a single field. What you want to do is probably a script that
combines userId and prodId, and then does a terms facet on the full combo.
Assuming that userId and prodId are full single tokens (i.e. for example
not_analyzed"), you can do something like this:

{
"facets": {
"user_prod": {
"terms": {
"script": "doc['userId'].value.toString() +
doc['prodId'].value.toString()"
}
}
}
}

And if you want the total distinct count, you will need to turn on
all_terms and then count the number of terms returned in the facet 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/d45217b7-e7cc-4153-8608-ab6f7b1ff9d1%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #4