I am writing an Elasticsearch plugin, and in this plugin I need to retrieve the term frequency count from a specified in a certain field. At the moment I am using the query below, and reading the number of hits from the result:
SearchResponse searchResponse = nodeClient
.prepareSearch(INDEX_NAME)
.setQuery(QueryBuilders.termQuery(TERM_FIELD, term))
.get();
However, this needs to be done multiple times (10-20 times) and seems to be slow. Is there a way to use the Elasticsearch Java API and read data from the inverted indices directly?
In Lucene I used a function called totalTermFreq()
, which reads the total number of occurences the term has across all documents directly from the inverted indices. Lucene's documentation of the function can be found here