How we implemented Group By in ES


(Sumit Guptaa) #1

Hi All,

I have the following document like:

"document_id" : "abcdef"
"domain" : "sumitgupta.org"
"url" : "http://www.sumitgupta.org/"
"document_title" : "sumitgupta - -tring to implement sql group by"
"document_text" : "Hello guys how r you"

When searching, I would like to display the results and group the results by domain. So i'm trying to be fair and show 10 different domains in the result rather than showing 10 results from the same domain.

In SQL I could achieve this using the following query:
SELECT * FROM table WHERE document_title LIKE '%sumitgupta%' GROUP BY domain

How could I get a similar GROUP BY results with elasticsearch.

Regards,
Sumit Gupta


(David Pilato) #2

When you Group by in SQL, you count values by type.
You can use Terms Facet to get the same kind of result.

For your use case, you will have to modify the default analyzer for domain field.

HTH

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

Le 25 sept. 2012 à 07:18, Sumit Guptaa sumit.gupta.ngi@gmail.com a écrit :

Hi All,

I have the following document like:

"document_id" : "abcdef"
"domain" : "sumitgupta.org"
"url" : "http://www.sumitgupta.org/"
"document_title" : "sumitgupta - -tring to implement sql group by"
"document_text" : "Hello guys how r you"

When searching, I would like to display the results and group the results by
domain. So i'm trying to be fair and show 10 different domains in the result
rather than showing 10 results from the same domain.

In SQL I could achieve this using the following query:
SELECT * FROM table WHERE document_title LIKE '%sumitgupta%' GROUP BY domain

How could I get a similar GROUP BY results with elasticsearch.

Regards,
Sumit Gupta

--
View this message in context: http://elasticsearch-users.115913.n3.nabble.com/How-we-implemented-Group-By-in-ES-tp4023084.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.

--

--


(system) #3