diff --git a/opensearch-search-quality-evaluation-plugin/scripts/run-query-set.sh b/opensearch-search-quality-evaluation-plugin/scripts/run-query-set.sh index f233a11..b14a138 100755 --- a/opensearch-search-quality-evaluation-plugin/scripts/run-query-set.sh +++ b/opensearch-search-quality-evaluation-plugin/scripts/run-query-set.sh @@ -7,7 +7,7 @@ ID_FIELD="asin" K="20" THRESHOLD="1.0" # Default value -curl -s -X DELETE "http://localhost:9200/search_quality_eval_query_sets_run_results" +curl -s -X DELETE "http://localhost:9200/search_quality_eval_query_sets_run_results,sqe_metrics_sample_data" # Keyword search curl -s -X POST "http://localhost:9200/_plugins/search_quality_eval/run?id=${QUERY_SET_ID}&judgments_id=${JUDGMENTS_ID}&index=${INDEX}&id_field=${ID_FIELD}&k=${K}" \ diff --git a/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/SearchQualityEvaluationPlugin.java b/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/SearchQualityEvaluationPlugin.java index eb7f2f7..45c7ba1 100644 --- a/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/SearchQualityEvaluationPlugin.java +++ b/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/SearchQualityEvaluationPlugin.java @@ -81,6 +81,11 @@ public class SearchQualityEvaluationPlugin extends Plugin implements ActionPlugi */ public static final String QUERY_SETS_RUN_RESULTS_INDEX_NAME = "search_quality_eval_query_sets_run_results"; + /** + * The name of the index that stores the metrics for the dashboard. + */ + public static final String DASHBOARD_METRICS_INDEX_NAME = "sqe_metrics_sample_data"; + /** * The name of the index that stores the implicit judgments. */ diff --git a/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/runners/AbstractQuerySetRunner.java b/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/runners/AbstractQuerySetRunner.java index 7c3fa75..6b9bea5 100644 --- a/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/runners/AbstractQuerySetRunner.java +++ b/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/runners/AbstractQuerySetRunner.java @@ -136,7 +136,7 @@ public Double getJudgmentValue(final String judgmentsId, final String query, fin final Map j = searchResponse.getHits().getAt(0).getSourceAsMap(); - LOGGER.info("Judgment contains a value: {}", j.get("judgment")); + // LOGGER.debug("Judgment contains a value: {}", j.get("judgment")); // TODO: Why does this not exist in some cases? if(j.containsKey("judgment")) { diff --git a/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/runners/OpenSearchQuerySetRunner.java b/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/runners/OpenSearchQuerySetRunner.java index f792943..94306f6 100644 --- a/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/runners/OpenSearchQuerySetRunner.java +++ b/opensearch-search-quality-evaluation-plugin/src/main/java/org/opensearch/eval/runners/OpenSearchQuerySetRunner.java @@ -10,6 +10,11 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.opensearch.action.admin.indices.create.CreateIndexRequest; +import org.opensearch.action.admin.indices.create.CreateIndexResponse; +import org.opensearch.action.admin.indices.exists.indices.IndicesExistsAction; +import org.opensearch.action.admin.indices.exists.indices.IndicesExistsRequest; +import org.opensearch.action.admin.indices.exists.indices.IndicesExistsResponse; import org.opensearch.action.bulk.BulkRequest; import org.opensearch.action.bulk.BulkResponse; import org.opensearch.action.index.IndexRequest; @@ -35,6 +40,7 @@ import java.util.Map; import java.util.UUID; +import static org.opensearch.eval.SearchQualityEvaluationPlugin.JUDGMENTS_INDEX_NAME; import static org.opensearch.eval.SearchQualityEvaluationRestHandler.QUERY_PLACEHOLDER; /** @@ -208,6 +214,58 @@ public void save(final QuerySetRunResult result) throws Exception { // See https://github.com/o19s/opensearch-search-quality-evaluation/blob/main/opensearch-dashboard-prototyping/METRICS_SCHEMA.md // See https://github.com/o19s/opensearch-search-quality-evaluation/blob/main/opensearch-dashboard-prototyping/sample_data.ndjson + final IndicesExistsRequest indicesExistsRequest = new IndicesExistsRequest(SearchQualityEvaluationPlugin.DASHBOARD_METRICS_INDEX_NAME); + + client.admin().indices().exists(indicesExistsRequest, new ActionListener<>() { + + @Override + public void onResponse(IndicesExistsResponse indicesExistsResponse) { + + if(!indicesExistsResponse.isExists()) { + + // Create the index. + // TODO: Read this mapping from a resource file instead. + final String mapping = "{\n" + + " \"properties\": {\n" + + " \"datetime\": { \"type\": \"date\", \"format\": \"basic_date_time\" },\n" + + " \"search_config\": { \"type\": \"keyword\" },\n" + + " \"query_set_id\": { \"type\": \"keyword\" },\n" + + " \"query\": { \"type\": \"keyword\" },\n" + + " \"metric\": { \"type\": \"keyword\" },\n" + + " \"value\": { \"type\": \"double\" },\n" + + " \"application\": { \"type\": \"keyword\" },\n" + + " \"evaluation_id\": { \"type\": \"keyword\" }\n" + + " }\n" + + " }"; + + // Create the judgments index. + final CreateIndexRequest createIndexRequest = new CreateIndexRequest(SearchQualityEvaluationPlugin.DASHBOARD_METRICS_INDEX_NAME).mapping(mapping); + + client.admin().indices().create(createIndexRequest, new ActionListener<>() { + + @Override + public void onResponse(CreateIndexResponse createIndexResponse) { + LOGGER.info("{} index created.", SearchQualityEvaluationPlugin.DASHBOARD_METRICS_INDEX_NAME); + } + + @Override + public void onFailure(Exception ex) { + LOGGER.error("Unable to create the {} index.", SearchQualityEvaluationPlugin.DASHBOARD_METRICS_INDEX_NAME, ex); + } + + }); + + } + + } + + @Override + public void onFailure(Exception ex) { + LOGGER.error("Unable to determine if {} index exists.", SearchQualityEvaluationPlugin.DASHBOARD_METRICS_INDEX_NAME, ex); + } + + }); + final BulkRequest bulkRequest = new BulkRequest(); final String timestamp = TimeUtils.getTimestamp();