.setSettings(ImmutableSettings.settingsBuilder().put("index.refresh_interval", -1)));
ensureGreen("test");
client().prepareIndex("test", "test", "1").setSource("field", "value1").get();
ExplainResponse response = client().prepareExplain(indexOrAlias(), "test", "1")
.setQuery(QueryBuilders.matchAllQuery()).get();
assertNotNull(response);
assertFalse(response.isExists()); // not a match b/c not realtime
assertThat(response.getIndex(), equalTo("test"));
assertThat(response.getType(), equalTo("test"));
assertThat(response.getId(), equalTo("1"));
assertFalse(response.isMatch()); // not a match b/c not realtime
refresh();
response = client().prepareExplain(indexOrAlias(), "test", "1")
.setQuery(QueryBuilders.matchAllQuery()).get();
assertNotNull(response);
assertTrue(response.isMatch());
assertNotNull(response.getExplanation());
assertTrue(response.getExplanation().isMatch());
assertThat(response.getIndex(), equalTo("test"));
assertThat(response.getType(), equalTo("test"));
assertThat(response.getId(), equalTo("1"));
assertThat(response.getExplanation().getValue(), equalTo(1.0f));
response = client().prepareExplain(indexOrAlias(), "test", "1")
.setQuery(QueryBuilders.termQuery("field", "value2")).get();
assertNotNull(response);
assertTrue(response.isExists());
assertFalse(response.isMatch());
assertThat(response.getIndex(), equalTo("test"));
assertThat(response.getType(), equalTo("test"));
assertThat(response.getId(), equalTo("1"));
assertNotNull(response.getExplanation());
assertFalse(response.getExplanation().isMatch());
response = client().prepareExplain(indexOrAlias(), "test", "1")
.setQuery(QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("field", "value1"))
.must(QueryBuilders.termQuery("field", "value2"))).get();
assertNotNull(response);
assertTrue(response.isExists());
assertFalse(response.isMatch());
assertThat(response.getIndex(), equalTo("test"));
assertThat(response.getType(), equalTo("test"));
assertThat(response.getId(), equalTo("1"));
assertNotNull(response.getExplanation());
assertFalse(response.getExplanation().isMatch());
assertThat(response.getExplanation().getDetails().length, equalTo(2));
response = client().prepareExplain(indexOrAlias(), "test", "2")
.setQuery(QueryBuilders.matchAllQuery()).get();
assertNotNull(response);
assertFalse(response.isExists());
assertFalse(response.isMatch());
assertThat(response.getIndex(), equalTo("test"));
assertThat(response.getType(), equalTo("test"));
assertThat(response.getId(), equalTo("2"));
}