Skip to content

Commit

Permalink
Skip over metadata fields in the field retrieval API. (#58710)
Browse files Browse the repository at this point in the history
This avoids unnecessary lookups, since metadata fields don't have _source
values.
  • Loading branch information
jtibshirani committed Jul 14, 2020
1 parent 680d49c commit b704f0e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
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

0 comments on commit b704f0e

Please sign in to comment.