|
|
@@ -133,6 +133,7 @@ import static org.hamcrest.Matchers.equalTo;
|
|
|
import static org.hamcrest.Matchers.greaterThan;
|
|
|
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
|
|
|
import static org.hamcrest.Matchers.hasItemInArray;
|
|
|
+import static org.hamcrest.Matchers.hasKey;
|
|
|
import static org.hamcrest.Matchers.hasSize;
|
|
|
import static org.hamcrest.Matchers.instanceOf;
|
|
|
import static org.hamcrest.Matchers.is;
|
|
|
@@ -801,6 +802,53 @@ public class DataStreamIT extends ESIntegTestCase {
|
|
|
assertSearchHits(searchResponse, "1");
|
|
|
}
|
|
|
|
|
|
+ public void testSearchFilteredAndUnfilteredAlias() throws Exception {
|
|
|
+ putComposableIndexTemplate("id1", List.of("logs-*"));
|
|
|
+ String dataStreamName = "logs-foobar";
|
|
|
+ client().prepareIndex(dataStreamName)
|
|
|
+ .setId("1")
|
|
|
+ .setSource("{\"@timestamp\": \"2022-12-12\", \"type\": \"x\"}", XContentType.JSON)
|
|
|
+ .setOpType(DocWriteRequest.OpType.CREATE)
|
|
|
+ .get();
|
|
|
+ client().prepareIndex(dataStreamName)
|
|
|
+ .setId("2")
|
|
|
+ .setSource("{\"@timestamp\": \"2022-12-12\", \"type\": \"y\"}", XContentType.JSON)
|
|
|
+ .setOpType(DocWriteRequest.OpType.CREATE)
|
|
|
+ .get();
|
|
|
+ refresh(dataStreamName);
|
|
|
+
|
|
|
+ AliasActions addFilteredAliasAction = new AliasActions(AliasActions.Type.ADD).index(dataStreamName)
|
|
|
+ .aliases("foo")
|
|
|
+ .filter(Map.of("term", Map.of("type", Map.of("value", "y"))));
|
|
|
+ AliasActions addUnfilteredAliasAction = new AliasActions(AliasActions.Type.ADD).index(dataStreamName).aliases("bar");
|
|
|
+
|
|
|
+ IndicesAliasesRequest aliasesAddRequest = new IndicesAliasesRequest();
|
|
|
+ aliasesAddRequest.addAliasAction(addFilteredAliasAction);
|
|
|
+ aliasesAddRequest.addAliasAction(addUnfilteredAliasAction);
|
|
|
+ assertAcked(client().admin().indices().aliases(aliasesAddRequest).actionGet());
|
|
|
+ GetAliasesResponse response = client().admin().indices().getAliases(new GetAliasesRequest()).actionGet();
|
|
|
+ assertThat(response.getDataStreamAliases(), hasKey("logs-foobar"));
|
|
|
+ assertThat(
|
|
|
+ response.getDataStreamAliases().get("logs-foobar"),
|
|
|
+ containsInAnyOrder(
|
|
|
+ new DataStreamAlias("bar", List.of("logs-foobar"), null, null),
|
|
|
+ new DataStreamAlias(
|
|
|
+ "foo",
|
|
|
+ List.of("logs-foobar"),
|
|
|
+ null,
|
|
|
+ Map.of("logs-foobar", Map.of("term", Map.of("type", Map.of("value", "y"))))
|
|
|
+ )
|
|
|
+ )
|
|
|
+ );
|
|
|
+
|
|
|
+ // Searching the filtered and unfiltered aliases should return all results (unfiltered):
|
|
|
+ SearchResponse searchResponse = client().prepareSearch("foo", "bar").get();
|
|
|
+ assertSearchHits(searchResponse, "1", "2");
|
|
|
+ // Searching the data stream name and the filtered alias should return all results (unfiltered):
|
|
|
+ searchResponse = client().prepareSearch("foo", dataStreamName).get();
|
|
|
+ assertSearchHits(searchResponse, "1", "2");
|
|
|
+ }
|
|
|
+
|
|
|
public void testRandomDataSteamAliasesUpdate() throws Exception {
|
|
|
putComposableIndexTemplate("id1", List.of("log-*"));
|
|
|
|