I'd like to return a user-defined number of hits ordered by date (desc) and deduped.
If I don't dedupe, my query works fine. However, when I use the aggregator with top-hits subaggregation my resulting buckets are NOT a deduped version of my results hits. Can someone tell me what I'm doing wrong (or the best way to do this)?
SearchRequestBuilder srb = client.prepareSearch()
.setIndices("indexA")
.setScroll(new TimeValue(60000))
.setQuery(builder)
.addAggregation(AggregationBuilders.terms("docs")
.field("dedupId")
.subAggregation(AggregationBuilders
.topHits("top_hits")
.setSize(1)
.addSort("orderDTS",sortOrder.DESC)))
.addSort("orderDTS", SortOrder.DESC)
.setFrom(0)
.setSize(maxNumResults);