Skip to content

[ML] The sort field on get records should default to the record_score #33358

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -79,7 +78,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