|
@@ -9,12 +9,15 @@
|
|
|
package org.elasticsearch.index.mapper.size;
|
|
|
|
|
|
import org.elasticsearch.common.Explicit;
|
|
|
+import org.elasticsearch.index.mapper.DocValueFetcher;
|
|
|
import org.elasticsearch.index.mapper.FieldMapper;
|
|
|
import org.elasticsearch.index.mapper.MappedFieldType;
|
|
|
import org.elasticsearch.index.mapper.MetadataFieldMapper;
|
|
|
import org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType;
|
|
|
import org.elasticsearch.index.mapper.NumberFieldMapper.NumberType;
|
|
|
import org.elasticsearch.index.mapper.ParseContext;
|
|
|
+import org.elasticsearch.index.mapper.ValueFetcher;
|
|
|
+import org.elasticsearch.index.query.SearchExecutionContext;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.List;
|
|
@@ -42,12 +45,26 @@ public class SizeFieldMapper extends MetadataFieldMapper {
|
|
|
|
|
|
@Override
|
|
|
public SizeFieldMapper build() {
|
|
|
- return new SizeFieldMapper(enabled.getValue(), new NumberFieldType(NAME, NumberType.INTEGER));
|
|
|
+ return new SizeFieldMapper(enabled.getValue(), new SizeFieldType());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static class SizeFieldType extends NumberFieldType {
|
|
|
+ SizeFieldType() {
|
|
|
+ super(NAME, NumberType.INTEGER);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ValueFetcher valueFetcher(SearchExecutionContext context, String format) {
|
|
|
+ if (hasDocValues() == false) {
|
|
|
+ return lookup -> List.of();
|
|
|
+ }
|
|
|
+ return new DocValueFetcher(docValueFormat(format, null), context.getForField(this));
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public static final TypeParser PARSER = new ConfigurableTypeParser(
|
|
|
- c -> new SizeFieldMapper(new Explicit<>(false, false), new NumberFieldType(NAME, NumberType.INTEGER)),
|
|
|
+ c -> new SizeFieldMapper(new Explicit<>(false, false), new SizeFieldType()),
|
|
|
c -> new Builder()
|
|
|
);
|
|
|
|