How can I get the results of a terms facet bucketed into ranges by the counts?


(Mike) #1

Assume I have a couple books like this:

{ title:"One", author: "John" }
{ title:"Two", author: "John" }
{ title:"Three", author: "Alex" }
{ title:"Four", author: "Alex" }
{ title:"Five", author: "Mike" }
{ title:"Six", author: "Mike" }
{ title:"Seven", author: "Mike" }
{ title:"Eight", author: "Dave" }

How can I get a grouping of authors by the number of books they wrote?

I can make a terms facet on author to get the top 4 most published authors
and get:
Mike : 3
John : 2
Alex : 2
Dave : 1

But what if I want something like this:
Written 6+ books : 0
Written 2-5 books : 3
Written 1 book : 1

--


(Nick Dunn) #2

As far as I know "group by" isn't supported. I think you'd need to convert your facet result to your desired range output in your own application logic.

--


(Sawyer Zhu) #3

You can use TermFacet to do this.

--


(David Pilato) #4

IMHO you are doing a count on Authors (books per author). You have to index Authors (and their books if needed).

Then, you can apply a RangeFacet on Authors.

My 2 cents.

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 24 août 2012 à 19:48, Mike mnilsson2323@gmail.com a écrit :

Assume I have a couple books like this:

{ title:"One", author: "John" }
{ title:"Two", author: "John" }
{ title:"Three", author: "Alex" }
{ title:"Four", author: "Alex" }
{ title:"Five", author: "Mike" }
{ title:"Six", author: "Mike" }
{ title:"Seven", author: "Mike" }
{ title:"Eight", author: "Dave" }

How can I get a grouping of authors by the number of books they wrote?

I can make a terms facet on author to get the top 4 most published authors and get:
Mike : 3
John : 2
Alex : 2
Dave : 1

But what if I want something like this:
Written 6+ books : 0
Written 2-5 books : 3
Written 1 book : 1

--

--


(system) #5