[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.
This commit is contained in:
Dimitris Athanasiou 2018-09-04 11:38:24 +01:00 committed by GitHub
parent 84eaac79d7
commit 1457b07a06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 8 deletions

View File

@ -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.

View File

@ -23,7 +23,6 @@ import org.elasticsearch.xpack.core.ml.action.util.PageParams;
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;
@ -79,7 +78,7 @@ public class GetRecordsAction extends Action<GetRecordsAction.Response> {
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() {

View File

@ -12,11 +12,10 @@ import org.elasticsearch.rest.BaseRestHandler;
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 @@ public class RestGetRecordsAction extends BaseRestHandler {
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()));
}