Skip to content

Commit 6a55390

Browse files
committed
Fix serialization of empty field capabilities response
When no response are required (no indices match the requested patterns) the empty response throws an NPE in the transport serialization (writeTo).
1 parent f097446 commit 6a55390

File tree

6 files changed

+14
-6
lines changed

6 files changed

+14
-6
lines changed

server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilities.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,14 @@ public String getName() {
166166
}
167167

168168
/**
169-
* Whether this field is indexed for search on all indices.
169+
* Whether this field can be aggregated on all indices.
170170
*/
171171
public boolean isAggregatable() {
172172
return isAggregatable;
173173
}
174174

175175
/**
176-
* Whether this field can be aggregated on all indices.
176+
* Whether this field is indexed for search on all indices.
177177
*/
178178
public boolean isSearchable() {
179179
return isSearchable;

server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesRequest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ public String[] fields() {
111111
}
112112

113113
/**
114-
*
115114
* The list of indices to lookup
116115
*/
117116
public FieldCapabilitiesRequest indices(String... indices) {

server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ private FieldCapabilitiesResponse(Map<String, Map<String, FieldCapabilities>> re
6565
*/
6666
FieldCapabilitiesResponse() {
6767
this.responseMap = Collections.emptyMap();
68+
this.indexResponses = Collections.emptyList();
6869
}
6970

7071
/**

server/src/main/java/org/elasticsearch/client/Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ public interface Client extends ElasticsearchClient, Releasable {
455455
/**
456456
* Builder for the field capabilities request.
457457
*/
458-
FieldCapabilitiesRequestBuilder prepareFieldCaps();
458+
FieldCapabilitiesRequestBuilder prepareFieldCaps(String... indices);
459459

460460
/**
461461
* An action that returns the field capabilities from the provided request

server/src/main/java/org/elasticsearch/client/support/AbstractClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,8 @@ public ActionFuture<FieldCapabilitiesResponse> fieldCaps(FieldCapabilitiesReques
651651
}
652652

653653
@Override
654-
public FieldCapabilitiesRequestBuilder prepareFieldCaps() {
655-
return new FieldCapabilitiesRequestBuilder(this, FieldCapabilitiesAction.INSTANCE);
654+
public FieldCapabilitiesRequestBuilder prepareFieldCaps(String... indices) {
655+
return new FieldCapabilitiesRequestBuilder(this, FieldCapabilitiesAction.INSTANCE, indices);
656656
}
657657

658658
static class Admin implements AdminClient {

server/src/test/java/org/elasticsearch/search/fieldcaps/FieldCapabilitiesIT.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.elasticsearch.action.fieldcaps.FieldCapabilities;
2323
import org.elasticsearch.action.fieldcaps.FieldCapabilitiesResponse;
24+
import org.elasticsearch.action.support.IndicesOptions;
2425
import org.elasticsearch.common.xcontent.XContentBuilder;
2526
import org.elasticsearch.common.xcontent.XContentFactory;
2627
import org.elasticsearch.plugins.MapperPlugin;
@@ -148,4 +149,11 @@ public void testFieldAliasFilteringWithWildcard() {
148149
assertEquals(1, response.get().size());
149150
assertTrue(response.get().containsKey("distance"));
150151
}
152+
153+
public void testEmptyIndexPattern() {
154+
FieldCapabilitiesResponse response = client().prepareFieldCaps("empty_index_pattern*")
155+
.setFields("*")
156+
.execute().actionGet();
157+
assertEquals(0, response.get().size());
158+
}
151159
}

0 commit comments

Comments
 (0)