use of org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse in project elasticsearch by elastic.
the class SimpleValidateQueryIT method testExplainFilteredAlias.
public void testExplainFilteredAlias() {
assertAcked(prepareCreate("test").addMapping("test", "field", "type=text").addAlias(new Alias("alias").filter(QueryBuilders.termQuery("field", "value1"))));
ensureGreen();
ValidateQueryResponse validateQueryResponse = client().admin().indices().prepareValidateQuery("alias").setQuery(QueryBuilders.matchAllQuery()).setExplain(true).get();
assertThat(validateQueryResponse.isValid(), equalTo(true));
assertThat(validateQueryResponse.getQueryExplanation().size(), equalTo(1));
assertThat(validateQueryResponse.getQueryExplanation().get(0).getIndex(), equalTo("test"));
assertThat(validateQueryResponse.getQueryExplanation().get(0).getExplanation(), containsString("field:value1"));
}
use of org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse in project elasticsearch by elastic.
the class SimpleValidateQueryIT method testExplainValidateQueryTwoNodes.
public void testExplainValidateQueryTwoNodes() throws IOException {
createIndex("test");
ensureGreen();
client().admin().indices().preparePutMapping("test").setType("type1").setSource(XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("foo").field("type", "text").endObject().startObject("bar").field("type", "integer").endObject().startObject("baz").field("type", "text").field("analyzer", "snowball").endObject().startObject("pin").startObject("properties").startObject("location").field("type", "geo_point").endObject().endObject().endObject().endObject().endObject().endObject()).execute().actionGet();
refresh();
for (Client client : internalCluster().getClients()) {
ValidateQueryResponse response = client.admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.wrapperQuery("foo".getBytes(StandardCharsets.UTF_8))).setExplain(true).execute().actionGet();
assertThat(response.isValid(), equalTo(false));
assertThat(response.getQueryExplanation().size(), equalTo(1));
assertThat(response.getQueryExplanation().get(0).getError(), containsString("Failed to derive xcontent"));
assertThat(response.getQueryExplanation().get(0).getExplanation(), nullValue());
}
for (Client client : internalCluster().getClients()) {
ValidateQueryResponse response = client.admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryStringQuery("foo")).setExplain(true).execute().actionGet();
assertThat(response.isValid(), equalTo(true));
assertThat(response.getQueryExplanation().size(), equalTo(1));
assertThat(response.getQueryExplanation().get(0).getExplanation(), equalTo("(foo:foo | baz:foo)"));
assertThat(response.getQueryExplanation().get(0).getError(), nullValue());
}
}
Aggregations