Filtering Aggs by most terms


(thinkmusic) #1

From a list of terms, I'm trying to find all the records that have those
terms in a specific field and aggregate on that field. As an example, I
have a list of records that contain a city name. I'd like the user to free
form type words (some of which would be the city name). Then I'd like to
see the top cities that have the most terms that match in them. This sort
of works but it seems to return all the records that have the most single
terms (lake) rather than the most terms that match. I do eventually get
"Mayfield Lake" but it can be far at the bottom since there is only a few
mayfields. Any suggestions on the best way to filter or only return records
that contain the most terms. Should this be part of the query? Can I sort
results in an Agg by relevance from the query?

"aggs": {
"cities": {
"filter": {
"bool": {
"should": [

[{"term":{"city":"mayfield"}},{"term":{"city":"lake"}},{"term":{"city":"capitol"}},{"term":{"city":"the"}}]
]
}
},
"aggs": {
"cities": {
"terms": {
"field": "cityState.raw"
}
}
}
},

example result:

aggregations: {

cities: {
- doc_count: 750
- -
cities: {
- -
buckets: [
- -
{
- key: "Moses Lake, WA"
- doc_count: 250
}
- -
{
- key: "Bonney Lake, WA"
- doc_count: 200
}
- -
....

--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/9ee290e0-9014-41a9-ae7d-fb8596616ca5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(system) #2