Moved resolveClosestNestedObjectMapper to MapperService
This commit is contained in:
parent
de243493c9
commit
7c53d22ce9
|
@ -763,6 +763,36 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
|
|||
return this.searchQuoteAnalyzer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the closest inherited {@link ObjectMapper} that is nested.
|
||||
*/
|
||||
public ObjectMapper resolveClosestNestedObjectMapper(String fieldName) {
|
||||
int indexOf = fieldName.lastIndexOf('.');
|
||||
if (indexOf == -1) {
|
||||
return null;
|
||||
} else {
|
||||
do {
|
||||
String objectPath = fieldName.substring(0, indexOf);
|
||||
ObjectMappers objectMappers = objectMapper(objectPath);
|
||||
if (objectMappers == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (objectMappers.hasNested()) {
|
||||
for (ObjectMapper objectMapper : objectMappers) {
|
||||
if (objectMapper.nested().isNested()) {
|
||||
return objectMapper;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
indexOf = objectPath.lastIndexOf('.');
|
||||
} while (indexOf != -1);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class SmartNameObjectMapper {
|
||||
private final ObjectMapper mapper;
|
||||
private final DocumentMapper docMapper;
|
||||
|
|
|
@ -214,7 +214,7 @@ public class SortParseElement implements SearchParseElement {
|
|||
throw new ElasticSearchIllegalArgumentException("mapping for explicit nested path is not mapped as nested: [" + nestedPath + "]");
|
||||
}
|
||||
} else {
|
||||
objectMapper = resolveClosestNestedObjectMapper(fieldName, context);
|
||||
objectMapper = context.mapperService().resolveClosestNestedObjectMapper(fieldName);
|
||||
}
|
||||
if (objectMapper != null && objectMapper.nested().isNested()) {
|
||||
Filter rootDocumentsFilter = context.filterCache().cache(NonNestedDocsFilter.INSTANCE);
|
||||
|
@ -238,31 +238,4 @@ public class SortParseElement implements SearchParseElement {
|
|||
return reverse ? SortMode.MAX : SortMode.MIN;
|
||||
}
|
||||
|
||||
private static ObjectMapper resolveClosestNestedObjectMapper(String fieldName, SearchContext context) {
|
||||
int indexOf = fieldName.lastIndexOf('.');
|
||||
if (indexOf == -1) {
|
||||
return null;
|
||||
} else {
|
||||
do {
|
||||
String objectPath = fieldName.substring(0, indexOf);
|
||||
ObjectMappers objectMappers = context.mapperService().objectMapper(objectPath);
|
||||
if (objectMappers == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (objectMappers.hasNested()) {
|
||||
for (ObjectMapper objectMapper : objectMappers) {
|
||||
if (objectMapper.nested().isNested()) {
|
||||
return objectMapper;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
indexOf = objectPath.lastIndexOf('.');
|
||||
} while (indexOf != -1);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue