Skip to content

Commit

Permalink
Address comment from Peng
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chu <[email protected]>
  • Loading branch information
noCharger committed Feb 20, 2024
1 parent efda5f2 commit 0b56cf9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.opensearch.flint.core.metrics.MetricConstants.REQUEST_METADATA_READ_METRIC_PREFIX;

/**
* {@link OpenSearchReader} using search. https://opensearch.org/docs/latest/api-reference/search/
*/
Expand All @@ -37,10 +39,18 @@ public OpenSearchQueryReader(IRestHighLevelClient client, String indexName, Sear
/**
* search.
*/
Optional<SearchResponse> search(SearchRequest request) throws IOException {
return Optional.of(client.search(request, RequestOptions.DEFAULT));
Optional<SearchResponse> search(SearchRequest request) {
Optional<SearchResponse> response = Optional.empty();
try {
response = Optional.of(client.search(request, RequestOptions.DEFAULT));
IRestHighLevelClient.recordOperationSuccess(REQUEST_METADATA_READ_METRIC_PREFIX);
} catch (Exception e) {
IRestHighLevelClient.recordOperationFailure(REQUEST_METADATA_READ_METRIC_PREFIX, e);
}
return response;
}


/**
* nothing to clean
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import java.util.List;
import java.util.Optional;

import static org.opensearch.flint.core.metrics.MetricConstants.REQUEST_METADATA_READ_METRIC_PREFIX;

/**
* Abstract OpenSearch Reader.
*/
Expand All @@ -43,7 +41,6 @@ public OpenSearchReader(IRestHighLevelClient client, SearchRequest searchRequest
try {
if (iterator == null || !iterator.hasNext()) {
Optional<SearchResponse> response = search(searchRequest);
IRestHighLevelClient.recordOperationSuccess(REQUEST_METADATA_READ_METRIC_PREFIX);
if (response.isEmpty()) {
iterator = null;
return false;
Expand All @@ -53,7 +50,6 @@ public OpenSearchReader(IRestHighLevelClient client, SearchRequest searchRequest
}
return iterator.hasNext();
} catch (OpenSearchStatusException e) {
IRestHighLevelClient.recordOperationFailure(REQUEST_METADATA_READ_METRIC_PREFIX, e);
// e.g., org.opensearch.OpenSearchStatusException: OpenSearch exception [type=index_not_found_exception, reason=no such index [query_results2]]
if (e.getMessage() != null && (e.getMessage().contains("index_not_found_exception"))) {
return false;
Expand Down

0 comments on commit 0b56cf9

Please sign in to comment.