Skip to content

Commit

Permalink
[ML] The sort field on get records should default to the record_score (
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
dimitris-athanasiou committed Sep 4, 2018
1 parent 10a2ffb commit ae55a93
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
4 changes: 2 additions & 2 deletions docs/java-rest/high-level/ml/get-records.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()));
}
Expand Down

0 comments on commit ae55a93

Please sign in to comment.