From ae55a931390a6f24da89a01483ac5eb1d6d21ee2 Mon Sep 17 00:00:00 2001 From: Dimitris Athanasiou Date: Tue, 4 Sep 2018 11:38:24 +0100 Subject: [PATCH] [ML] The sort field on get records should default to the record_score (#33358) This is not changing the behaviour as when the sort field was set to `influencer_score` the secondary sort would be used and that was using the `record_score` at the highest priority. --- docs/java-rest/high-level/ml/get-records.asciidoc | 4 ++-- .../xpack/core/ml/action/GetRecordsAction.java | 3 +-- .../xpack/ml/rest/results/RestGetRecordsAction.java | 6 ++---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/docs/java-rest/high-level/ml/get-records.asciidoc b/docs/java-rest/high-level/ml/get-records.asciidoc index 40cc185225ee8..f8a88f34d3379 100644 --- a/docs/java-rest/high-level/ml/get-records.asciidoc +++ b/docs/java-rest/high-level/ml/get-records.asciidoc @@ -54,11 +54,11 @@ include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-r -------------------------------------------------- include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-sort] -------------------------------------------------- -<1> The field to sort records on. Defaults to `influencer_score`. +<1> The field to sort records on. Defaults to `record_score`. ["source","java",subs="attributes,callouts,macros"] -------------------------------------------------- -include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-end] +include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-start] -------------------------------------------------- <1> Records with timestamps on or after this time will be returned. diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetRecordsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetRecordsAction.java index 586a40af81a29..88c263ba6cbae 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetRecordsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetRecordsAction.java @@ -23,7 +23,6 @@ import org.elasticsearch.xpack.core.ml.action.util.QueryPage; import org.elasticsearch.xpack.core.ml.job.config.Job; import org.elasticsearch.xpack.core.ml.job.results.AnomalyRecord; -import org.elasticsearch.xpack.core.ml.job.results.Influencer; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import java.io.IOException; @@ -84,7 +83,7 @@ public static Request parseRequest(String jobId, XContentParser parser) { private boolean excludeInterim = false; private PageParams pageParams = new PageParams(); private double recordScoreFilter = 0.0; - private String sort = Influencer.INFLUENCER_SCORE.getPreferredName(); + private String sort = RECORD_SCORE_FILTER.getPreferredName(); private boolean descending = true; public Request() { diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java index 4c5fc6c33460a..c7e571f2cdce3 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java @@ -12,11 +12,10 @@ import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.xpack.ml.MachineLearning; import org.elasticsearch.xpack.core.ml.action.GetRecordsAction; import org.elasticsearch.xpack.core.ml.action.util.PageParams; import org.elasticsearch.xpack.core.ml.job.config.Job; -import org.elasticsearch.xpack.core.ml.job.results.AnomalyRecord; +import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; @@ -54,8 +53,7 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient request.setRecordScore( Double.parseDouble(restRequest.param(GetRecordsAction.Request.RECORD_SCORE_FILTER.getPreferredName(), String.valueOf(request.getRecordScoreFilter())))); - request.setSort(restRequest.param(GetRecordsAction.Request.SORT.getPreferredName(), - AnomalyRecord.RECORD_SCORE.getPreferredName())); + request.setSort(restRequest.param(GetRecordsAction.Request.SORT.getPreferredName(), request.getSort())); request.setDescending(restRequest.paramAsBoolean(GetRecordsAction.Request.DESCENDING.getPreferredName(), request.isDescending())); }