Termstats facet for multiple string fields

Hi,

I got termsstats facet code working in Java for a single non-numeric
key field. The way I did this is I introduced a new numeric field
called "counter" that always has a value 1. Here is an example of curl
version of my code:

"query" : {
	"match_all": {}
 },
"facets" : {
	"facet1" : {
		"terms_stats" : {
			"key_field" : "field1",
			"value_field" : "counter"
		}
	}
}

How do I specify more than one key field? Does ES support this
feature today, or it is currently under development?

Thank you,
Eugene.

Regarding the count, you can simply use a value script that is simply "1".

Regarding the terms stats on multiple key fields, you can simply have several terms stats facets, each on different field. Or are you looking for something different?
On Thursday, March 24, 2011 at 12:59 AM, eugene wrote:

Hi,

I got termsstats facet code working in Java for a single non-numeric
key field. The way I did this is I introduced a new numeric field
called "counter" that always has a value 1. Here is an example of curl
version of my code:

"query" : {
"match_all": {}
},
"facets" : {
"facet1" : {
"terms_stats" : {
"key_field" : "field1",
"value_field" : "counter"
}
}
}

How do I specify more than one key field? Does ES support this
feature today, or it is currently under development?

Thank you,
Eugene.

Wait, now I am a bit confused :), why use term stats to get how many times a term occurs, you can just use the terms facet, no?
On Thursday, March 24, 2011 at 1:05 AM, Shay Banon wrote:

Regarding the count, you can simply use a value script that is simply "1".

Regarding the terms stats on multiple key fields, you can simply have several terms stats facets, each on different field. Or are you looking for something different?
On Thursday, March 24, 2011 at 12:59 AM, eugene wrote:

Hi,

I got termsstats facet code working in Java for a single non-numeric
key field. The way I did this is I introduced a new numeric field
called "counter" that always has a value 1. Here is an example of curl
version of my code:

"query" : {
"match_all": {}
},
"facets" : {
"facet1" : {
"terms_stats" : {
"key_field" : "field1",
"value_field" : "counter"
}
}
}

How do I specify more than one key field? Does ES support this
feature today, or it is currently under development?

Thank you,
Eugene.

I am looking for grouping fields, equivalent to sql query "select
field1, field2, sum(counter) from my_table group by field1, field2",
which implies that I need to have 2 key fields under the same facet.

On Mar 23, 4:05 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Regarding the count, you can simply use a value script that is simply "1".

Regarding the terms stats on multiple key fields, you can simply have several terms stats facets, each on different field. Or are you looking for something different?

On Thursday, March 24, 2011 at 12:59 AM, eugene wrote:

Hi,

I got termsstats facet code working in Java for a single non-numeric
key field. The way I did this is I introduced a new numeric field
called "counter" that always has a value 1. Here is an example of curl
version of my code:

"query" : {
"match_all": {}
},
"facets" : {
"facet1" : {
"terms_stats" : {
"key_field" : "field1",
"value_field" : "counter"
}
}
}

How do I specify more than one key field? Does ES support this
feature today, or it is currently under development?

Thank you,
Eugene.- Hide quoted text -

  • Show quoted text -

So, you want to get counts for tuples of field1 and field2? You can do that using terms stats and script field, by creating a script that combined the two: doc['field1'].value + "_" + doc['field2'].value. Not amazing in terms of perf because of the string generation, but, might be good for you.
On Thursday, March 24, 2011 at 1:08 AM, eugene wrote:

I am looking for grouping fields, equivalent to sql query "select
field1, field2, sum(counter) from my_table group by field1, field2",
which implies that I need to have 2 key fields under the same facet.

On Mar 23, 4:05 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Regarding the count, you can simply use a value script that is simply "1".

Regarding the terms stats on multiple key fields, you can simply have several terms stats facets, each on different field. Or are you looking for something different?

On Thursday, March 24, 2011 at 12:59 AM, eugene wrote:

Hi,

I got termsstats facet code working in Java for a single non-numeric
key field. The way I did this is I introduced a new numeric field
called "counter" that always has a value 1. Here is an example of curl
version of my code:

"query" : {
"match_all": {}
},
"facets" : {
"facet1" : {
"terms_stats" : {
"key_field" : "field1",
"value_field" : "counter"
}
}
}

How do I specify more than one key field? Does ES support this
feature today, or it is currently under development?

Thank you,
Eugene.- Hide quoted text -

  • Show quoted text -

Does that mean I should create a new script_field, and then use it as
a key_field in the terms_stats facet?

On Mar 23, 4:26 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

So, you want to get counts for tuples of field1 and field2? You can do that using terms stats and script field, by creating a script that combined the two: doc['field1'].value + "_" + doc['field2'].value. Not amazing in terms of perf because of the string generation, but, might be good for you.

On Thursday, March 24, 2011 at 1:08 AM, eugene wrote:

I am looking for grouping fields, equivalent to sql query "select
field1, field2, sum(counter) from my_table group by field1, field2",
which implies that I need to have 2 key fields under the same facet.

On Mar 23, 4:05 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Regarding the count, you can simply use a value script that is simply "1".

Regarding the terms stats on multiple key fields, you can simply have several terms stats facets, each on different field. Or are you looking for something different?

On Thursday, March 24, 2011 at 12:59 AM, eugene wrote:

Hi,

I got termsstats facet code working in Java for a single non-numeric
key field. The way I did this is I introduced a new numeric field
called "counter" that always has a value 1. Here is an example of curl
version of my code:

"query" : {
"match_all": {}
},
"facets" : {
"facet1" : {
"terms_stats" : {
"key_field" : "field1",
"value_field" : "counter"
}
}
}

How do I specify more than one key field? Does ES support this
feature today, or it is currently under development?

Thank you,
Eugene.- Hide quoted text -

  • Show quoted text -- Hide quoted text -
  • Show quoted text -