.setRefresh(true)
.execute().actionGet();
client.admin().cluster().prepareHealth().setWaitForGreenStatus().setWaitForActiveShards(4).execute().actionGet();
for (int i = 0; i < 10; i++) {
IndexResponse index = client.prepareIndex("test", "type1", Integer.toString(i)).setSource("field1", "value1")
.setPercolate("*").execute().actionGet();
assertThat(index.matches().size(), equalTo(1));
assertThat(index.matches(), hasItem("kuku"));
}
for (int i = 0; i < 10; i++) {
IndexResponse index = client.prepareIndex("test", "type1", Integer.toString(i)).setSource("field1", "value1")
.setPercolate("color:blue").execute().actionGet();
assertThat(index.matches().size(), equalTo(1));
assertThat(index.matches(), hasItem("kuku"));
}
for (int i = 0; i < 10; i++) {
IndexResponse index = client.prepareIndex("test", "type1", Integer.toString(i)).setSource("field1", "value1")
.setPercolate("color:green").execute().actionGet();
assertThat(index.matches().size(), equalTo(0));
}
// test bulk
BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
for (int i = 0; i < 10; i++) {
bulkRequestBuilder.add(client.prepareIndex("test", "type1", Integer.toString(i)).setSource("field1", "value1")
.setPercolate("*"));
}
BulkResponse bulkResponse = bulkRequestBuilder.execute().actionGet();
assertThat(bulkResponse.hasFailures(), equalTo(false));
for (BulkItemResponse bulkItemResponse : bulkResponse) {
IndexResponse index = bulkItemResponse.response();
assertThat(index.matches().size(), equalTo(1));
assertThat(index.matches(), hasItem("kuku"));
}
}