Skip to content

Commit

Permalink
Changing rank agg clickthrough size to 0 because we don't care about …
Browse files Browse the repository at this point in the history
…the documents.
  • Loading branch information
jzonthemtn committed Dec 10, 2024
1 parent 2a15ba9 commit f3fcf44
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ public void onResponse(final IndicesExistsResponse indicesExistsResponse) {
" \"query_id\": { \"type\": \"keyword\" },\n" +
" \"query\": { \"type\": \"keyword\" },\n" +
" \"document_id\": { \"type\": \"keyword\" },\n" +
" \"judgment\": { \"type\": \"double\" }\n" +
" \"judgment\": { \"type\": \"double\" },\n" +
" \"timestamp\": { \"type\": \"date\", \"format\": \"basic_date_time\" }\n" +
" }\n" +
" }";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.opensearch.search.Scroll;
import org.opensearch.search.SearchHit;
import org.opensearch.search.aggregations.AggregationBuilders;
import org.opensearch.search.aggregations.BucketOrder;
import org.opensearch.search.aggregations.bucket.terms.Terms;
import org.opensearch.search.aggregations.bucket.terms.TermsAggregationBuilder;
import org.opensearch.search.builder.SearchSourceBuilder;
Expand Down Expand Up @@ -290,14 +291,17 @@ public Map<Integer, Double> getRankAggregatedClickThrough() throws Exception {
final QueryBuilder findRangeNumber = QueryBuilders.rangeQuery("event_attributes.position.ordinal").lte(parameters.getMaxRank());
final QueryBuilder queryBuilder = new BoolQueryBuilder().must(findRangeNumber);

final TermsAggregationBuilder positionsAggregator = AggregationBuilders.terms("By_Position").field("event_attributes.position.ordinal").size(parameters.getMaxRank());
final TermsAggregationBuilder actionNameAggregation = AggregationBuilders.terms("By_Action").field("action_name").subAggregation(positionsAggregator).size(parameters.getMaxRank());
// Order the aggregations by _id and not by value.
final BucketOrder bucketOrder = BucketOrder.key(true);

final TermsAggregationBuilder positionsAggregator = AggregationBuilders.terms("By_Position").field("event_attributes.position.ordinal").order(bucketOrder).size(parameters.getMaxRank());
final TermsAggregationBuilder actionNameAggregation = AggregationBuilders.terms("By_Action").field("action_name").subAggregation(positionsAggregator).order(bucketOrder).size(parameters.getMaxRank());

final SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(queryBuilder);
searchSourceBuilder.aggregation(actionNameAggregation);
searchSourceBuilder.from(0);
searchSourceBuilder.size(100);
searchSourceBuilder.size(0);

final SearchRequest searchRequest = new SearchRequest(SearchQualityEvaluationPlugin.UBI_EVENTS_INDEX_NAME).source(searchSourceBuilder);
final SearchResponse searchResponse = client.search(searchRequest).get();
Expand All @@ -308,6 +312,9 @@ public Map<Integer, Double> getRankAggregatedClickThrough() throws Exception {
final Terms actionTerms = searchResponse.getAggregations().get("By_Action");
final Collection<? extends Terms.Bucket> actionBuckets = actionTerms.getBuckets();

LOGGER.info("search:");
LOGGER.info(searchSourceBuilder.toString());

for(final Terms.Bucket actionBucket : actionBuckets) {

// Handle the "click" bucket.
Expand Down

0 comments on commit f3fcf44

Please sign in to comment.