Skip to content

Commit 800ba31

Browse files
authored
Fix SourceOnlySnapshotIT (#53462)
The tests in this class had been failing for a while, but went unnoticed as not tested by CI (see #53442). The reason the tests fail is that the can-match phase is smarter now, and filters out access to a non-existing field. Closes #53442
1 parent ba3c363 commit 800ba31

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

x-pack/plugin/core/src/test/java/org/elasticsearch/snapshots/SourceOnlySnapshotIT.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ public void testSnapshotAndRestore() throws Exception {
105105
});
106106
assertTrue(e.toString().contains("_source only indices can't be searched or filtered"));
107107

108-
e = expectThrows(SearchPhaseExecutionException.class, () ->
109-
client().prepareSearch(sourceIdx).setQuery(QueryBuilders.termQuery("field1", "bar")).get());
110-
assertTrue(e.toString().contains("_source only indices can't be searched or filtered"));
108+
// can-match phase pre-filters access to non-existing field
109+
assertEquals(0,
110+
client().prepareSearch(sourceIdx).setQuery(QueryBuilders.termQuery("field1", "bar")).get().getHits().getTotalHits().value);
111111
// make sure deletes do not work
112112
String idToDelete = "" + randomIntBetween(0, builders.length);
113113
expectThrows(ClusterBlockException.class, () -> client().prepareDelete(sourceIdx, idToDelete)
@@ -130,9 +130,9 @@ public void testSnapshotAndRestoreWithNested() throws Exception {
130130
SearchPhaseExecutionException e = expectThrows(SearchPhaseExecutionException.class, () ->
131131
client().prepareSearch(sourceIdx).setQuery(QueryBuilders.idsQuery().addIds("" + randomIntBetween(0, builders.length))).get());
132132
assertTrue(e.toString().contains("_source only indices can't be searched or filtered"));
133-
e = expectThrows(SearchPhaseExecutionException.class, () ->
134-
client().prepareSearch(sourceIdx).setQuery(QueryBuilders.termQuery("field1", "bar")).get());
135-
assertTrue(e.toString().contains("_source only indices can't be searched or filtered"));
133+
// can-match phase pre-filters access to non-existing field
134+
assertEquals(0,
135+
client().prepareSearch(sourceIdx).setQuery(QueryBuilders.termQuery("field1", "bar")).get().getHits().getTotalHits().value);
136136
// make sure deletes do not work
137137
String idToDelete = "" + randomIntBetween(0, builders.length);
138138
expectThrows(ClusterBlockException.class, () -> client().prepareDelete(sourceIdx, idToDelete)

0 commit comments

Comments
 (0)