Avoid deprecation warning when running the ML datafeed extractor. (#31463)

In #29639 we added a `format` option to doc-value fields and deprecated usage
of doc-value fields without a format so that we could migrate doc-value fields
to use the format that comes with the mappings by default. However I missed to
fix the machine-learning datafeed extractor.
This commit is contained in:
Adrien Grand 2018-06-22 13:46:48 +02:00 committed by GitHub
parent eade161894
commit 8ae2049889
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -103,7 +103,13 @@ abstract class ExtractedField {
if (value.length != 1) {
return value;
}
value[0] = ((BaseDateTime) value[0]).getMillis();
if (value[0] instanceof String) { // doc_value field with the epoch_millis format
value[0] = Long.parseLong((String) value[0]);
} else if (value[0] instanceof BaseDateTime) { // script field
value[0] = ((BaseDateTime) value[0]).getMillis();
} else {
throw new IllegalStateException("Unexpected value for a time field: " + value[0].getClass());
}
return value;
}
}

View File

@ -20,6 +20,7 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.script.Script;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.fetch.StoredFieldsContext;
import org.elasticsearch.search.fetch.subphase.DocValueFieldsContext;
import org.elasticsearch.search.sort.SortOrder;
import org.elasticsearch.xpack.core.ClientHelper;
import org.elasticsearch.xpack.core.ml.datafeed.extractor.DataExtractor;
@ -47,6 +48,7 @@ class ScrollDataExtractor implements DataExtractor {
private static final Logger LOGGER = Loggers.getLogger(ScrollDataExtractor.class);
private static final TimeValue SCROLL_TIMEOUT = new TimeValue(30, TimeUnit.MINUTES);
private static final String EPOCH_MILLIS_FORMAT = "epoch_millis";
private final Client client;
private final ScrollDataExtractorContext context;
@ -115,7 +117,11 @@ class ScrollDataExtractor implements DataExtractor {
context.query, context.extractedFields.timeField(), start, context.end));
for (String docValueField : context.extractedFields.getDocValueFields()) {
searchRequestBuilder.addDocValueField(docValueField);
if (docValueField.equals(context.extractedFields.timeField())) {
searchRequestBuilder.addDocValueField(docValueField, EPOCH_MILLIS_FORMAT);
} else {
searchRequestBuilder.addDocValueField(docValueField, DocValueFieldsContext.USE_DEFAULT_FORMAT);
}
}
String[] sourceFields = context.extractedFields.getSourceFields();
if (sourceFields.length == 0) {