From 6ac08b17bb4f2fdccfca7ab9fdaa618fec7e7751 Mon Sep 17 00:00:00 2001 From: markharwood Date: Thu, 14 Nov 2019 17:10:52 +0000 Subject: [PATCH] Address jpountz review comments: * rest_total_hits_as_int -> track_total_hits * Use Regex.simpleMatch --- .../test/multi_cluster/70_skip_shards.yml | 32 +++++++++---------- .../multi_cluster/90_index_name_query.yml | 10 +++--- .../test/AbstractBuilderTestCase.java | 8 ++--- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/70_skip_shards.yml b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/70_skip_shards.yml index e549648e862c0..92ae11c712b25 100644 --- a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/70_skip_shards.yml +++ b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/70_skip_shards.yml @@ -91,13 +91,13 @@ # check that we match the alias with term query - do: search: - rest_total_hits_as_int: true + track_total_hits: true index: "skip_shards_local_index" pre_filter_shard_size: 1 ccs_minimize_roundtrips: false body: { "size" : 10, "query" : { "term" : { "_index" : "test_skip_alias" } } } - - match: { hits.total: 2 } + - match: { hits.total.value: 2 } - match: { hits.hits.0._index: "skip_shards_local_index"} - match: { _shards.total: 2 } - match: { _shards.successful: 2 } @@ -107,13 +107,13 @@ # check that we match the alias with terms query - do: search: - rest_total_hits_as_int: true + track_total_hits: true index: "skip_shards_local_index" pre_filter_shard_size: 1 ccs_minimize_roundtrips: false body: { "size" : 10, "query" : { "terms" : { "_index" : ["test_skip_alias", "does_not_match"] } } } - - match: { hits.total: 2 } + - match: { hits.total.value: 2 } - match: { hits.hits.0._index: "skip_shards_local_index"} - match: { _shards.total: 2 } - match: { _shards.successful: 2 } @@ -123,13 +123,13 @@ # check that we match the alias with prefix query - do: search: - rest_total_hits_as_int: true + track_total_hits: true index: "skip_shards_local_index" pre_filter_shard_size: 1 ccs_minimize_roundtrips: false body: { "size" : 10, "query" : { "prefix" : { "_index" : "test_skip_ali" } } } - - match: { hits.total: 2 } + - match: { hits.total.value: 2 } - match: { hits.hits.0._index: "skip_shards_local_index"} - match: { _shards.total: 2 } - match: { _shards.successful: 2 } @@ -139,13 +139,13 @@ # check that we match the alias with wildcard query - do: search: - rest_total_hits_as_int: true + track_total_hits: true index: "skip_shards_local_index" pre_filter_shard_size: 1 ccs_minimize_roundtrips: false body: { "size" : 10, "query" : { "wildcard" : { "_index" : "test_skip_ali*" } } } - - match: { hits.total: 2 } + - match: { hits.total.value: 2 } - match: { hits.hits.0._index: "skip_shards_local_index"} - match: { _shards.total: 2 } - match: { _shards.successful: 2 } @@ -156,14 +156,14 @@ # check that skipped when we don't match the alias with a term query - do: search: - rest_total_hits_as_int: true + track_total_hits: true index: "skip_shards_local_index" pre_filter_shard_size: 1 ccs_minimize_roundtrips: false body: { "size" : 10, "query" : { "term" : { "_index" : "does_not_match" } } } - - match: { hits.total: 0 } + - match: { hits.total.value: 0 } - match: { _shards.total: 2 } - match: { _shards.successful: 2 } # When all shards are skipped current logic returns 1 to produce a valid search result @@ -173,14 +173,14 @@ # check that skipped when we don't match the alias with a terms query - do: search: - rest_total_hits_as_int: true + track_total_hits: true index: "skip_shards_local_index" pre_filter_shard_size: 1 ccs_minimize_roundtrips: false body: { "size" : 10, "query" : { "terms" : { "_index" : ["does_not_match", "also_does_not_match"] } } } - - match: { hits.total: 0 } + - match: { hits.total.value: 0 } - match: { _shards.total: 2 } - match: { _shards.successful: 2 } # When all shards are skipped current logic returns 1 to produce a valid search result @@ -190,14 +190,14 @@ # check that skipped when we don't match the alias with a prefix query - do: search: - rest_total_hits_as_int: true + track_total_hits: true index: "skip_shards_local_index" pre_filter_shard_size: 1 ccs_minimize_roundtrips: false body: { "size" : 10, "query" : { "prefix" : { "_index" : "does_not_matc" } } } - - match: { hits.total: 0 } + - match: { hits.total.value: 0 } - match: { _shards.total: 2 } - match: { _shards.successful: 2 } # When all shards are skipped current logic returns 1 to produce a valid search result @@ -207,14 +207,14 @@ # check that skipped when we don't match the alias with a wildcard query - do: search: - rest_total_hits_as_int: true + track_total_hits: true index: "skip_shards_local_index" pre_filter_shard_size: 1 ccs_minimize_roundtrips: false body: { "size" : 10, "query" : { "wildcard" : { "_index" : "does_not_matc*" } } } - - match: { hits.total: 0 } + - match: { hits.total.value: 0 } - match: { _shards.total: 2 } - match: { _shards.successful: 2 } # When all shards are skipped current logic returns 1 to produce a valid search result diff --git a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/90_index_name_query.yml b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/90_index_name_query.yml index d0d752952bc48..a60a1b0d812ee 100644 --- a/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/90_index_name_query.yml +++ b/qa/multi-cluster-search/src/test/resources/rest-api-spec/test/multi_cluster/90_index_name_query.yml @@ -70,7 +70,7 @@ teardown: - do: search: ccs_minimize_roundtrips: false - rest_total_hits_as_int: true + track_total_hits: true index: "single_doc_index,my_remote_cluster:single_doc_index" pre_filter_shard_size: 1 body: @@ -78,7 +78,7 @@ teardown: term: "_index": "does_not_match" - - match: { hits.total: 0 } + - match: { hits.total.value: 0 } - match: { _shards.total: 2 } - match: { _shards.successful: 2 } - match: { _shards.skipped : 1} @@ -87,7 +87,7 @@ teardown: - do: search: ccs_minimize_roundtrips: false - rest_total_hits_as_int: true + track_total_hits: true index: "single_doc_index,my_remote_cluster:single_doc_index" pre_filter_shard_size: 1 body: @@ -95,8 +95,8 @@ teardown: term: "_index": "my_remote_cluster:does_not_match" - - match: { hits.total: 0 } + - match: { hits.total.value: 0 } - match: { _shards.total: 2 } - match: { _shards.successful: 2 } - match: { _shards.skipped : 1} - - match: { _shards.failed: 0 } + - match: { _shards.failed: 0 } diff --git a/test/framework/src/main/java/org/elasticsearch/test/AbstractBuilderTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/AbstractBuilderTestCase.java index 619e2253109de..e726b4dc15094 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/AbstractBuilderTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/AbstractBuilderTestCase.java @@ -36,6 +36,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; +import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; @@ -402,12 +403,7 @@ public void onRemoval(ShardId shardId, Accountable accountable) { public static Predicate indexNameMatcher() { // Simplistic index name matcher used for testing - return pattern ->{ - if (pattern.endsWith("*")) { - return index.getName().startsWith(pattern.substring(0, pattern.length()-1)); - } - return pattern.equals(index.getName()); - }; + return pattern -> Regex.simpleMatch(pattern, index.getName()); } @Override