3

I'm trying to work out a way of finding the most popular terms and their usage in ElasticSearch. The Terms Aggregation is very close but returns the count of documents that the term appeared in, rather than how many times the term appeared.

For example, imagine an appropriate index has been created to index these example documents:

{ text: 'one two two' }
{ text: 'two three' }

Then executing the following search:

{
    aggregations: {
        popular_terms: {
            terms: {
                field: 'text'
            }
        }
    }
}

Will return:

... {
    buckets: [
        { key: 'two', value: 2 },
        { key: 'one', value: 1 },
        { key: 'three', value: 1 }
    ]
}

Is it possible to search with an aggregation counting instances of the terms in a similar way? So in this example returning 3 for the value 'two' as it appears twice in the first document?

David Padbury
  • 1,142
  • 7
  • 22

1 Answers1

1

Aggregation counts the number of documents based on a criteria (eg: terms ). So it won't return what you are expecting.

For your use case you can probably use the term vector

Prabin Meitei
  • 1,920
  • 1
  • 13
  • 16