From f3fcf442f646618e0bd3ed7299825192b69e9301 Mon Sep 17 00:00:00 2001 From: jzonthemtn Date: Tue, 10 Dec 2024 09:49:08 -0500 Subject: [PATCH] Changing rank agg clickthrough size to 0 because we don't care about the documents. --- .../eval/SearchQualityEvaluationRestHandler.java | 2 +- .../judgments/clickmodel/coec/CoecClickModel.java | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/SearchQualityEvaluationRestHandler.java b/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/SearchQualityEvaluationRestHandler.java index d8d66b7..20bacd4 100644 --- a/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/SearchQualityEvaluationRestHandler.java +++ b/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/SearchQualityEvaluationRestHandler.java @@ -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" + " }"; diff --git a/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/judgments/clickmodel/coec/CoecClickModel.java b/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/judgments/clickmodel/coec/CoecClickModel.java index 94ff62b..d39f37b 100644 --- a/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/judgments/clickmodel/coec/CoecClickModel.java +++ b/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/judgments/clickmodel/coec/CoecClickModel.java @@ -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; @@ -290,14 +291,17 @@ public Map 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(); @@ -308,6 +312,9 @@ public Map getRankAggregatedClickThrough() throws Exception { final Terms actionTerms = searchResponse.getAggregations().get("By_Action"); final Collection actionBuckets = actionTerms.getBuckets(); + LOGGER.info("search:"); + LOGGER.info(searchSourceBuilder.toString()); + for(final Terms.Bucket actionBucket : actionBuckets) { // Handle the "click" bucket.