Search in sources :

Example 6 with ValidateQueryResponse

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"));
}
Also used : ValidateQueryResponse(org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse) Alias(org.elasticsearch.action.admin.indices.alias.Alias)

Example 7 with ValidateQueryResponse

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());
    }
}
Also used : ValidateQueryResponse(org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse) Client(org.elasticsearch.client.Client)

Aggregations

ValidateQueryResponse (org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse)7 IOException (java.io.IOException)1 Alias (org.elasticsearch.action.admin.indices.alias.Alias)1 QueryExplanation (org.elasticsearch.action.admin.indices.validate.query.QueryExplanation)1 ValidateQueryRequest (org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest)1 IndicesOptions (org.elasticsearch.action.support.IndicesOptions)1 Client (org.elasticsearch.client.Client)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 ParsingException (org.elasticsearch.common.ParsingException)1 Strings (org.elasticsearch.common.Strings)1 Settings (org.elasticsearch.common.settings.Settings)1 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)1 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)1 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)1 RestChannel (org.elasticsearch.rest.RestChannel)1 RestController (org.elasticsearch.rest.RestController)1 RestRequest (org.elasticsearch.rest.RestRequest)1 GET (org.elasticsearch.rest.RestRequest.Method.GET)1 POST (org.elasticsearch.rest.RestRequest.Method.POST)1 RestResponse (org.elasticsearch.rest.RestResponse)1