fixed aggregations according to text/keyword type
This commit is contained in:
parent
c8b5ca96d2
commit
35a57d3153
|
@ -53,22 +53,22 @@ public class EventStatsManager {
|
|||
|
||||
public List<BrowseEntry> browseTopics() {
|
||||
|
||||
final String term = "topic";
|
||||
final String term = "topic.keyword";
|
||||
|
||||
final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(QueryBuilders.matchAllQuery())
|
||||
.withSearchType(SearchType.DEFAULT)
|
||||
.addAggregation(AggregationBuilders.terms(term).field(term).size(1000).minDocCount(1))
|
||||
.build();
|
||||
.withQuery(QueryBuilders.matchAllQuery())
|
||||
.withSearchType(SearchType.DEFAULT)
|
||||
.addAggregation(AggregationBuilders.terms(term).field(term).size(1000).minDocCount(1))
|
||||
.build();
|
||||
|
||||
final SearchHits<Event> hits = esOperations.search(searchQuery, Event.class, IndexCoordinates.of(elasticSearchProperties.getEventsIndexName()));
|
||||
|
||||
final Aggregations aggregations = hits.getAggregations();
|
||||
|
||||
return ((ParsedStringTerms) aggregations.asMap().get(term)).getBuckets()
|
||||
.stream()
|
||||
.map(b -> new BrowseEntry(b.getKeyAsString(), b.getDocCount()))
|
||||
.collect(Collectors.toList());
|
||||
.stream()
|
||||
.map(b -> new BrowseEntry(b.getKeyAsString(), b.getDocCount()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -101,17 +101,19 @@ public class OpenaireBrokerController extends AbstractLbsController {
|
|||
@GetMapping("/topicsForDatasource")
|
||||
public List<BrowseEntry> findTopicsForDatasource(@RequestParam final String ds) {
|
||||
|
||||
final String term = "topic.keyword";
|
||||
|
||||
final NativeSearchQuery searchQuery = new NativeSearchQueryBuilder()
|
||||
.withQuery(QueryBuilders.nestedQuery("map", QueryBuilders.matchQuery("map.targetDatasourceName", ds), ScoreMode.None))
|
||||
.withSearchType(SearchType.DEFAULT)
|
||||
.addAggregation(AggregationBuilders.terms("topic").field("topic").size(1000).minDocCount(1))
|
||||
.addAggregation(AggregationBuilders.terms(term).field(term).size(1000).minDocCount(1))
|
||||
.build();
|
||||
|
||||
final SearchHits<Event> hits = esOperations.search(searchQuery, Event.class, IndexCoordinates.of(props.getEventsIndexName()));
|
||||
|
||||
final Aggregations aggregations = hits.getAggregations();
|
||||
|
||||
return ((ParsedStringTerms) aggregations.asMap().get("topic")).getBuckets()
|
||||
return ((ParsedStringTerms) aggregations.asMap().get(term)).getBuckets()
|
||||
.stream()
|
||||
.map(b -> new BrowseEntry(b.getKeyAsString(), b.getDocCount()))
|
||||
.collect(Collectors.toList());
|
||||
|
|
Loading…
Reference in New Issue