Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ranjith Ramachandra committed Sep 2, 2023
1 parent 2f85d03 commit b2e2c86
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testNoShardSizeString() throws Exception {

indexData();

SearchResponse response = client().prepareSearch("idx")
SearchResponse response = client().prepareSearch("idx").setPreference("_primary")
.setQuery(matchAllQuery())
.addAggregation(
terms("keys").field("key").size(3).collectMode(randomFrom(SubAggCollectionMode.values())).order(BucketOrder.count(false))
Expand All @@ -74,7 +74,7 @@ public void testShardSizeEqualsSizeString() throws Exception {

indexData();

SearchResponse response = client().prepareSearch("idx")
SearchResponse response = client().prepareSearch("idx").setPreference("_primary")
.setQuery(matchAllQuery())
.addAggregation(
terms("keys").field("key")
Expand Down Expand Up @@ -103,7 +103,7 @@ public void testWithShardSizeString() throws Exception {

indexData();

SearchResponse response = client().prepareSearch("idx")
SearchResponse response = client().prepareSearch("idx").setPreference("_primary")
.setQuery(matchAllQuery())
.addAggregation(
terms("keys").field("key")
Expand Down Expand Up @@ -132,7 +132,7 @@ public void testWithShardSizeStringSingleShard() throws Exception {

indexData();

SearchResponse response = client().prepareSearch("idx")
SearchResponse response = client().prepareSearch("idx").setPreference("_primary")
.setRouting(routing1)
.setQuery(matchAllQuery())
.addAggregation(
Expand Down Expand Up @@ -161,7 +161,7 @@ public void testNoShardSizeTermOrderString() throws Exception {

indexData();

SearchResponse response = client().prepareSearch("idx")
SearchResponse response = client().prepareSearch("idx").setPreference("_primary")
.setQuery(matchAllQuery())
.addAggregation(
terms("keys").field("key").size(3).collectMode(randomFrom(SubAggCollectionMode.values())).order(BucketOrder.key(true))
Expand All @@ -185,7 +185,7 @@ public void testNoShardSizeLong() throws Exception {

indexData();

SearchResponse response = client().prepareSearch("idx")
SearchResponse response = client().prepareSearch("idx").setPreference("_primary")
.setQuery(matchAllQuery())
.addAggregation(
terms("keys").field("key").size(3).collectMode(randomFrom(SubAggCollectionMode.values())).order(BucketOrder.count(false))
Expand All @@ -209,7 +209,7 @@ public void testShardSizeEqualsSizeLong() throws Exception {

indexData();

SearchResponse response = client().prepareSearch("idx")
SearchResponse response = client().prepareSearch("idx").setPreference("_primary")
.setQuery(matchAllQuery())
.addAggregation(
terms("keys").field("key")
Expand Down Expand Up @@ -237,7 +237,7 @@ public void testWithShardSizeLong() throws Exception {

indexData();

SearchResponse response = client().prepareSearch("idx")
SearchResponse response = client().prepareSearch("idx").setPreference("_primary")
.setQuery(matchAllQuery())
.addAggregation(
terms("keys").field("key")
Expand Down Expand Up @@ -266,7 +266,7 @@ public void testWithShardSizeLongSingleShard() throws Exception {

indexData();

SearchResponse response = client().prepareSearch("idx")
SearchResponse response = client().prepareSearch("idx").setPreference("_primary")
.setRouting(routing1)
.setQuery(matchAllQuery())
.addAggregation(
Expand Down Expand Up @@ -295,7 +295,7 @@ public void testNoShardSizeTermOrderLong() throws Exception {

indexData();

SearchResponse response = client().prepareSearch("idx")
SearchResponse response = client().prepareSearch("idx").setPreference("_primary")
.setQuery(matchAllQuery())
.addAggregation(
terms("keys").field("key").size(3).collectMode(randomFrom(SubAggCollectionMode.values())).order(BucketOrder.key(true))
Expand All @@ -319,7 +319,7 @@ public void testNoShardSizeDouble() throws Exception {

indexData();

SearchResponse response = client().prepareSearch("idx")
SearchResponse response = client().prepareSearch("idx").setPreference("_primary")
.setQuery(matchAllQuery())
.addAggregation(
terms("keys").field("key").size(3).collectMode(randomFrom(SubAggCollectionMode.values())).order(BucketOrder.count(false))
Expand All @@ -343,7 +343,7 @@ public void testShardSizeEqualsSizeDouble() throws Exception {

indexData();

SearchResponse response = client().prepareSearch("idx")
SearchResponse response = client().prepareSearch("idx").setPreference("_primary")
.setQuery(matchAllQuery())
.addAggregation(
terms("keys").field("key")
Expand Down Expand Up @@ -371,7 +371,7 @@ public void testWithShardSizeDouble() throws Exception {

indexData();

SearchResponse response = client().prepareSearch("idx")
SearchResponse response = client().prepareSearch("idx").setPreference("_primary")
.setQuery(matchAllQuery())
.addAggregation(
terms("keys").field("key")
Expand Down Expand Up @@ -399,7 +399,7 @@ public void testWithShardSizeDoubleSingleShard() throws Exception {

indexData();

SearchResponse response = client().prepareSearch("idx")
SearchResponse response = client().prepareSearch("idx").setPreference("_primary")
.setRouting(routing1)
.setQuery(matchAllQuery())
.addAggregation(
Expand Down Expand Up @@ -428,7 +428,7 @@ public void testNoShardSizeTermOrderDouble() throws Exception {

indexData();

SearchResponse response = client().prepareSearch("idx")
SearchResponse response = client().prepareSearch("idx").setPreference("_primary")
.setQuery(matchAllQuery())
.addAggregation(
terms("keys").field("key").size(3).collectMode(randomFrom(SubAggCollectionMode.values())).order(BucketOrder.key(true))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public void testPluginSort() throws Exception {

refresh();

SearchResponse searchResponse = client().prepareSearch("test").addSort(new CustomSortBuilder("field", SortOrder.ASC)).get();
SearchResponse searchResponse = client().prepareSearch("test").setPreference("_primary").addSort(new CustomSortBuilder("field", SortOrder.ASC)).get();
assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("3"));
assertThat(searchResponse.getHits().getAt(1).getId(), equalTo("2"));
assertThat(searchResponse.getHits().getAt(2).getId(), equalTo("1"));

searchResponse = client().prepareSearch("test").addSort(new CustomSortBuilder("field", SortOrder.DESC)).get();
searchResponse = client().prepareSearch("test").setPreference("_primary").addSort(new CustomSortBuilder("field", SortOrder.DESC)).get();
assertThat(searchResponse.getHits().getAt(0).getId(), equalTo("1"));
assertThat(searchResponse.getHits().getAt(1).getId(), equalTo("2"));
assertThat(searchResponse.getHits().getAt(2).getId(), equalTo("3"));
Expand All @@ -61,7 +61,7 @@ public void testPluginSortXContent() throws Exception {
refresh();

// builder -> json -> builder
SearchResponse searchResponse = client().prepareSearch("test")
SearchResponse searchResponse = client().prepareSearch("test").setPreference("_primary")
.setSource(
SearchSourceBuilder.fromXContent(
createParser(
Expand All @@ -76,7 +76,7 @@ public void testPluginSortXContent() throws Exception {
assertThat(searchResponse.getHits().getAt(1).getId(), equalTo("2"));
assertThat(searchResponse.getHits().getAt(2).getId(), equalTo("1"));

searchResponse = client().prepareSearch("test")
searchResponse = client().prepareSearch("test").setPreference("_primary")
.setSource(
SearchSourceBuilder.fromXContent(
createParser(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public void testSourceDefaultBehavior() {
refresh();


SearchResponse response = client().prepareSearch("test").get();
SearchResponse response = client().prepareSearch("test").setPreference("_primary").get();
assertThat(response.getHits().getAt(0).getSourceAsString(), notNullValue());

response = client().prepareSearch("test").addStoredField("bla").get();
response = client().prepareSearch("test").setPreference("_primary").addStoredField("bla").get();
assertThat(response.getHits().getAt(0).getSourceAsString(), nullValue());

response = client().prepareSearch("test").addStoredField("_source").get();
response = client().prepareSearch("test").setPreference("_primary").addStoredField("_source").get();
assertThat(response.getHits().getAt(0).getSourceAsString(), notNullValue());

}
Expand All @@ -66,22 +66,22 @@ public void testSourceFiltering() {
client().prepareIndex("test").setId("1").setSource("field1", "value", "field2", "value2").get();
refresh();

SearchResponse response = client().prepareSearch("test").setFetchSource(false).get();
SearchResponse response = client().prepareSearch("test").setPreference("_primary").setFetchSource(false).get();
assertThat(response.getHits().getAt(0).getSourceAsString(), nullValue());

response = client().prepareSearch("test").setFetchSource(true).get();
response = client().prepareSearch("test").setPreference("_primary").setFetchSource(true).get();
assertThat(response.getHits().getAt(0).getSourceAsString(), notNullValue());

response = client().prepareSearch("test").setFetchSource("field1", null).get();
response = client().prepareSearch("test").setPreference("_primary").setFetchSource("field1", null).get();
assertThat(response.getHits().getAt(0).getSourceAsString(), notNullValue());
assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(1));
assertThat((String) response.getHits().getAt(0).getSourceAsMap().get("field1"), equalTo("value"));

response = client().prepareSearch("test").setFetchSource("hello", null).get();
response = client().prepareSearch("test").setPreference("_primary").setFetchSource("hello", null).get();
assertThat(response.getHits().getAt(0).getSourceAsString(), notNullValue());
assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(0));

response = client().prepareSearch("test").setFetchSource(new String[] { "*" }, new String[] { "field2" }).get();
response = client().prepareSearch("test").setPreference("_primary").setFetchSource(new String[] { "*" }, new String[] { "field2" }).get();
assertThat(response.getHits().getAt(0).getSourceAsString(), notNullValue());
assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(1));
assertThat((String) response.getHits().getAt(0).getSourceAsMap().get("field1"), equalTo("value"));
Expand All @@ -99,12 +99,12 @@ public void testSourceWithWildcardFiltering() {
client().prepareIndex("test").setId("1").setSource("field", "value").get();
refresh();

SearchResponse response = client().prepareSearch("test").setFetchSource(new String[] { "*.notexisting", "field" }, null).get();
SearchResponse response = client().prepareSearch("test").setPreference("_primary").setFetchSource(new String[] { "*.notexisting", "field" }, null).get();
assertThat(response.getHits().getAt(0).getSourceAsString(), notNullValue());
assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(1));
assertThat((String) response.getHits().getAt(0).getSourceAsMap().get("field"), equalTo("value"));

response = client().prepareSearch("test").setFetchSource(new String[] { "field.notexisting.*", "field" }, null).get();
response = client().prepareSearch("test").setPreference("_primary").setFetchSource(new String[] { "field.notexisting.*", "field" }, null).get();
assertThat(response.getHits().getAt(0).getSourceAsString(), notNullValue());
assertThat(response.getHits().getAt(0).getSourceAsMap().size(), equalTo(1));
assertThat((String) response.getHits().getAt(0).getSourceAsMap().get("field"), equalTo("value"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ protected void indexData() throws Exception {

indexRandom(true, docs);

SearchResponse resp = client().prepareSearch("idx").setRouting(routing1).setQuery(matchAllQuery()).get();
SearchResponse resp = client().prepareSearch("idx").setPreference("_primary").setRouting(routing1).setQuery(matchAllQuery()).get();
assertSearchResponse(resp);
long totalOnOne = resp.getHits().getTotalHits().value;
assertThat(totalOnOne, is(15L));
resp = client().prepareSearch("idx").setRouting(routing2).setQuery(matchAllQuery()).get();
resp = client().prepareSearch("idx").setPreference("_primary").setRouting(routing2).setQuery(matchAllQuery()).get();
assertSearchResponse(resp);
long totalOnTwo = resp.getHits().getTotalHits().value;
assertThat(totalOnTwo, is(12L));
Expand Down

0 comments on commit b2e2c86

Please sign in to comment.