Skip to content

Commit

Permalink
Creating the dashboard metrics index.
Browse files Browse the repository at this point in the history
  • Loading branch information
jzonthemtn committed Dec 11, 2024
1 parent 399efbb commit 7bae099
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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}" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public Double getJudgmentValue(final String judgmentsId, final String query, fin

final Map<String, Object> 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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 7bae099

Please sign in to comment.