Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Elasticsearch Aggregation search : how to avoid search hits I don't need ?
Dear all,
First of all, Happy New Year to everyone ! It can be the 31st of December, still we need to move forward on some projects...
I am currently trying to use aggregate using Search API and have successfully written the following code.
The above works perfectly. However, from an optimization perspective, I am looking for a solution where hits are not returned as I don't need them. From ElasticSearch, they say that it avoids the fetch phase (and then improve performance): https://www.elastic.co/guide/en/elasticsearch/reference/6.7/returning-only-agg-results.html
But when I set
Does anyone has a solution ?
Thank you,
First of all, Happy New Year to everyone ! It can be the 31st of December, still we need to move forward on some projects...
I am currently trying to use aggregate using Search API and have successfully written the following code.
SearchRequestBuilder searchRequestBuilder = searchRequestBuilderFactory.builder();
DateHistogramAggregation dateHistogramAggregation= _aggregations.dateHistogram("createDate", "createDate");
dateHistogramAggregation.setDateHistogramInterval("15m");
searchRequestBuilder = searchRequestBuilder.addAggregation(dateHistogramAggregation);
searchRequestBuilder = searchRequestBuilder.modelIndexerClasses(MyModel.class);
searchRequestBuilder = searchRequestBuilder.size(1);
searchRequestBuilder = searchRequestBuilder.withSearchContext(searchContext -> searchContext.setCompanyId(serviceContext.getCompanyId()));
SearchResponse searchResponse = searcher.search(searchRequestBuilder.build());
The above works perfectly. However, from an optimization perspective, I am looking for a solution where hits are not returned as I don't need them. From ElasticSearch, they say that it avoids the fetch phase (and then improve performance): https://www.elastic.co/guide/en/elasticsearch/reference/6.7/returning-only-agg-results.html
But when I set
.size(0)
I can't retrieve the results from the SearchResponse
object: I get a nullPointerException.Does anyone has a solution ?
Thank you,
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™