From 720b16535012ace55a51d801c3179dc124059f44 Mon Sep 17 00:00:00 2001 From: Luca Cavanna Date: Fri, 25 Nov 2016 10:58:06 +0100 Subject: [PATCH] Search shards to print out aliases array together with alias filter (#21784) With #21738 we added an indices section to the search shards api, that will return the concrete indices hit by the request, and eventually the corresponding alias filter. The java API returns the AliasFilter object, which holds the filter itself and an array of aliases that pointed to the index in the original request. The REST layer doesn't print out the aliases array though. This commit adds the aliases array as well and tests for this. --- .../shards/ClusterSearchShardsResponse.java | 3 ++- .../test/search_shards/10_basic.yaml | 24 ++++++++++++++----- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsResponse.java index 882d082527e..ac48a9bc1d8 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/shards/ClusterSearchShardsResponse.java @@ -115,7 +115,8 @@ public class ClusterSearchShardsResponse extends ActionResponse implements ToXCo String index = entry.getKey(); builder.startObject(index); AliasFilter aliasFilter = entry.getValue(); - if (aliasFilter.getQueryBuilder() != null) { + if (aliasFilter.getAliases().length > 0) { + builder.array("aliases", aliasFilter.getAliases()); builder.field("filter"); aliasFilter.getQueryBuilder().toXContent(builder, params); } diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/search_shards/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/search_shards/10_basic.yaml index 4f7d91f42af..f94ba86d914 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/search_shards/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/search_shards/10_basic.yaml @@ -31,26 +31,38 @@ field: type: text aliases: - test_alias_1: {} - test_alias_2: + test_alias_no_filter: {} + test_alias_filter_1: filter: term: - field : value + field : value1 + test_alias_filter_2: + filter: + term: + field : value2 - do: search_shards: - index: test_alias_1 + index: test_alias_no_filter - length: { shards: 1 } - match: { shards.0.0.index: test_index } - is_true: indices.test_index - is_false: indices.test_index.filter + - is_false: indices.test_index.aliases - do: search_shards: - index: test_alias_2 + index: test_alias_filter_1 - length: { shards: 1 } - match: { shards.0.0.index: test_index } - - match: { indices.test_index: {filter: { term : { field: { value: value, boost: 1.0}}}}} + - match: { indices.test_index: {aliases: [test_alias_filter_1], filter: { term : { field: { value: value1, boost: 1.0}}}}} + - do: + search_shards: + index: ["test_alias_filter_1","test_alias_filter_2"] + + - length: { shards: 1 } + - match: { shards.0.0.index: test_index } + - match: { indices.test_index: {aliases: [test_alias_filter_1, test_alias_filter_2], filter: { bool: { should : [{ term : { field: { value: value1, boost: 1.0}}}, { term : { field: { value: value2, boost: 1.0}}}], adjust_pure_negative: true, boost: 1.0, disable_coord: false }}}}