Search in sources :

Example 1 with ShardValidateQueryRequest

use of org.elasticsearch.action.admin.indices.validate.query.ShardValidateQueryRequest in project elasticsearch by elastic.

the class ShardValidateQueryRequestTests method testSerialize50Request.

// BWC test for changes from #20916
public void testSerialize50Request() throws IOException {
    ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest("indices");
    validateQueryRequest.query(QueryBuilders.termQuery("field", "value"));
    validateQueryRequest.rewrite(true);
    validateQueryRequest.explain(false);
    validateQueryRequest.types("type1", "type2");
    ShardValidateQueryRequest request = new ShardValidateQueryRequest(new ShardId("index", "foobar", 1), new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), new String[] { "alias0", "alias1" }), validateQueryRequest);
    BytesArray requestBytes = new BytesArray(Base64.getDecoder().decode("AAVpbmRleAZmb29iYXIBAQdpbmRpY2VzBAR0ZXJtP4AAAAAFZmllbGQVBXZhbHVlAgV0eXBlMQV0eXBlMgIGYWxpYXMwBmFsaWFzMQABAA"));
    try (StreamInput in = new NamedWriteableAwareStreamInput(requestBytes.streamInput(), namedWriteableRegistry)) {
        in.setVersion(Version.V_5_0_0);
        ShardValidateQueryRequest readRequest = new ShardValidateQueryRequest();
        readRequest.readFrom(in);
        assertEquals(0, in.available());
        assertArrayEquals(request.filteringAliases().getAliases(), readRequest.filteringAliases().getAliases());
        expectThrows(IllegalStateException.class, () -> readRequest.filteringAliases().getQueryBuilder());
        assertArrayEquals(request.types(), readRequest.types());
        assertEquals(request.explain(), readRequest.explain());
        assertEquals(request.query(), readRequest.query());
        assertEquals(request.rewrite(), readRequest.rewrite());
        assertEquals(request.shardId(), readRequest.shardId());
        BytesStreamOutput output = new BytesStreamOutput();
        output.setVersion(Version.V_5_0_0);
        readRequest.writeTo(output);
        assertEquals(output.bytes().toBytesRef(), requestBytes.toBytesRef());
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ShardValidateQueryRequest(org.elasticsearch.action.admin.indices.validate.query.ShardValidateQueryRequest) AliasFilter(org.elasticsearch.search.internal.AliasFilter) BytesArray(org.elasticsearch.common.bytes.BytesArray) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) ValidateQueryRequest(org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest) ShardValidateQueryRequest(org.elasticsearch.action.admin.indices.validate.query.ShardValidateQueryRequest) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Example 2 with ShardValidateQueryRequest

use of org.elasticsearch.action.admin.indices.validate.query.ShardValidateQueryRequest in project elasticsearch by elastic.

the class ShardValidateQueryRequestTests method testSerialize.

public void testSerialize() throws IOException {
    try (BytesStreamOutput output = new BytesStreamOutput()) {
        ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest("indices");
        validateQueryRequest.query(QueryBuilders.termQuery("field", "value"));
        validateQueryRequest.rewrite(true);
        validateQueryRequest.explain(false);
        validateQueryRequest.types("type1", "type2");
        ShardValidateQueryRequest request = new ShardValidateQueryRequest(new ShardId("index", "foobar", 1), new AliasFilter(QueryBuilders.termQuery("filter_field", "value"), new String[] { "alias0", "alias1" }), validateQueryRequest);
        request.writeTo(output);
        try (StreamInput in = new NamedWriteableAwareStreamInput(output.bytes().streamInput(), namedWriteableRegistry)) {
            ShardValidateQueryRequest readRequest = new ShardValidateQueryRequest();
            readRequest.readFrom(in);
            assertEquals(request.filteringAliases(), readRequest.filteringAliases());
            assertArrayEquals(request.types(), readRequest.types());
            assertEquals(request.explain(), readRequest.explain());
            assertEquals(request.query(), readRequest.query());
            assertEquals(request.rewrite(), readRequest.rewrite());
            assertEquals(request.shardId(), readRequest.shardId());
        }
    }
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) ShardValidateQueryRequest(org.elasticsearch.action.admin.indices.validate.query.ShardValidateQueryRequest) AliasFilter(org.elasticsearch.search.internal.AliasFilter) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) StreamInput(org.elasticsearch.common.io.stream.StreamInput) NamedWriteableAwareStreamInput(org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput) ValidateQueryRequest(org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest) ShardValidateQueryRequest(org.elasticsearch.action.admin.indices.validate.query.ShardValidateQueryRequest) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput)

Aggregations

ShardValidateQueryRequest (org.elasticsearch.action.admin.indices.validate.query.ShardValidateQueryRequest)2 ValidateQueryRequest (org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest)2 BytesStreamOutput (org.elasticsearch.common.io.stream.BytesStreamOutput)2 NamedWriteableAwareStreamInput (org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput)2 StreamInput (org.elasticsearch.common.io.stream.StreamInput)2 ShardId (org.elasticsearch.index.shard.ShardId)2 AliasFilter (org.elasticsearch.search.internal.AliasFilter)2 BytesArray (org.elasticsearch.common.bytes.BytesArray)1