-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[ML] Adding support for geo_shape, geo_centroid, geo_point in datafeeds #42969
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
Changes from 1 commit
def0018
a03fb11
b43f0ee
2374df1
a348e3e
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 |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ | |
| import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation; | ||
| import org.elasticsearch.search.aggregations.bucket.SingleBucketAggregation; | ||
| import org.elasticsearch.search.aggregations.bucket.histogram.Histogram; | ||
| import org.elasticsearch.search.aggregations.metrics.GeoCentroid; | ||
| import org.elasticsearch.search.aggregations.metrics.Max; | ||
| import org.elasticsearch.search.aggregations.metrics.NumericMetricsAggregation; | ||
| import org.elasticsearch.search.aggregations.metrics.Percentile; | ||
|
|
@@ -275,14 +276,16 @@ private void processBucket(MultiBucketsAggregation bucketAgg, boolean addField) | |
| } | ||
|
|
||
| /** | ||
| * Adds a leaf key-value. It returns the name of the key added or {@code null} when nothing was added. | ||
| * Adds a leaf key-value. It returns {@code true} if the key added or {@code false} when nothing was added. | ||
| * Non-finite metric values are not added. | ||
| */ | ||
| private boolean processLeaf(Aggregation agg) throws IOException { | ||
| if (agg instanceof NumericMetricsAggregation.SingleValue) { | ||
| return processSingleValue((NumericMetricsAggregation.SingleValue) agg); | ||
| } else if (agg instanceof Percentiles) { | ||
| return processPercentiles((Percentiles) agg); | ||
| } else if (agg instanceof GeoCentroid){ | ||
| return processGeoCentroid((GeoCentroid) agg); | ||
| } else { | ||
| throw new IllegalArgumentException("Unsupported aggregation type [" + agg.getName() + "]"); | ||
| } | ||
|
|
@@ -300,6 +303,14 @@ private boolean addMetricIfFinite(String key, double value) { | |
| return false; | ||
| } | ||
|
|
||
| private boolean processGeoCentroid(GeoCentroid agg) { | ||
| if (agg.count() > 0) { | ||
|
||
| keyValuePairs.put(agg.getName(), agg.centroid().getLat() + "," + agg.centroid().getLon()); | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| private boolean processPercentiles(Percentiles percentiles) throws IOException { | ||
| Iterator<Percentile> percentileIterator = percentiles.iterator(); | ||
| boolean aggregationAdded = addMetricIfFinite(percentiles.getName(), percentileIterator.next().getValue()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,6 +87,9 @@ protected ExtractedField detect(String field) { | |
| : ExtractedField.ExtractionMethod.SOURCE; | ||
| } | ||
| } | ||
| if (isFieldOfType(field, "geo_point") || isFieldOfType(field, "geo_shape")) { | ||
| return ExtractedField.newGeoField(field, internalField, method); | ||
|
||
| } | ||
| return ExtractedField.newField(field, internalField, method); | ||
| } | ||
|
|
||
|
|
||
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.
I debated looking at buckets/records as well, but opted out of it as I did not want a flaky test. Could add some more checks here if they are deemed necessary.