Custom facet

Hi,

Do you have any idea how I could obtain from:

{"timestamp": "random_date", "tag":"red", "counter": "3"}
{"timestamp": "random_date", "tag":"blue", "counter": "2"}
{"timestamp": "random_date", "tag":"red", "counter":"7"}

a facet that would show:
tag: red
count: 10

tag: blue
count: 2

aka do the sum for the counter for each tag in only one request ?

Thank you,

Cristian

--

Never tried, but perhaps the terms stat facet using the counter field as
the value field? It will return too many stats, but one of them will be the
sum of all values.

Cheers,

Ivan

On Wed, Nov 14, 2012 at 6:10 AM, Cristian Toader ticosan@gmail.com wrote:

Hi,

Do you have any idea how I could obtain from:

{"timestamp": "random_date", "tag":"red", "counter": "3"}
{"timestamp": "random_date", "tag":"blue", "counter": "2"}
{"timestamp": "random_date", "tag":"red", "counter":"7"}

a facet that would show:
tag: red
count: 10

tag: blue
count: 2

aka do the sum for the counter for each tag in only one request ?

Thank you,

Cristian

--

--

Hi Cristi :slight_smile:

Yep, terms stats should do the trick:

But please note that the "counter" field needs to be numeric. If you
index it as a string it won't work:

Best regards,
Radu

http://sematext.com/ -- Elasticsearch -- Solr -- Lucene

On Wed, Nov 14, 2012 at 4:10 PM, Cristian Toader ticosan@gmail.com wrote:

Hi,

Do you have any idea how I could obtain from:

{"timestamp": "random_date", "tag":"red", "counter": "3"}
{"timestamp": "random_date", "tag":"blue", "counter": "2"}
{"timestamp": "random_date", "tag":"red", "counter":"7"}

a facet that would show:
tag: red
count: 10

tag: blue
count: 2

aka do the sum for the counter for each tag in only one request ?

Thank you,

Cristian

--

Thank you both for the answer :slight_smile:

I had to do some tweaking in the after code, since the facet results are
ordered by count and not by the stat I need. I'd which to be able to sort
such facet by any of its component stats ;).

Cristian

On Thursday, November 15, 2012 9:57:24 AM UTC+2, Radu Gheorghe wrote:

Hi Cristi :slight_smile:

Yep, terms stats should do the trick:
Elasticsearch terms facet · GitHub

But please note that the "counter" field needs to be numeric. If you
index it as a string it won't work:
Elasticsearch terms facet string · GitHub

Best regards,
Radu

http://sematext.com/ -- Elasticsearch -- Solr -- Lucene

On Wed, Nov 14, 2012 at 4:10 PM, Cristian Toader <tic...@gmail.com<javascript:>>
wrote:

Hi,

Do you have any idea how I could obtain from:

{"timestamp": "random_date", "tag":"red", "counter": "3"}
{"timestamp": "random_date", "tag":"blue", "counter": "2"}
{"timestamp": "random_date", "tag":"red", "counter":"7"}

a facet that would show:
tag: red
count: 10

tag: blue
count: 2

aka do the sum for the counter for each tag in only one request ?

Thank you,

Cristian

--