-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid deprecation warning when running the ML datafeed extractor. #31463
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,7 +103,13 @@ public Object[] value(SearchHit hit) { | |
if (value.length != 1) { | ||
return value; | ||
} | ||
value[0] = ((BaseDateTime) value[0]).getMillis(); | ||
if (value[0] instanceof BaseDateTime) { // script field | ||
value[0] = ((BaseDateTime) value[0]).getMillis(); | ||
} else if (value[0] instanceof String) { // doc_value field with the epoch_millis format | ||
value[0] = Long.parseLong((String) value[0]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the value going to be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is correct. |
||
} else { | ||
throw new IllegalStateException("Unexpected value for a time field: " + value[0].getClass()); | ||
} | ||
return value; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
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 @@ private SearchRequestBuilder buildSearchRequest(long start) { | |
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the default format for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On 6.x, the default is to keep returning a date time object for backward compatibility. If you use In 7.x I plan to make |
||
} | ||
} | ||
String[] sourceFields = context.extractedFields.getSourceFields(); | ||
if (sourceFields.length == 0) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we swap the order of those
instanceof
checks? The time value will be coming from a doc_value way more often than from a script field, so I'd rather do the most useful check first.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍