From 9c5977fe9736ab3b73765534aad37c721f94d355 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 1 Sep 2023 13:13:46 -0700 Subject: [PATCH] Add _primary preference only for segment replication enabled indices (#2040) (#2045) * Add _primary preference only for segment replication enabled indices * Add test for segment replication tests * Remove isSegRepEnabled check and use _primary_first preference * Remove unused ClusterState reference * Self review --------- (cherry picked from commit 9c12628a256c959036c4ca297205b56939860674) Signed-off-by: Suraj Singh Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- .../storage/OpenSearchDataSourceMetadataStorage.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java b/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java index 3de924dcbb..5f5e087ce0 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java @@ -224,6 +224,8 @@ private List searchInDataSourcesIndex(QueryBuilder query) { searchSourceBuilder.query(query); searchSourceBuilder.size(DATASOURCE_QUERY_RESULT_SIZE); searchRequest.source(searchSourceBuilder); + // https://github.com/opensearch-project/sql/issues/1801. + searchRequest.preference("_primary_first"); ActionFuture searchResponseActionFuture; try (ThreadContext.StoredContext ignored = client.threadPool().getThreadContext().stashContext()) {