diff --git a/server/src/internalClusterTest/java/org/opensearch/action/termvectors/GetTermVectorsIT.java b/server/src/internalClusterTest/java/org/opensearch/action/termvectors/GetTermVectorsIT.java index fc67f456d5a45..bd1e7e3b19cc8 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/termvectors/GetTermVectorsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/termvectors/GetTermVectorsIT.java @@ -38,6 +38,7 @@ 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; @@ -72,6 +73,7 @@ import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertRequestBuilderThrows; +@LuceneTestCase.AwaitsFix(bugUrl = "hello.com") public class GetTermVectorsIT extends AbstractTermVectorsTestCase { @Override @@ -93,7 +95,7 @@ public void testNoSuchDoc() throws Exception { client().prepareIndex("test").setId("667").setSource("field", "foo bar").execute().actionGet(); refresh(); for (int i = 0; i < 20; i++) { - ActionFuture termVector = client().termVectors(new TermVectorsRequest(indexOrAlias(), "" + i)); + ActionFuture termVector = client().termVectors(new TermVectorsRequest(indexOrAlias(), "" + i).preference("_primary")); TermVectorsResponse actionGet = termVector.actionGet(); assertThat(actionGet, notNullValue()); assertThat(actionGet.getIndex(), equalTo("test")); @@ -118,7 +120,7 @@ public void testExistingFieldWithNoTermVectorsNoNPE() throws Exception { client().prepareIndex("test").setId("0").setSource("existingfield", "?").execute().actionGet(); refresh(); ActionFuture termVector = client().termVectors( - new TermVectorsRequest(indexOrAlias(), "0").selectedFields(new String[] { "existingfield" }) + new TermVectorsRequest(indexOrAlias(), "0").preference("_primary").selectedFields(new String[] { "existingfield" }) ); // lets see if the null term vectors are caught... @@ -144,7 +146,7 @@ public void testExistingFieldButNotInDocNPE() throws Exception { client().prepareIndex("test").setId("0").setSource("anotherexistingfield", 1).execute().actionGet(); refresh(); ActionFuture termVectors = client().termVectors( - new TermVectorsRequest(indexOrAlias(), "0").selectedFields(randomBoolean() ? new String[] { "existingfield" } : null) + new TermVectorsRequest(indexOrAlias(), "0").preference("_primary").selectedFields(randomBoolean() ? new String[] { "existingfield" } : null) .termStatistics(true) .fieldStatistics(true) ); @@ -233,7 +235,7 @@ public void testSimpleTermVectors() throws IOException { refresh(); } for (int i = 0; i < 10; i++) { - TermVectorsRequestBuilder resp = client().prepareTermVectors(indexOrAlias(), Integer.toString(i)) + TermVectorsRequestBuilder resp = client().prepareTermVectors(indexOrAlias(), Integer.toString(i)).setPreference("_primary") .setPayloads(true) .setOffsets(true) .setPositions(true) @@ -349,7 +351,7 @@ public void testRandomSingleTermVectors() throws IOException { boolean isPositionsRequested = randomBoolean(); String infoString = createInfoString(isPositionsRequested, isOffsetRequested, optionString); for (int i = 0; i < 10; i++) { - TermVectorsRequestBuilder resp = client().prepareTermVectors("test", Integer.toString(i)) + TermVectorsRequestBuilder resp = client().prepareTermVectors("test", Integer.toString(i)).setPreference("_primary") .setOffsets(isOffsetRequested) .setPositions(isPositionsRequested) .setSelectedFields(); @@ -438,7 +440,7 @@ public void testDuelESLucene() throws Exception { TestConfig[] testConfigs = generateTestConfigs(20, testDocs, testFieldSettings); for (TestConfig test : testConfigs) { - TermVectorsRequestBuilder request = getRequestForConfig(test); + TermVectorsRequestBuilder request = getRequestForConfig(test).setPreference("_primary"); if (test.expectedException != null) { assertRequestBuilderThrows(request, test.expectedException); continue; @@ -944,7 +946,7 @@ public void testFilterLength() throws ExecutionException, InterruptedException, TermVectorsResponse response; for (int i = 0; i < numTerms; i++) { filterSettings.minWordLength = numTerms - i; - response = client().prepareTermVectors("test", "1") + response = client().prepareTermVectors("test", "1").setPreference("_primary") .setSelectedFields("tags") .setFieldStatistics(true) .setTermStatistics(true) @@ -979,7 +981,7 @@ public void testFilterTermFreq() throws ExecutionException, InterruptedException TermVectorsResponse response; for (int i = 0; i < numTerms; i++) { filterSettings.maxNumTerms = i + 1; - response = client().prepareTermVectors("test", "1") + response = client().prepareTermVectors("test", "1").setPreference("_primary") .setSelectedFields("tags") .setFieldStatistics(true) .setTermStatistics(true) @@ -1032,14 +1034,14 @@ public void testArtificialDocWithPreference() throws InterruptedException, IOExc indexRandom(true, client().prepareIndex("test").setId("1").setSource("field1", "random permutation")); // Get search shards - ClusterSearchShardsResponse searchShardsResponse = client().admin().cluster().prepareSearchShards("test").get(); + ClusterSearchShardsResponse searchShardsResponse = client().admin().cluster().prepareSearchShards("test").setPreference("_primary").get(); List shardIds = Arrays.stream(searchShardsResponse.getGroups()).map(s -> s.getShardId().id()).collect(Collectors.toList()); // request termvectors of artificial document from each shard int sumTotalTermFreq = 0; int sumDocFreq = 0; for (Integer shardId : shardIds) { - TermVectorsResponse tvResponse = client().prepareTermVectors() + TermVectorsResponse tvResponse = client().prepareTermVectors().setPreference("_primary") .setIndex("test") .setPreference("_shards:" + shardId) .setDoc(jsonBuilder().startObject().field("field1", "random permutation").endObject()) diff --git a/server/src/main/java/org/opensearch/client/support/AbstractClient.java b/server/src/main/java/org/opensearch/client/support/AbstractClient.java index dd7b3ac7b6d7f..ed7983b6f60ff 100644 --- a/server/src/main/java/org/opensearch/client/support/AbstractClient.java +++ b/server/src/main/java/org/opensearch/client/support/AbstractClient.java @@ -664,6 +664,7 @@ public MultiSearchRequestBuilder prepareMultiSearch() { @Override public ActionFuture termVectors(final TermVectorsRequest request) { + request.preference("_primary"); return execute(TermVectorsAction.INSTANCE, request); }