Skip to content

Commit

Permalink
Address jpountz review comments:
Browse files Browse the repository at this point in the history
* rest_total_hits_as_int -> track_total_hits
* Use Regex.simpleMatch
  • Loading branch information
markharwood committed Nov 15, 2019
1 parent 8e42ac4 commit 6ac08b1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 }
Expand All @@ -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 }
Expand All @@ -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 }
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ 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:
query:
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}
Expand All @@ -87,16 +87,16 @@ 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:
query:
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 }
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -402,12 +403,7 @@ public void onRemoval(ShardId shardId, Accountable accountable) {

public static Predicate<String> 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
Expand Down

0 comments on commit 6ac08b1

Please sign in to comment.