Skip to content

Commit 1457b07

Browse files
[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.
1 parent 84eaac7 commit 1457b07

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

docs/java-rest/high-level/ml/get-records.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-r
5454
--------------------------------------------------
5555
include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-sort]
5656
--------------------------------------------------
57-
<1> The field to sort records on. Defaults to `influencer_score`.
57+
<1> The field to sort records on. Defaults to `record_score`.
5858

5959
["source","java",subs="attributes,callouts,macros"]
6060
--------------------------------------------------
61-
include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-end]
61+
include-tagged::{doc-tests}/MlClientDocumentationIT.java[x-pack-ml-get-records-start]
6262
--------------------------------------------------
6363
<1> Records with timestamps on or after this time will be returned.
6464

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetRecordsAction.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.xpack.core.ml.action.util.QueryPage;
2424
import org.elasticsearch.xpack.core.ml.job.config.Job;
2525
import org.elasticsearch.xpack.core.ml.job.results.AnomalyRecord;
26-
import org.elasticsearch.xpack.core.ml.job.results.Influencer;
2726
import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper;
2827

2928
import java.io.IOException;
@@ -79,7 +78,7 @@ public static Request parseRequest(String jobId, XContentParser parser) {
7978
private boolean excludeInterim = false;
8079
private PageParams pageParams = new PageParams();
8180
private double recordScoreFilter = 0.0;
82-
private String sort = Influencer.INFLUENCER_SCORE.getPreferredName();
81+
private String sort = RECORD_SCORE_FILTER.getPreferredName();
8382
private boolean descending = true;
8483

8584
public Request() {

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
import org.elasticsearch.rest.RestController;
1313
import org.elasticsearch.rest.RestRequest;
1414
import org.elasticsearch.rest.action.RestToXContentListener;
15-
import org.elasticsearch.xpack.ml.MachineLearning;
1615
import org.elasticsearch.xpack.core.ml.action.GetRecordsAction;
1716
import org.elasticsearch.xpack.core.ml.action.util.PageParams;
1817
import org.elasticsearch.xpack.core.ml.job.config.Job;
19-
import org.elasticsearch.xpack.core.ml.job.results.AnomalyRecord;
18+
import org.elasticsearch.xpack.ml.MachineLearning;
2019

2120
import java.io.IOException;
2221

@@ -54,8 +53,7 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
5453
request.setRecordScore(
5554
Double.parseDouble(restRequest.param(GetRecordsAction.Request.RECORD_SCORE_FILTER.getPreferredName(),
5655
String.valueOf(request.getRecordScoreFilter()))));
57-
request.setSort(restRequest.param(GetRecordsAction.Request.SORT.getPreferredName(),
58-
AnomalyRecord.RECORD_SCORE.getPreferredName()));
56+
request.setSort(restRequest.param(GetRecordsAction.Request.SORT.getPreferredName(), request.getSort()));
5957
request.setDescending(restRequest.paramAsBoolean(GetRecordsAction.Request.DESCENDING.getPreferredName(),
6058
request.isDescending()));
6159
}

0 commit comments

Comments
 (0)