|
56 | 56 | import org.opensearch.common.unit.TimeValue;
|
57 | 57 | import org.opensearch.common.util.FeatureFlags;
|
58 | 58 | import org.opensearch.common.util.LocaleUtils;
|
| 59 | +import org.opensearch.core.xcontent.XContentBuilder; |
59 | 60 | import org.opensearch.index.compositeindex.datacube.DimensionType;
|
60 | 61 | import org.opensearch.index.fielddata.IndexFieldData;
|
61 | 62 | import org.opensearch.index.fielddata.IndexNumericFieldData.NumericType;
|
@@ -819,16 +820,29 @@ public Long getNullValue() {
|
819 | 820 | }
|
820 | 821 |
|
821 | 822 | @Override
|
822 |
| - protected String[] deriveSource(LeafReader leafReader, int docId) throws IOException { |
| 823 | + protected void deriveSource(XContentBuilder builder, LeafReader leafReader, int docId) throws IOException { |
| 824 | + validateDerivedSourceAllowed(); |
823 | 825 | SortedNumericDocValues sortedNumericDocValues = leafReader.getSortedNumericDocValues(name());
|
824 |
| - if (sortedNumericDocValues.advanceExact(docId)) { |
| 826 | + if (sortedNumericDocValues != null && sortedNumericDocValues.advanceExact(docId)) { |
825 | 827 | int size = sortedNumericDocValues.docValueCount();
|
826 | 828 | String[] values = new String[size];
|
827 | 829 | DateFormatter dateFormatter = fieldType().dateTimeFormatter;
|
828 | 830 | for (int i = 0; i < size; i++)
|
829 | 831 | values[i] = dateFormatter.formatMillis(sortedNumericDocValues.nextValue());
|
830 |
| - return values; |
| 832 | + if (size == 1) { |
| 833 | + builder.field(name(), values[0]); |
| 834 | + } else { |
| 835 | + builder.array(name(), values); |
| 836 | + } |
| 837 | + } |
| 838 | + } |
| 839 | + |
| 840 | + private void validateDerivedSourceAllowed() { |
| 841 | + if (this.copyTo() != null && !this.copyTo().copyToFields().isEmpty()) { |
| 842 | + throw new UnsupportedOperationException("Unable to derive source for fields with copyTo parameter set"); |
| 843 | + } |
| 844 | + if (mappedFieldType.hasDocValues() == false) { |
| 845 | + throw new UnsupportedOperationException("Unable to derive source for fields with docValues disabled"); |
831 | 846 | }
|
832 |
| - return null; |
833 | 847 | }
|
834 | 848 | }
|
0 commit comments