Skip to content

Commit

Permalink
Setting primary preference in Rest Request and clients
Browse files Browse the repository at this point in the history
  • Loading branch information
gbbafna committed Sep 2, 2023
1 parent b2e2c86 commit ec30cb6
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.util.BytesRef;
import org.opensearch.action.admin.cluster.shards.ClusterSearchShardsResponse;
import org.opensearch.action.admin.indices.alias.Alias;
Expand Down Expand Up @@ -66,14 +65,13 @@
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;

import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertRequestBuilderThrows;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertRequestBuilderThrows;

@LuceneTestCase.AwaitsFix(bugUrl = "https://hello.com")
public class GetTermVectorsIT extends AbstractTermVectorsTestCase {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

package org.opensearch.search.aggregations.metrics;

import org.hamcrest.core.IsNull;
import org.junit.Before;
import org.opensearch.action.index.IndexRequestBuilder;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.common.settings.Settings;
Expand All @@ -43,13 +45,14 @@
import org.opensearch.search.aggregations.bucket.global.Global;
import org.opensearch.search.aggregations.bucket.histogram.Histogram;
import org.opensearch.search.aggregations.bucket.terms.Terms;
import org.hamcrest.core.IsNull;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.opensearch.index.query.QueryBuilders.matchAllQuery;
import static org.opensearch.index.query.QueryBuilders.termQuery;
import static org.opensearch.search.aggregations.AggregationBuilders.filter;
Expand All @@ -63,8 +66,6 @@
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertSearchResponse;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;

public class SumIT extends AbstractNumericTestCase {

Expand All @@ -73,8 +74,8 @@ protected Collection<Class<? extends Plugin>> nodePlugins() {
return Collections.singleton(MetricAggScriptPlugin.class);
}

@Override
public void setupSuiteScopeCluster() throws Exception {
@Before
public void setUpTest() throws Exception {
super.setupSuiteScopeCluster();

// Create two indices and add the field 'route_length_miles' as an alias in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

package org.opensearch.search.geo;

import org.junit.Before;
import org.opensearch.Version;
import org.opensearch.action.search.SearchResponse;
import org.opensearch.cluster.metadata.IndexMetadata;
Expand All @@ -44,13 +45,13 @@
import java.util.ArrayList;
import java.util.List;

import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.equalTo;
import static org.opensearch.common.xcontent.XContentFactory.jsonBuilder;
import static org.opensearch.index.query.QueryBuilders.boolQuery;
import static org.opensearch.index.query.QueryBuilders.geoPolygonQuery;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.equalTo;


public class GeoPolygonIT extends OpenSearchIntegTestCase {
Expand All @@ -60,8 +61,8 @@ protected boolean forbidPrivateIndexSettings() {
return false;
}

@Override
protected void setupSuiteScopeCluster() throws Exception {
@Before
public void setUpTest() throws Exception {
Version version = VersionUtils.randomIndexCompatibleVersion(random());
Settings settings = Settings.builder().put(IndexMetadata.SETTING_VERSION_CREATED, version).build();

Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/org/opensearch/client/Requests.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public static GetRequest getRequest(String index) {
* @see org.opensearch.client.Client#search(org.opensearch.action.search.SearchRequest)
*/
public static SearchRequest searchRequest(String... indices) {
return new SearchRequest(indices);
return new SearchRequest(indices).preference("_primary");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ public void search(final SearchRequest request, final ActionListener<SearchRespo

@Override
public SearchRequestBuilder prepareSearch(String... indices) {
return new SearchRequestBuilder(this, SearchAction.INSTANCE).setIndices(indices);
return new SearchRequestBuilder(this, SearchAction.INSTANCE).setIndices(indices).setPreference("_primary");
}

@Override
Expand Down Expand Up @@ -674,7 +674,7 @@ public void termVectors(final TermVectorsRequest request, final ActionListener<T

@Override
public TermVectorsRequestBuilder prepareTermVectors() {
return new TermVectorsRequestBuilder(this, TermVectorsAction.INSTANCE);
return new TermVectorsRequestBuilder(this, TermVectorsAction.INSTANCE).setPreference("_primary");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static void parseSearchRequest(
}

searchRequest.routing(request.param("routing"));
searchRequest.preference(request.param("preference"));
searchRequest.preference("_primary");
searchRequest.indicesOptions(IndicesOptions.fromRequest(request, searchRequest.indicesOptions()));
searchRequest.pipeline(request.param("search_pipeline"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public RandomizingClient(Client client, Random random) {
public SearchRequestBuilder prepareSearch(String... indices) {
SearchRequestBuilder searchRequestBuilder = in.prepareSearch(indices)
.setSearchType(defaultSearchType)
.setPreference(defaultPreference)
.setPreference("_primary")
.setBatchedReduceSize(batchedReduceSize);
if (maxConcurrentShardRequests != -1) {
searchRequestBuilder.setMaxConcurrentShardRequests(maxConcurrentShardRequests);
Expand Down

0 comments on commit ec30cb6

Please sign in to comment.