public XContentThrowableRestResponse(RestRequest request, Throwable t) throws IOException { this(request, ((t instanceof ElasticsearchException) ? ((ElasticsearchException) t).status() : RestStatus.INTERNAL_SERVER_ERROR), t); }
public static RestStatus status(Throwable t) { if (t != null) { if (t instanceof ElasticsearchException) { return ((ElasticsearchException) t).status(); } else if (t instanceof IllegalArgumentException) { return RestStatus.BAD_REQUEST; } else if (t instanceof EsRejectedExecutionException) { return RestStatus.TOO_MANY_REQUESTS; } } return RestStatus.INTERNAL_SERVER_ERROR; }
public DefaultShardOperationFailedException(ElasticsearchException e) { super(e.getIndex() == null ? null : e.getIndex().getName(), e.getShardId() == null ? -1 : e.getShardId().getId(), detailedMessage(e), e.status(), e); }
public static RestStatus status(Throwable t) { if (t != null) { if (t instanceof ElasticsearchException) { return ((ElasticsearchException) t).status(); } else if (t instanceof IllegalArgumentException) { return RestStatus.BAD_REQUEST; } } return RestStatus.INTERNAL_SERVER_ERROR; }
public static RestStatus status(Throwable t) { if (t != null) { if (t instanceof ElasticsearchException) { return ((ElasticsearchException) t).status(); } else if (t instanceof IllegalArgumentException) { return RestStatus.BAD_REQUEST; } else if (t instanceof EsRejectedExecutionException) { return RestStatus.TOO_MANY_REQUESTS; } } return RestStatus.INTERNAL_SERVER_ERROR; }
public static RestStatus status(Throwable t) { if (t != null) { if (t instanceof ElasticsearchException) { return ((ElasticsearchException) t).status(); } else if (t instanceof IllegalArgumentException) { return RestStatus.BAD_REQUEST; } else if (t instanceof EsRejectedExecutionException) { return RestStatus.TOO_MANY_REQUESTS; } } return RestStatus.INTERNAL_SERVER_ERROR; }
public static RestStatus status(Throwable t) { if (t != null) { if (t instanceof ElasticsearchException) { return ((ElasticsearchException) t).status(); } else if (t instanceof IllegalArgumentException) { return RestStatus.BAD_REQUEST; } } return RestStatus.INTERNAL_SERVER_ERROR; }
public XContentThrowableRestResponse(RestRequest request, Throwable t) throws IOException { this(request, ((t instanceof ElasticsearchException) ? ((ElasticsearchException) t).status() : RestStatus.INTERNAL_SERVER_ERROR), t); }
public UpdateResponse update(String indexName, String type, String id) throws IOException { try { Map<String, Object> jsonMap = new HashMap<>(); jsonMap.put("updated", new Date()); jsonMap.put("reason", "daily update"); UpdateRequest request = new UpdateRequest("posts", "doc", "1") .doc(jsonMap); UpdateResponse updateResponse = client.update(request); return updateResponse; } catch (ElasticsearchException exception) { if (exception.status() == RestStatus.NOT_FOUND) { } } return null; }
public boolean exists(String indexName, String type, String id) throws IOException { try { GetRequest getRequest = new GetRequest( indexName, type, id); return client.exists(getRequest); } catch (ElasticsearchException exception) { if (exception.status() == RestStatus.NOT_FOUND) { } } return false; }
public GetResponse get(String indexName, String type, String id) throws IOException { try { GetRequest getRequest = new GetRequest( indexName, type, id); GetResponse getResponse = client.get(getRequest); return getResponse; } catch (ElasticsearchException exception) { if (exception.status() == RestStatus.NOT_FOUND) { } } return null; }
public DefaultShardOperationFailedException(ElasticsearchException e) { this.index = e.getIndex(); this.shardId = e.getShardId().id(); this.reason = e; this.status = e.status(); }
public boolean existsIndex(String indexName, String type) throws IOException { try { GetIndexRequest request = new GetIndexRequest(); request.indices(indexName); return client.indices().exists(request); } catch (ElasticsearchException exception) { if (exception.status() == RestStatus.NOT_FOUND) { } } return false; }
public int recoveryFromSnapshot(Engine engine, Translog.Snapshot snapshot) throws IOException { Translog.Operation operation; int opsRecovered = 0; while ((operation = snapshot.next()) != null) { try { performRecoveryOperation(engine, operation, true); opsRecovered++; } catch (ElasticsearchException e) { if (e.status() == RestStatus.BAD_REQUEST) { // mainly for MapperParsingException and Failure to detect xcontent logger.info("ignoring recovery of a corrupt translog entry", e); } else { throw e; } } } return opsRecovered; }
public boolean delete(String indexName, String type, String id) throws IOException { try { DeleteRequest request = new DeleteRequest("posts", "doc", "1").version(2); DeleteResponse deleteResponse = client.delete(request); return deleteResponse.isFragment(); } catch (ElasticsearchException exception) { if (exception.status() == RestStatus.NOT_FOUND) { } } return false; } public UpdateResponse update(String indexName, String type, String id) throws IOException {
public boolean deleteIndex(String indexName, String type) throws IOException { try { DeleteIndexRequest request = new DeleteIndexRequest("posts"); DeleteIndexResponse deleteIndexResponse = client.indices().delete(request); /*restHighLevelClient.indices().deleteAsync(request, new ActionListener<DeleteIndexResponse>() { @Override public void onResponse(DeleteIndexResponse deleteIndexResponse) { } @Override public void onFailure(Exception e) { } });*/ return deleteIndexResponse.isAcknowledged(); } catch (ElasticsearchException exception) { if (exception.status() == RestStatus.NOT_FOUND) { } } return false; }
public DefaultShardOperationFailedException(ElasticsearchException e) { this.index = e.getIndex() == null ? null : e.getIndex().getName(); this.shardId = e.getShardId().id(); this.reason = e; this.status = e.status(); }
public DefaultShardOperationFailedException(ElasticsearchException e) { super(e.getIndex() == null ? null : e.getIndex().getName(), e.getShardId() == null ? -1 : e.getShardId().getId(), detailedMessage(e), e.status(), e); }
if (e instanceof ElasticsearchException && ((ElasticsearchException) e).status() == RestStatus.CONFLICT) { return Optional.empty(); } else {
public static void assertFailures(SearchRequestBuilder searchRequestBuilder, RestStatus restStatus, Matcher<String> reasonMatcher) { //when the number for shards is randomized and we expect failures //we can either run into partial or total failures depending on the current number of shards try { SearchResponse searchResponse = searchRequestBuilder.get(); assertThat("Expected shard failures, got none", searchResponse.getShardFailures().length, greaterThan(0)); for (ShardSearchFailure shardSearchFailure : searchResponse.getShardFailures()) { assertThat(shardSearchFailure.status(), equalTo(restStatus)); assertThat(shardSearchFailure.reason(), reasonMatcher); } assertVersionSerializable(searchResponse); } catch (ElasticsearchException e) { assertThat(e.status(), equalTo(restStatus)); assertThat(e.toString(), reasonMatcher); } catch (Exception e) { fail("ElasticsearchException expected but got " + e.getClass()); } }