Skip to content

Commit

Permalink
Add bool query and match_all when _tier matches
Browse files Browse the repository at this point in the history
  • Loading branch information
andreidan committed Oct 17, 2024
1 parent 98277e1 commit 26a572a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ protected QueryBuilder doCoordinatorRewrite(CoordinatorRewriteContext coordinato
Query tierFieldQuery = tierFieldType.innerTermsQuery(value, coordinatorRewriteContext);
if (tierFieldQuery instanceof MatchNoDocsQuery) {
return new MatchNoneQueryBuilder("The \"" + getName() + "\" query was rewritten to a \"match_none\" query.");
} else if (tierFieldQuery instanceof MatchAllDocsQuery) {
return new MatchAllQueryBuilder();
}
}
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.mapper.DateFieldMapper;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.index.query.TermQueryBuilder;
Expand Down Expand Up @@ -1082,6 +1083,21 @@ public void testCanMatchSkipsPartiallyMountedIndicesWhenFrozenNodesUnavailable()
assertThat(searchResponse.getHits().getTotalHits().value, equalTo((long) numDocsRegularIndex));
});
}

{
// bool query
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery().mustNot(QueryBuilders.termQuery("_tier", "data_frozen"));
List<String> indicesToSearch = List.of(regularIndex, partiallyMountedIndex);
SearchRequest request = new SearchRequest().indices(indicesToSearch.toArray(new String[0]))
.source(new SearchSourceBuilder().query(boolQueryBuilder));

assertResponse(client().search(request), searchResponse -> {
// as we excluded the frozen tier we shouldn't get any failures
assertThat(searchResponse.getFailedShards(), equalTo(0));
// we should be receiving all the hits from the index that's in the data_content tier
assertThat(searchResponse.getHits().getTotalHits().value, equalTo((long) numDocsRegularIndex));
});
}
}

private void createIndexWithOnlyOneTimestampField(String timestampField, String index, int numShards, Settings extraSettings)
Expand Down

0 comments on commit 26a572a

Please sign in to comment.