Fix NPE if field caps request has a field that exists not in all indices (#24504)

If a field caps request contains a field name that doesn't exist in all indices
the response will be partial and we hide an NPE. The NPE is now fixed but we still
have the problem that we don't pass on errors on the shard level to the user. This will
be fixed in a followup.
This commit is contained in:
Simon Willnauer 2017-05-05 11:56:03 +02:00 committed by GitHub
parent 6e970db533
commit 03267e03da
2 changed files with 46 additions and 2 deletions

View File

@ -80,8 +80,10 @@ public class TransportFieldCapabilitiesIndexAction extends TransportSingleShardA
Map<String, FieldCapabilities> responseMap = new HashMap<>(); Map<String, FieldCapabilities> responseMap = new HashMap<>();
for (String field : fieldNames) { for (String field : fieldNames) {
MappedFieldType ft = mapperService.fullName(field); MappedFieldType ft = mapperService.fullName(field);
FieldCapabilities fieldCap = new FieldCapabilities(field, ft.typeName(), ft.isSearchable(), ft.isAggregatable()); if (ft != null) {
responseMap.put(field, fieldCap); FieldCapabilities fieldCap = new FieldCapabilities(field, ft.typeName(), ft.isSearchable(), ft.isAggregatable());
responseMap.put(field, fieldCap);
}
} }
return new FieldCapabilitiesIndexResponse(shardId.getIndexName(), responseMap); return new FieldCapabilitiesIndexResponse(shardId.getIndexName(), responseMap);
} }

View File

@ -165,3 +165,45 @@ setup:
- match: {fields.number.long.indices: ["test3"]} - match: {fields.number.long.indices: ["test3"]}
- is_false: fields.number.long.non_searchable_indices - is_false: fields.number.long.non_searchable_indices
- is_false: fields.number.long.non_aggregatable_indices - is_false: fields.number.long.non_aggregatable_indices
---
"Mix in non-existing field field caps":
- skip:
version: " - 5.4.0"
reason: this bug has been fixed in 5.4.0
- do:
field_caps:
index: 'test1,test2,test3'
fields: [text, keyword, no_such_field, number, geo]
- match: {fields.text.text.searchable: true}
- match: {fields.text.text.aggregatable: false}
- is_false: fields.text.text.indices
- is_false: fields.text.text.non_searchable_indices
- is_false: fields.text.text.non_aggregatable_indices
- match: {fields.keyword.keyword.searchable: true}
- match: {fields.keyword.keyword.aggregatable: true}
- is_false: fields.text.keyword.indices
- is_false: fields.text.keyword.non_searchable_indices
- is_false: fields.text.keyword.non_aggregatable_indices
- match: {fields.number.double.searchable: true}
- match: {fields.number.double.aggregatable: true}
- match: {fields.number.double.indices: ["test1", "test2"]}
- is_false: fields.number.double.non_searchable_indices
- is_false: fields.number.double.non_aggregatable_indices
- match: {fields.number.long.searchable: true}
- match: {fields.number.long.aggregatable: true}
- match: {fields.number.long.indices: ["test3"]}
- is_false: fields.number.long.non_searchable_indices
- is_false: fields.number.long.non_aggregatable_indices
- match: {fields.geo.geo_point.searchable: true}
- match: {fields.geo.geo_point.aggregatable: true}
- match: {fields.geo.geo_point.indices: ["test1", "test2"]}
- is_false: fields.geo.geo_point.non_searchable_indices
- is_false: fields.geo.geo_point.non_aggregatable_indices
- match: {fields.geo.keyword.searchable: true}
- match: {fields.geo.keyword.aggregatable: true}
- match: {fields.geo.keyword.indices: ["test3"]}
- is_false: fields.geo.keyword.non_searchable_indices
- is_false: fields.geo.keyword.on_aggregatable_indices