Fix querying a data stream name in _index field. (#63178)
Backport #63170 to 7.x branch. The _index field is a special field that allows using queries against the name of an index or alias. Data stream names were not included, this pr fixes that by changing SearchIndexNameMatcher (which used via IndexFieldMapper) to also include data streams.
This commit is contained in:
parent
1663dc7cf8
commit
300e525138
|
@ -74,7 +74,7 @@ public class SearchIndexNameMatcher implements Predicate<String> {
|
|||
|
||||
private boolean matchesIndex(String pattern) {
|
||||
String[] concreteIndices = expressionResolver.concreteIndexNames(
|
||||
clusterService.state(), IndicesOptions.lenientExpandOpen(), pattern);
|
||||
clusterService.state(), IndicesOptions.lenientExpandOpen(), true, pattern);
|
||||
for (String index : concreteIndices) {
|
||||
if (Regex.simpleMatch(index, indexName)) {
|
||||
return true;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
package org.elasticsearch.datastreams;
|
||||
|
||||
import org.apache.lucene.search.TotalHits;
|
||||
import org.elasticsearch.ElasticsearchStatusException;
|
||||
import org.elasticsearch.ExceptionsHelper;
|
||||
import org.elasticsearch.action.ActionRequestBuilder;
|
||||
|
@ -50,6 +51,7 @@ import org.elasticsearch.common.xcontent.XContentType;
|
|||
import org.elasticsearch.index.IndexNotFoundException;
|
||||
import org.elasticsearch.index.mapper.DateFieldMapper;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
import org.elasticsearch.index.query.TermQueryBuilder;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
@ -1098,6 +1100,21 @@ public class DataStreamIT extends ESIntegTestCase {
|
|||
);
|
||||
}
|
||||
|
||||
public void testQueryDataStreamNameInIndexField() throws Exception {
|
||||
putComposableIndexTemplate("id1", List.of("metrics-*"));
|
||||
CreateDataStreamAction.Request createDataStreamRequest = new CreateDataStreamAction.Request("metrics-foo");
|
||||
client().execute(CreateDataStreamAction.INSTANCE, createDataStreamRequest).get();
|
||||
|
||||
indexDocs("metrics-foo", 1);
|
||||
indexDocs("metrics-bar", 1);
|
||||
|
||||
SearchRequest searchRequest = new SearchRequest("*");
|
||||
searchRequest.source().query(new TermQueryBuilder("_index", "metrics-foo"));
|
||||
SearchResponse searchResponse = client().search(searchRequest).actionGet();
|
||||
assertThat(searchResponse.getHits().getTotalHits().value, equalTo(1L));
|
||||
assertThat(searchResponse.getHits().getTotalHits().relation, equalTo(TotalHits.Relation.EQUAL_TO));
|
||||
}
|
||||
|
||||
private static void verifyResolvability(String dataStream, ActionRequestBuilder<?, ?> requestBuilder, boolean fail) {
|
||||
verifyResolvability(dataStream, requestBuilder, fail, 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue