Skip to content

Commit

Permalink
Add nested and object fields to field capabilities response
Browse files Browse the repository at this point in the history
This commit adds nested and object fields to the field capabilities response.

Closes elastic#33237
  • Loading branch information
jimczi committed Sep 18, 2018
1 parent 87cedef commit ee17abf
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ setup:
nested2:
type: float
doc_values: false
level1:
type: nested
properties:
level2:
type: object
properties:
leaf1:
type: text
index: false

- do:
indices.create:
index: test2
Expand All @@ -48,6 +58,15 @@ setup:
nested2:
type: float
doc_values: true
level1:
type: nested
properties:
level2:
type: object
properties:
leaf1:
type: text
index: false
- do:
indices.create:
index: test3
Expand All @@ -64,14 +83,23 @@ setup:
geo:
type: keyword
object:
type: object
type: nested
properties:
nested1 :
type : long
index: false
nested2:
type: keyword
doc_values: false
level1:
type: object
properties:
level2:
type: object
properties:
leaf1:
type: text
index: false

---
"Get simple field caps":
Expand Down Expand Up @@ -112,7 +140,7 @@ setup:
- is_false: fields.geo.keyword.non_searchable_indices
- is_false: fields.geo.keyword.on_aggregatable_indices
---
"Get nested field caps":
"Get leaves field caps":

- do:
field_caps:
Expand Down Expand Up @@ -140,6 +168,47 @@ setup:
- is_false: fields.object\.nested2.keyword.non_aggregatable_indices
- is_false: fields.object\.nested2.keyword.non_searchable_indices
---
"Get object and nested field caps":
- skip:
version: " - 6.99.99"
reason: object and nested fields are returned since 7.0

- do:
field_caps:
index: 'test1,test2,test3'
fields: object*,level1*

- match: {fields.object.object.indices: ["test1", "test2"]}
- match: {fields.object.object.searchable: false}
- match: {fields.object.object.aggregatable: false}
- is_false: fields.object.object.non_aggregatable_indices
- is_false: fields.object.object.non_searchable_indices
- match: {fields.object.nested.indices: ["test3"]}
- match: {fields.object.nested.searchable: false}
- match: {fields.object.nested.aggregatable: false}
- is_false: fields.object.nested.non_aggregatable_indices
- is_false: fields.object.nested.non_searchable_indices
- match: {fields.level1.nested.indices: ["test1", "test2"]}
- match: {fields.level1.nested.searchable: false}
- match: {fields.level1.nested.aggregatable: false}
- is_false: fields.level1.nested.non_aggregatable_indices
- is_false: fields.level1.nested.non_searchable_indices
- match: {fields.level1.object.indices: ["test3"]}
- match: {fields.level1.object.searchable: false}
- match: {fields.level1.object.aggregatable: false}
- is_false: fields.level1.object.non_aggregatable_indices
- is_false: fields.level1.object.non_searchable_indices
- match: {fields.level1\.level2.object.searchable: false}
- match: {fields.level1\.level2.object.aggregatable: false}
- is_false: fields.level1\.level2.object.indices
- is_false: fields.level1\.level2.object.non_aggregatable_indices
- is_false: fields.level1\.level2.object.non_searchable_indices
- match: {fields.level1\.level2\.leaf1.text.searchable: false}
- match: {fields.level1\.level2\.leaf1.text.aggregatable: false}
- is_false: fields.level1\.level2\.leaf1.text.indices
- is_false: fields.level1\.level2\.leaf1.text.non_aggregatable_indices
- is_false: fields.level1\.level2\.leaf1.text..non_searchable_indices
---
"Get prefix field caps":

- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.mapper.MappedFieldType;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.mapper.ObjectMapper;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.threadpool.ThreadPool;
Expand Down Expand Up @@ -88,6 +89,18 @@ protected FieldCapabilitiesIndexResponse shardOperation(final FieldCapabilitiesI
responseMap.put(field, fieldCap);
}
}
// add nested and object fields
int dotIndex = ft.name().indexOf('.');
while (dotIndex > -1) {
String parentField = ft.name().substring(0, dotIndex);
ObjectMapper mapper = mapperService.getObjectMapper(parentField);
if (mapper != null) {
String type = mapper.nested().isNested() ? "nested" : "object";
FieldCapabilities fieldCap = new FieldCapabilities(parentField, type, false, false);
responseMap.put(parentField, fieldCap);
}
dotIndex = ft.name().indexOf('.', dotIndex + 1);
}
}
return new FieldCapabilitiesIndexResponse(shardId.getIndexName(), responseMap);
}
Expand Down

0 comments on commit ee17abf

Please sign in to comment.