Skip to content
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

[ML] Add new geo_results.(actual_point|typical_point) fields for lat_long results #47050

Conversation

benwtrent
Copy link
Member

@benwtrent benwtrent commented Sep 24, 2019

This PR adds a new geo_results.* field for actual/typical fields in the anomaly record storage, and the anomaly cause storage.

I did not opt for these two items to be returned within the HLRC client and to have the HLRC have a helper method that transforms the two points to a GeoPoint if the function is lat_long.

The purpose behind this change is so that lan_long anomaly records can be trivially visible within Kibana Maps. Additionally, helpful queries and inspections can be made against the records as well with the plethora of geo capabilities within the stack.

@elasticmachine
Copy link
Collaborator

Pinging @elastic/ml-core

@benwtrent benwtrent added v7.6.0 and removed v7.5.0 labels Oct 16, 2019
@benwtrent
Copy link
Member Author

@elasticmachine update branch

@benwtrent
Copy link
Member Author

@alexfrancoeur Thought you would enjoy this. This PR adds geo_point mappings for anomaly detection jobs. Just needed to add a index pattern to include the .ml-anomalies-*
and the results of a lat_long detector are displayable in maps

image

@benwtrent benwtrent changed the title [ML] Add new (actual|typical)_geo field for lat_lon results [ML] Add new geo.(actual|typical) fields for lat_lon results Oct 25, 2019
@alexfrancoeur
Copy link

@benwtrent your assumption was correct, I absolutely love this 😄❤️ ❤️ This type of functionality is the perfect way to bring in a streamlined approach for creating ML jobs from within the maps application. Ideally, our end users won't have to know anything about the .ml-anomalies-* index.

Now I'm curious, would be it possible to support geo_shape in the future?

cc: @elastic/kibana-gis

@benwtrent
Copy link
Member Author

@alexfrancoeur the lat_long detector is the only detector that generates records that conform to geo typed data. And it only generates points. I opted for geo_point as it still seems to be the broader accepted and usable value across the stack (more agg/search support, etc.).

As for more detectors in the future that look at other geo data (shapes, lines, etc.) that is definitely within the realm of possibility, just not in the near future :)

@alexfrancoeur
Copy link

Thanks for the quick response! Agreed that points are more heavily used today. If we choose to introduce a streamlined UX for geo_point anomaly detection from Elastic Maps, it'll be interesting to see how many requests we get for geo_shape. geo_shape support definitely feels more like a roadmap feature, but thought I'd ask 😄

@benwtrent benwtrent changed the title [ML] Add new geo.(actual|typical) fields for lat_lon results [ML] Add new geo_results.(actual|typical) fields for lat_lon results Oct 25, 2019
Copy link
Contributor

@droberts195 droberts195 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ease of getting ML lat_long anomalies onto maps is great.

My main comment is about whether the fields should be generated in the C++ code. I think we should ask for more opinions about this.

builder.endObject();
return builder;
}

private void writeDoublesAsGeoPoint(XContentBuilder builder, String fieldName, List<Double> doubles) throws IOException {
if (doubles != null) {
//TODO should we fail if `doubles` is not an array of length 2?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an internal assertion as you've got it now is best. Throwing an exception here would mean it was impossible to get anything from the results endpoint.

However, see my main comment because that would render this a moot point as the whole method could be deleted.

Copy link
Contributor

@droberts195 droberts195 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with the caveat that you should check with the ES core infra team about changing the method visibility in XContentBuilder. (If they don't like it there's an easy change that can be made to this PR to avoid it.)

@@ -850,7 +850,7 @@ private XContentBuilder value(ToXContent value) throws IOException {
return value(value, ToXContent.EMPTY_PARAMS);
}

private XContentBuilder value(ToXContent value, ToXContent.Params params) throws IOException {
public XContentBuilder value(ToXContent value, ToXContent.Params params) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really see why making this public would be a problem given what it does and the other public methods nearby. However, you should probably run this by somebody in the ES core infra team before merging.

There is a simple way to avoid making this public - see my next comment.

builder.field(CAUSES.getPreferredName(), causes);
builder.startArray(CAUSES.getPreferredName());
for (AnomalyCause cause : causes) {
builder.value(cause, params);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line could be changed to cause.toXContent(builder, params); to avoid the need to change method visibility in the X-Content builder.

@benwtrent
Copy link
Member Author

run elasticsearch-ci/2

@benwtrent benwtrent changed the title [ML] Add new geo_results.(actual|typical) fields for lat_lon results [ML] Add new geo_results.(actual_point|typical_point) fields for lat_lon results Nov 11, 2019
@benwtrent benwtrent changed the title [ML] Add new geo_results.(actual_point|typical_point) fields for lat_lon results [ML] Add new geo_results.(actual_point|typical_point) fields for lat_long results Nov 11, 2019
@benwtrent benwtrent merged commit ee8853f into elastic:master Nov 11, 2019
@benwtrent benwtrent deleted the feature/ml-add-geo-mapping-for-anomaly-records branch November 11, 2019 18:21
benwtrent added a commit to benwtrent/elasticsearch that referenced this pull request Nov 11, 2019
…_long` results (elastic#47050)

[ML] Add new geo_results.(actual_point|typical_point) fields for `lat_long` results (elastic#47050)

Related PR: elastic/ml-cpp#809
benwtrent added a commit to elastic/ml-cpp that referenced this pull request Nov 11, 2019
Adds new geo_point formatted fields for Java side consumption. These are only written if we have actual|typical values that have length of 2, and are using a lat_long function.

This is my first PR against this repo, let me know if I missed something.

related elastic/elasticsearch#47050
benwtrent added a commit that referenced this pull request Nov 11, 2019
…r `lat_long` results (#47050) (#48958)

* [ML] Add new geo_results.(actual_point|typical_point) fields for `lat_long` results (#47050)

[ML] Add new geo_results.(actual_point|typical_point) fields for `lat_long` results (#47050)

Related PR: elastic/ml-cpp#809

* adjusting bwc version
benwtrent added a commit to elastic/ml-cpp that referenced this pull request Nov 11, 2019
Adds new geo_point formatted fields for Java side consumption. These are only written if we have actual|typical values that have length of 2, and are using a lat_long function.

This is my first PR against this repo, let me know if I missed something.

related elastic/elasticsearch#47050
@alexfrancoeur
Copy link

wooo! Nice one @benwtrent

debadair pushed a commit to debadair/elasticsearch that referenced this pull request Nov 13, 2019
…_long` results (elastic#47050)

[ML] Add new geo_results.(actual_point|typical_point) fields for `lat_long` results (elastic#47050)

Related PR: elastic/ml-cpp#809
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants