Skip to content

Skip over metadata fields in the field retrieval API. #58710

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static FieldValueRetriever create(MapperService mapperService,

Collection<String> concreteFields = mapperService.simpleMatchToFullName(fieldPattern);
for (String field : concreteFields) {
if (fieldMappers.getMapper(field) != null) {
if (fieldMappers.getMapper(field) != null && mapperService.isMetadataField(field) == false) {
Set<String> sourcePath = mapperService.sourcePath(field);
fields.add(new FieldContext(field, sourcePath, format));
}
Expand All @@ -62,6 +62,7 @@ public static FieldValueRetriever create(MapperService mapperService,
return new FieldValueRetriever(fieldMappers, fields);
}


private FieldValueRetriever(DocumentFieldMappers fieldMappers,
List<FieldContext> fieldContexts) {
this.fieldMappers = fieldMappers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,29 @@ public void testNonExistentField() throws IOException {
assertThat(fields.size(), equalTo(0));
}

public void testMetadataFields() throws IOException {
MapperService mapperService = createMapperService();
XContentBuilder source = XContentFactory.jsonBuilder().startObject()
.field("field", "value")
.endObject();

Map<String, DocumentField> fields = retrieveFields(mapperService, source, "_routing");
assertTrue(fields.isEmpty());
}

public void testRetrieveAllFields() throws IOException {
MapperService mapperService = createMapperService();
XContentBuilder source = XContentFactory.jsonBuilder().startObject()
.field("field", "value")
.startObject("object")
.field("field", "other-value")
.endObject()
.endObject();

Map<String, DocumentField> fields = retrieveFields(mapperService, source, "*");
assertThat(fields.size(), equalTo(2));
}

public void testArrayValueMappers() throws IOException {
MapperService mapperService = createMapperService();

Expand Down