Skip to content

Commit

Permalink
[ML] Tolerate total_search_time_ms not mapped in get datafeed stats (#…
Browse files Browse the repository at this point in the history
…46432)

ML users who upgrade from versions prior to 7.4 to 7.4 or later
will have ML results indices that do not have mappings for the
total_search_time_ms field.  Therefore, when searching these
indices we must tolerate this field not having a mapping.

Fixes #46437
  • Loading branch information
droberts195 committed Sep 6, 2019
1 parent 25d2e65 commit a08cfcb
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ private SearchRequestBuilder createLatestDatafeedTimingStatsSearch(String indexN
.setSize(1)
.setIndicesOptions(IndicesOptions.lenientExpandOpen())
.setQuery(QueryBuilders.idsQuery().addIds(DatafeedTimingStats.documentId(jobId)))
.addSort(SortBuilders.fieldSort(DatafeedTimingStats.TOTAL_SEARCH_TIME_MS.getPreferredName()).order(SortOrder.DESC));
.addSort(SortBuilders.fieldSort(DatafeedTimingStats.TOTAL_SEARCH_TIME_MS.getPreferredName())
.unmappedType("double").order(SortOrder.DESC));
}

public void getAutodetectParams(Job job, Consumer<AutodetectParams> consumer, Consumer<Exception> errorHandler) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,62 @@ setup:
- match: { datafeeds.0.state: "stopped"}
- match: { datafeeds.1.datafeed_id: "datafeed-2"}
- match: { datafeeds.1.state: "stopped"}

---
"Test get datafeed stats when total_search_time_ms mapping is missing":

- skip:
features: headers

- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
indices.delete:
index: ".ml-anomalies-shared"

- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
indices.create:
index: ".ml-special-index-to-avoid-picking-up-template"
body:
mappings:
properties:
timestamp:
type: date

- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
indices.put_alias:
index: ".ml-special-index-to-avoid-picking-up-template"
name: ".ml-anomalies-get-datafeed-stats-1"

- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
indices.put_alias:
index: ".ml-special-index-to-avoid-picking-up-template"
name: ".ml-anomalies-.write-get-datafeed-stats-1"

- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
indices.put_alias:
index: ".ml-special-index-to-avoid-picking-up-template"
name: ".ml-anomalies-get-datafeed-stats-2"

- do:
headers:
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
indices.put_alias:
index: ".ml-special-index-to-avoid-picking-up-template"
name: ".ml-anomalies-.write-get-datafeed-stats-2"

- do:
ml.get_datafeed_stats: {}
- match: { count: 2 }
- match: { datafeeds.0.datafeed_id: "datafeed-1"}
- match: { datafeeds.0.state: "stopped"}
- match: { datafeeds.1.datafeed_id: "datafeed-2"}
- match: { datafeeds.1.state: "stopped"}

0 comments on commit a08cfcb

Please sign in to comment.