Skip to content

Commit

Permalink
Add getMapper(field) to Mapper, so both field with multifields and ob…
Browse files Browse the repository at this point in the history
…ject mappers can provide underlying field mappers
  • Loading branch information
carlosdelest committed Mar 21, 2024
1 parent e023a19 commit 05aa06f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public Iterator<Mapper> iterator() {
return Collections.emptyIterator();
}

@Override
public Mapper getMapper(String field) {
return null;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
return builder.startObject(simpleName()).field("type", CONTENT_TYPE).field(Names.PATH, path).endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,17 @@ public Iterator<Mapper> iterator() {
return multiFieldsIterator();
}

@Override
public Mapper getMapper(String field) {
while (iterator().hasNext()) {
Mapper mapper = iterator().next();
if (mapper.simpleName().equals(field)) {
return mapper;
}
}
return null;
}

protected Iterator<Mapper> multiFieldsIterator() {
return Iterators.forArray(multiFields.mappers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,12 @@ public static FieldType freezeAndDeduplicateFieldType(FieldType fieldType) {
* Defines how this mapper counts towards {@link MapperService#INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING}.
*/
public abstract int getTotalFieldsCount();

/**
* Returns a submapper for this mapper, if it exists.
*
* @param field field name from which to obtain the mapper
* @return submapper
*/
public abstract Mapper getMapper(String field);
}

0 comments on commit 05aa06f

Please sign in to comment.