From cbbc3cfe2051fbc761021b21792b3f05605b6ed1 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Wed, 5 Apr 2017 13:48:06 +0200 Subject: [PATCH] [ML] Slightly adjust JobProvider#getAutodetectParams(...) Original commit: elastic/x-pack-elasticsearch@2aaf618d7864f0e9667f0ad553412dfd0dc05d2c --- .../xpack/ml/job/persistence/JobProvider.java | 26 ++++++++++--------- .../integration/MlDistributedFailureIT.java | 3 ++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobProvider.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobProvider.java index fa71625ede0..9ceacf423dc 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobProvider.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/job/persistence/JobProvider.java @@ -260,13 +260,10 @@ public class JobProvider { msearch.execute(ActionListener.wrap( response -> { - for (MultiSearchResponse.Item itemResponse : response.getResponses()) { + for (int i = 0; i < response.getResponses().length; i++) { + MultiSearchResponse.Item itemResponse = response.getResponses()[i]; if (itemResponse.isFailure()) { - if (itemResponse.getFailure() instanceof IndexNotFoundException == false) { - throw itemResponse.getFailure(); - } else { - // Ignore IndexNotFoundException; AutodetectParamsBuilder has defaults for new jobs - } + errorHandler.accept(itemResponse.getFailure()); } else { SearchResponse searchResponse = itemResponse.getResponse(); ShardSearchFailure[] shardFailures = searchResponse.getShardFailures(); @@ -280,12 +277,16 @@ public class JobProvider { errorHandler.accept(new ElasticsearchException("[" + jobId + "] Search request encountered [" + unavailableShards + "] unavailable shards")); } else { - SearchHit[] hits = searchResponse.getHits().getHits(); - if (hits.length == 1) { - parseAutodetectParamSearchHit(paramsBuilder, hits[0], errorHandler); - } else if (hits.length > 1) { - errorHandler.accept(new IllegalStateException("Got [" - + hits.length + "] even though search size was 1")); + SearchHits hits = searchResponse.getHits(); + long totalHits = hits.getTotalHits(); + if (totalHits == 0) { + SearchRequest searchRequest = msearch.request().requests().get(i); + LOGGER.debug("Found 0 hits for [{}/{}]", searchRequest.indices(), searchRequest.types()); + } else if (totalHits == 1) { + parseAutodetectParamSearchHit(paramsBuilder, hits.getAt(0), errorHandler); + } else if (totalHits > 1) { + errorHandler.accept(new IllegalStateException("Expected total hits 0 or 1, but got [" + totalHits + + "] total hits")); } } } @@ -298,6 +299,7 @@ public class JobProvider { private SearchRequestBuilder createDocIdSearch(String index, String type, String id) { return client.prepareSearch(index).setSize(1) + .setIndicesOptions(IndicesOptions.lenientExpandOpen()) .setQuery(QueryBuilders.idsQuery(type).addIds(id)) .setRouting(id); } diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java index dadf50b6ffb..670a2024cef 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/integration/MlDistributedFailureIT.java @@ -38,7 +38,8 @@ import java.io.IOException; import java.util.Collections; import java.util.concurrent.TimeUnit; -@TestLogging("org.elasticsearch.xpack.ml.datafeed:DEBUG,org.elasticsearch.xpack.ml.action:DEBUG") +@TestLogging("org.elasticsearch.xpack.ml.datafeed:DEBUG,org.elasticsearch.xpack.ml.action:DEBUG," + + "org.elasticsearch.xpack.ml.job.persistence:DEBUG") public class MlDistributedFailureIT extends BaseMlIntegTestCase { public void testFailOver() throws Exception {