client().prepareIndex("twitter", "tweet").setSource(json).setRefresh(true).execute().actionGet();
SearchResponse search = client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
assertThat(search.getHits().totalHits(), equalTo(1l));
DeleteByQueryRequestBuilder deleteByQueryRequestBuilder = client().prepareDeleteByQuery();
deleteByQueryRequestBuilder.setIndices("twitter", "missing");
deleteByQueryRequestBuilder.setQuery(QueryBuilders.matchAllQuery());
try {
deleteByQueryRequestBuilder.execute().actionGet();
fail("Exception should have been thrown.");
} catch (IndexMissingException e) {
//everything well
}
deleteByQueryRequestBuilder.setIndicesOptions(IndicesOptions.lenientExpandOpen());
DeleteByQueryResponse actionGet = deleteByQueryRequestBuilder.execute().actionGet();
assertThat(actionGet.status(), equalTo(RestStatus.OK));
assertThat(actionGet.getIndex("twitter").getFailedShards(), equalTo(0));
assertThat(actionGet.getIndex("twitter"), notNullValue());
client().admin().indices().prepareRefresh().execute().actionGet();