Can we do statistical facets on groups in a single query?

Hi all,

I have say five fields A,B,C,D and E. I am able to do statistical facet
(min,max,sum,mean) over field E over records satisfying some conditions in
where clause.

Now I have A as the country and I want to group the records (say country
A1, A2, A3 and so on) and apply statistical facets on field E over those
groups using a single query.

Is it possible to do this? If yes how ?

Please help. Thanks in advance for your help.

Regards,
Rakesh Kumar Rakshit

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

Hey,

Check out the script field for the statistical facet, that might help you

--Alex

On Thu, Nov 21, 2013 at 9:10 AM, rakesh rakshit <ihavethepotential@gmail.com

wrote:

Hi all,

I have say five fields A,B,C,D and E. I am able to do statistical facet
(min,max,sum,mean) over field E over records satisfying some conditions in
where clause.

Now I have A as the country and I want to group the records (say country
A1, A2, A3 and so on) and apply statistical facets on field E over those
groups using a single query.

Is it possible to do this? If yes how ?

Please help. Thanks in advance for your help.

Regards,
Rakesh Kumar Rakshit

--
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.
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.
For more options, visit https://groups.google.com/groups/opt_out.

Check out terms stat fact

Thanks,
Ram

On Thursday, November 21, 2013 3:05:21 PM UTC+5:30, Alexander Reelsen wrote:

Hey,

Check out the script field for the statistical facet, that might help you

Elasticsearch Platform — Find real-time answers at scale | Elastic

--Alex

On Thu, Nov 21, 2013 at 9:10 AM, rakesh rakshit <ihavethe...@gmail.com<javascript:>

wrote:

Hi all,

I have say five fields A,B,C,D and E. I am able to do statistical facet
(min,max,sum,mean) over field E over records satisfying some conditions in
where clause.

Now I have A as the country and I want to group the records (say country
A1, A2, A3 and so on) and apply statistical facets on field E over those
groups using a single query.

Is it possible to do this? If yes how ?

Please help. Thanks in advance for your help.

Regards,
Rakesh Kumar Rakshit

--
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 elasticsearc...@googlegroups.com <javascript:>.
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.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Alex,

Thanks for the reply. I went through script field and found it is required
to do statistical computation involving a numeric value derived from the
script you will write. I cannot find if it allows you apply facets in
subsets/groups.

For example, consider the following data:

{"country" : "1", "population":"100"}
{"country" : "1", "population":"200"}
{"country" : "2", "population":"100"}
{"country" : "2", "population":"200"}
{"country" : "1", "population":"500"}

I want to compute total population groupby country. So the expected results
will be :

{"country" : "1", "total":"800"},{"country" : "2", "total":"300"}

Please let me know if you feel this can be done by script field in ES.

Thanks,
Rakesh

On Thursday, November 21, 2013 3:05:21 PM UTC+5:30, Alexander Reelsen wrote:

Hey,

Check out the script field for the statistical facet, that might help you

Elasticsearch Platform — Find real-time answers at scale | Elastic

--Alex

On Thu, Nov 21, 2013 at 9:10 AM, rakesh rakshit <ihavethe...@gmail.com<javascript:>

wrote:

Hi all,

I have say five fields A,B,C,D and E. I am able to do statistical facet
(min,max,sum,mean) over field E over records satisfying some conditions in
where clause.

Now I have A as the country and I want to group the records (say country
A1, A2, A3 and so on) and apply statistical facets on field E over those
groups using a single query.

Is it possible to do this? If yes how ?

Please help. Thanks in advance for your help.

Regards,
Rakesh Kumar Rakshit

--
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 elasticsearc...@googlegroups.com <javascript:>.
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.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Rakesh,

you can use the terms stats facet for this:

{
"facets": {
"countryPopulation": {
"terms_stats": {
"key_field": "country",
"value_field": "population"
}
}
}
}

This will give you the following:

"terms": [
{
"term": "1",
"count": 3,
"total_count": 3,
"min": 100,
"max": 500,
"total": 800,
"mean": 266.6666666666667
},
{
"term": "2",
"count": 2,
"total_count": 2,
"min": 100,
"max": 200,
"total": 300,
"mean": 150
}
]

Best regards
Hannes

On 21.11.2013 14:28, rakesh rakshit wrote:

Hi Alex,

Thanks for the reply. I went through script field and found it is required
to do statistical computation involving a numeric value derived from the
script you will write. I cannot find if it allows you apply facets in
subsets/groups.

For example, consider the following data:

{"country" : "1", "population":"100"}
{"country" : "1", "population":"200"}
{"country" : "2", "population":"100"}
{"country" : "2", "population":"200"}
{"country" : "1", "population":"500"}

I want to compute total population groupby country. So the expected results
will be :

{"country" : "1", "total":"800"},{"country" : "2", "total":"300"}

Please let me know if you feel this can be done by script field in ES.

Thanks,
Rakesh

On Thursday, November 21, 2013 3:05:21 PM UTC+5:30, Alexander Reelsen wrote:

Hey,

Check out the script field for the statistical facet, that might help you

Elasticsearch Platform — Find real-time answers at scale | Elastic

--Alex

On Thu, Nov 21, 2013 at 9:10 AM, rakesh rakshit <ihavethe...@gmail.com<javascript:>

wrote:

Hi all,

I have say five fields A,B,C,D and E. I am able to do statistical facet
(min,max,sum,mean) over field E over records satisfying some conditions in
where clause.

Now I have A as the country and I want to group the records (say country
A1, A2, A3 and so on) and apply statistical facets on field E over those
groups using a single query.

Is it possible to do this? If yes how ?

Please help. Thanks in advance for your help.

Regards,
Rakesh Kumar Rakshit

--
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 elasticsearc...@googlegroups.com <javascript:>.
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.
For more options, visit https://groups.google.com/groups/opt_out.