Refactor validate to validateQuery and move into indices admin action

This commit is contained in:
Lee Hinman 2011-12-28 15:24:08 -07:00
parent 0cb1a2ebe1
commit f6b036f713
25 changed files with 272 additions and 301 deletions

View File

@ -29,8 +29,6 @@ public class TransportActions {
public static final String INDEX = "indices/index/shard/index";
public static final String COUNT = "indices/count";
public static final String VALIDATE = "indices/validate";
public static final String DELETE = "indices/index/shard/delete";
@ -69,6 +67,7 @@ public class TransportActions {
public static final String ANALYZE = "indices/analyze";
public static final String PUT_INDEX_TEMPLATE = "indices/putIndexTemplate";
public static final String DELETE_INDEX_TEMPLATE = "indices/deleteIndexTemplate";
public static final String VALIDATE_QUERY = "indices/validateQuery";
public static class Gateway {
public static final String SNAPSHOT = "indices/gateway/snapshot";

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.elasticsearch.action.validate;
package org.elasticsearch.action.admin.indices.validate.query;
import org.elasticsearch.action.support.broadcast.BroadcastShardOperationRequest;
import org.elasticsearch.common.Nullable;
@ -32,7 +32,7 @@ import java.io.IOException;
*
*
*/
class ShardValidateRequest extends BroadcastShardOperationRequest {
class ShardValidateQueryRequest extends BroadcastShardOperationRequest {
private byte[] querySource;
private int querySourceOffset;
@ -43,11 +43,11 @@ class ShardValidateRequest extends BroadcastShardOperationRequest {
@Nullable
private String[] filteringAliases;
ShardValidateRequest() {
ShardValidateQueryRequest() {
}
public ShardValidateRequest(String index, int shardId, @Nullable String[] filteringAliases, ValidateRequest request) {
public ShardValidateQueryRequest(String index, int shardId, @Nullable String[] filteringAliases, ValidateQueryRequest request) {
super(index, shardId);
this.querySource = request.querySource();
this.querySourceOffset = request.querySourceOffset();

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.elasticsearch.action.validate;
package org.elasticsearch.action.admin.indices.validate.query;
import org.elasticsearch.action.support.broadcast.BroadcastShardOperationResponse;
import org.elasticsearch.common.io.stream.StreamInput;
@ -30,15 +30,15 @@ import java.io.IOException;
*
*
*/
class ShardValidateResponse extends BroadcastShardOperationResponse {
class ShardValidateQueryResponse extends BroadcastShardOperationResponse {
private boolean valid;
ShardValidateResponse() {
ShardValidateQueryResponse() {
}
public ShardValidateResponse(String index, int shardId, boolean valid) {
public ShardValidateQueryResponse(String index, int shardId, boolean valid) {
super(index, shardId);
this.valid = valid;
}

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.elasticsearch.action.validate;
package org.elasticsearch.action.admin.indices.validate.query;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.action.ShardOperationFailedException;
@ -32,6 +32,8 @@ import org.elasticsearch.cluster.routing.GroupShardsIterator;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.IndexQueryParserService;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.shard.service.IndexShard;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.threadpool.ThreadPool;
@ -47,12 +49,12 @@ import static com.google.common.collect.Lists.newArrayList;
/**
*
*/
public class TransportValidateAction extends TransportBroadcastOperationAction<ValidateRequest, ValidateResponse, ShardValidateRequest, ShardValidateResponse> {
public class TransportValidateQueryAction extends TransportBroadcastOperationAction<ValidateQueryRequest, ValidateQueryResponse, ShardValidateQueryRequest, ShardValidateQueryResponse> {
private final IndicesService indicesService;
@Inject
public TransportValidateAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, TransportService transportService, IndicesService indicesService) {
public TransportValidateQueryAction(Settings settings, ThreadPool threadPool, ClusterService clusterService, TransportService transportService, IndicesService indicesService) {
super(settings, threadPool, clusterService, transportService);
this.indicesService = indicesService;
}
@ -64,51 +66,51 @@ public class TransportValidateAction extends TransportBroadcastOperationAction<V
@Override
protected String transportAction() {
return TransportActions.VALIDATE;
return TransportActions.Admin.Indices.VALIDATE_QUERY;
}
@Override
protected String transportShardAction() {
return "indices/validate/shard";
return "indices/validateQuery/shard";
}
@Override
protected ValidateRequest newRequest() {
return new ValidateRequest();
protected ValidateQueryRequest newRequest() {
return new ValidateQueryRequest();
}
@Override
protected ShardValidateRequest newShardRequest() {
return new ShardValidateRequest();
protected ShardValidateQueryRequest newShardRequest() {
return new ShardValidateQueryRequest();
}
@Override
protected ShardValidateRequest newShardRequest(ShardRouting shard, ValidateRequest request) {
protected ShardValidateQueryRequest newShardRequest(ShardRouting shard, ValidateQueryRequest request) {
String[] filteringAliases = clusterService.state().metaData().filteringAliases(shard.index(), request.indices());
return new ShardValidateRequest(shard.index(), shard.id(), filteringAliases, request);
return new ShardValidateQueryRequest(shard.index(), shard.id(), filteringAliases, request);
}
@Override
protected ShardValidateResponse newShardResponse() {
return new ShardValidateResponse();
protected ShardValidateQueryResponse newShardResponse() {
return new ShardValidateQueryResponse();
}
@Override
protected GroupShardsIterator shards(ValidateRequest request, String[] concreteIndices, ClusterState clusterState) {
protected GroupShardsIterator shards(ValidateQueryRequest request, String[] concreteIndices, ClusterState clusterState) {
// Hard-code routing to limit request to a single shard.
Map<String, Set<String>> routingMap = clusterState.metaData().resolveSearchRouting("0", request.indices());
return clusterService.operationRouting().searchShards(clusterState, request.indices(), concreteIndices, null, routingMap, "_local");
}
@Override
protected void checkBlock(ValidateRequest request, String[] concreteIndices, ClusterState state) {
protected void checkBlock(ValidateQueryRequest request, String[] concreteIndices, ClusterState state) {
for (String index : concreteIndices) {
state.blocks().indexBlocked(ClusterBlockLevel.READ, index);
}
}
@Override
protected ValidateResponse newResponse(ValidateRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) {
protected ValidateQueryResponse newResponse(ValidateQueryRequest request, AtomicReferenceArray shardsResponses, ClusterState clusterState) {
int successfulShards = 0;
int failedShards = 0;
boolean valid = true;
@ -124,18 +126,29 @@ public class TransportValidateAction extends TransportBroadcastOperationAction<V
}
shardFailures.add(new DefaultShardOperationFailedException((BroadcastShardOperationFailedException) shardResponse));
} else {
valid = valid && ((ShardValidateResponse) shardResponse).valid();
valid = valid && ((ShardValidateQueryResponse) shardResponse).valid();
successfulShards++;
}
}
return new ValidateResponse(valid, shardsResponses.length(), successfulShards, failedShards, shardFailures);
return new ValidateQueryResponse(valid, shardsResponses.length(), successfulShards, failedShards, shardFailures);
}
@Override
protected ShardValidateResponse shardOperation(ShardValidateRequest request) throws ElasticSearchException {
IndexShard indexShard = indicesService.indexServiceSafe(request.index()).shardSafe(request.shardId());
boolean valid = indexShard.validate(request.querySource(), request.querySourceOffset(), request.querySourceLength(),
request.filteringAliases(), request.types());
return new ShardValidateResponse(request.index(), request.shardId(), valid);
protected ShardValidateQueryResponse shardOperation(ShardValidateQueryRequest request) throws ElasticSearchException {
IndexQueryParserService queryParserService = indicesService.indexServiceSafe(request.index()).queryParserService();
boolean valid;
if (request.querySourceLength() == 0) {
valid = true;
} else {
try {
queryParserService.parse(request.querySource(), request.querySourceOffset(), request.querySourceLength());
valid = true;
} catch (QueryParsingException e) {
valid = false;
} catch (AssertionError e) {
valid = false;
}
}
return new ShardValidateQueryResponse(request.index(), request.shardId(), valid);
}
}

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.elasticsearch.action.validate;
package org.elasticsearch.action.admin.indices.validate.query;
import org.apache.lucene.util.UnicodeUtil;
import org.elasticsearch.ElasticSearchGenerationException;
@ -25,7 +25,6 @@ import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequest;
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
import org.elasticsearch.client.Requests;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.Required;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.Unicode;
@ -49,7 +48,7 @@ import java.util.Map;
*
*
*/
public class ValidateRequest extends BroadcastOperationRequest {
public class ValidateQueryRequest extends BroadcastOperationRequest {
private static final XContentType contentType = Requests.CONTENT_TYPE;
@ -60,14 +59,14 @@ public class ValidateRequest extends BroadcastOperationRequest {
private String[] types = Strings.EMPTY_ARRAY;
ValidateRequest() {
ValidateQueryRequest() {
}
/**
* Constructs a new validate request against the provided indices. No indices provided means it will
* run against all indices.
*/
public ValidateRequest(String... indices) {
public ValidateQueryRequest(String... indices) {
super(indices);
}
@ -81,7 +80,7 @@ public class ValidateRequest extends BroadcastOperationRequest {
* Controls the operation threading model.
*/
@Override
public ValidateRequest operationThreading(BroadcastOperationThreading operationThreading) {
public ValidateQueryRequest operationThreading(BroadcastOperationThreading operationThreading) {
super.operationThreading(operationThreading);
return this;
}
@ -99,12 +98,12 @@ public class ValidateRequest extends BroadcastOperationRequest {
* Should the listener be called on a separate thread if needed.
*/
@Override
public ValidateRequest listenerThreaded(boolean threadedListener) {
public ValidateQueryRequest listenerThreaded(boolean threadedListener) {
super.listenerThreaded(threadedListener);
return this;
}
public ValidateRequest indices(String... indices) {
public ValidateQueryRequest indices(String... indices) {
this.indices = indices;
return this;
}
@ -130,7 +129,7 @@ public class ValidateRequest extends BroadcastOperationRequest {
* @see org.elasticsearch.index.query.QueryBuilders
*/
@Required
public ValidateRequest query(QueryBuilder queryBuilder) {
public ValidateQueryRequest query(QueryBuilder queryBuilder) {
BytesStream bos = queryBuilder.buildAsUnsafeBytes();
this.querySource = bos.underlyingBytes();
this.querySourceOffset = 0;
@ -143,7 +142,7 @@ public class ValidateRequest extends BroadcastOperationRequest {
* The query source to execute in the form of a map.
*/
@Required
public ValidateRequest query(Map querySource) {
public ValidateQueryRequest query(Map querySource) {
try {
XContentBuilder builder = XContentFactory.contentBuilder(contentType);
builder.map(querySource);
@ -154,7 +153,7 @@ public class ValidateRequest extends BroadcastOperationRequest {
}
@Required
public ValidateRequest query(XContentBuilder builder) {
public ValidateQueryRequest query(XContentBuilder builder) {
try {
this.querySource = builder.underlyingBytes();
this.querySourceOffset = 0;
@ -171,7 +170,7 @@ public class ValidateRequest extends BroadcastOperationRequest {
* or {@link #query(org.elasticsearch.index.query.QueryBuilder)}.
*/
@Required
public ValidateRequest query(String querySource) {
public ValidateQueryRequest query(String querySource) {
UnicodeUtil.UTF8Result result = Unicode.fromStringAsUtf8(querySource);
this.querySource = result.result;
this.querySourceOffset = 0;
@ -184,7 +183,7 @@ public class ValidateRequest extends BroadcastOperationRequest {
* The query source to validate.
*/
@Required
public ValidateRequest query(byte[] querySource) {
public ValidateQueryRequest query(byte[] querySource) {
return query(querySource, 0, querySource.length, false);
}
@ -192,7 +191,7 @@ public class ValidateRequest extends BroadcastOperationRequest {
* The query source to validate.
*/
@Required
public ValidateRequest query(byte[] querySource, int offset, int length, boolean unsafe) {
public ValidateQueryRequest query(byte[] querySource, int offset, int length, boolean unsafe) {
this.querySource = querySource;
this.querySourceOffset = offset;
this.querySourceLength = length;
@ -210,7 +209,7 @@ public class ValidateRequest extends BroadcastOperationRequest {
/**
* The types of documents the query will run against. Defaults to all types.
*/
public ValidateRequest types(String... types) {
public ValidateQueryRequest types(String... types) {
this.types = types;
return this;
}

View File

@ -17,7 +17,7 @@
* under the License.
*/
package org.elasticsearch.action.validate;
package org.elasticsearch.action.admin.indices.validate.query;
import org.elasticsearch.action.ShardOperationFailedException;
import org.elasticsearch.action.support.broadcast.BroadcastOperationResponse;
@ -32,15 +32,15 @@ import java.util.List;
*
*
*/
public class ValidateResponse extends BroadcastOperationResponse {
public class ValidateQueryResponse extends BroadcastOperationResponse {
private boolean valid;
ValidateResponse() {
ValidateQueryResponse() {
}
ValidateResponse(boolean valid, int totalShards, int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
ValidateQueryResponse(boolean valid, int totalShards, int successfulShards, int failedShards, List<ShardOperationFailedException> shardFailures) {
super(totalShards, successfulShards, failedShards, shardFailures);
this.valid = valid;
}

View File

@ -20,4 +20,4 @@
/**
* Validate action.
*/
package org.elasticsearch.action.validate;
package org.elasticsearch.action.admin.indices.validate.query;

View File

@ -41,8 +41,6 @@ import org.elasticsearch.action.percolate.PercolateResponse;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchScrollRequest;
import org.elasticsearch.action.validate.ValidateRequest;
import org.elasticsearch.action.validate.ValidateResponse;
import org.elasticsearch.client.action.bulk.BulkRequestBuilder;
import org.elasticsearch.client.action.count.CountRequestBuilder;
import org.elasticsearch.client.action.delete.DeleteRequestBuilder;
@ -54,7 +52,6 @@ import org.elasticsearch.client.action.mlt.MoreLikeThisRequestBuilder;
import org.elasticsearch.client.action.percolate.PercolateRequestBuilder;
import org.elasticsearch.client.action.search.SearchRequestBuilder;
import org.elasticsearch.client.action.search.SearchScrollRequestBuilder;
import org.elasticsearch.client.action.validate.ValidateRequestBuilder;
import org.elasticsearch.common.Nullable;
/**
@ -277,29 +274,6 @@ public interface Client {
*/
CountRequestBuilder prepareCount(String... indices);
/**
* A count of all the documents matching a specific query.
*
* @param request The count request
* @return The result future
* @see Requests#countRequest(String...)
*/
ActionFuture<ValidateResponse> validate(ValidateRequest request);
/**
* A count of all the documents matching a specific query.
*
* @param request The count request
* @param listener A listener to be notified of the result
* @see Requests#countRequest(String...)
*/
void validate(ValidateRequest request, ActionListener<ValidateResponse> listener);
/**
* A count of all the documents matching a specific query.
*/
ValidateRequestBuilder prepareValidate(String... indices);
/**
* Search across one or more indices and one or more types with a query.
*

View File

@ -61,6 +61,8 @@ import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplat
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
import org.elasticsearch.client.action.admin.indices.alias.IndicesAliasesRequestBuilder;
import org.elasticsearch.client.action.admin.indices.analyze.AnalyzeRequestBuilder;
import org.elasticsearch.client.action.admin.indices.cache.clear.ClearIndicesCacheRequestBuilder;
@ -81,6 +83,7 @@ import org.elasticsearch.client.action.admin.indices.stats.IndicesStatsRequestBu
import org.elasticsearch.client.action.admin.indices.status.IndicesStatusRequestBuilder;
import org.elasticsearch.client.action.admin.indices.template.delete.DeleteIndexTemplateRequestBuilder;
import org.elasticsearch.client.action.admin.indices.template.put.PutIndexTemplateRequestBuilder;
import org.elasticsearch.client.action.admin.indices.validate.query.ValidateQueryRequestBuilder;
import org.elasticsearch.common.Nullable;
/**
@ -537,4 +540,27 @@ public interface IndicesAdminClient {
* @param name The name of the template.
*/
DeleteIndexTemplateRequestBuilder prepareDeleteTemplate(String name);
/**
* Validate a query for correctness.
*
* @param request The count request
* @return The result future
* @see Requests#countRequest(String...)
*/
ActionFuture<ValidateQueryResponse> validateQuery(ValidateQueryRequest request);
/**
* Validate a query for correctness.
*
* @param request The count request
* @param listener A listener to be notified of the result
* @see Requests#countRequest(String...)
*/
void validateQuery(ValidateQueryRequest request, ActionListener<ValidateQueryResponse> listener);
/**
* Validate a query for correctness.
*/
ValidateQueryRequestBuilder prepareValidateQuery(String... indices);
}

View File

@ -0,0 +1,75 @@
package org.elasticsearch.client.action.admin.indices.validate.query;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.action.admin.indices.support.BaseIndicesRequestBuilder;
import org.elasticsearch.index.query.QueryBuilder;
/**
*
*/
public class ValidateQueryRequestBuilder extends BaseIndicesRequestBuilder<ValidateQueryRequest, ValidateQueryResponse> {
public ValidateQueryRequestBuilder(IndicesAdminClient client) {
super(client, new ValidateQueryRequest());
}
/**
* Sets the indices the query validation will run against.
*/
public ValidateQueryRequestBuilder setIndices(String... indices) {
request.indices(indices);
return this;
}
/**
* The types of documents the query will run against. Defaults to all types.
*/
public ValidateQueryRequestBuilder setTypes(String... types) {
request.types(types);
return this;
}
/**
* The query source to validate.
*
* @see org.elasticsearch.index.query.QueryBuilders
*/
public ValidateQueryRequestBuilder setQuery(QueryBuilder queryBuilder) {
request.query(queryBuilder);
return this;
}
/**
* The query source to validate.
*
* @see org.elasticsearch.index.query.QueryBuilders
*/
public ValidateQueryRequestBuilder setQuery(byte[] querySource) {
request.query(querySource);
return this;
}
/**
* Controls the operation threading model.
*/
public ValidateQueryRequestBuilder setOperationThreading(BroadcastOperationThreading operationThreading) {
request.operationThreading(operationThreading);
return this;
}
/**
* Should the listener be called on a separate thread if needed.
*/
public ValidateQueryRequestBuilder setListenerThreaded(boolean threadedListener) {
request.listenerThreaded(threadedListener);
return this;
}
@Override
protected void doExecute(ActionListener<ValidateQueryResponse> listener) {
client.validateQuery(request, listener);
}
}

View File

@ -1,75 +0,0 @@
package org.elasticsearch.client.action.validate;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
import org.elasticsearch.action.validate.ValidateRequest;
import org.elasticsearch.action.validate.ValidateResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.action.support.BaseRequestBuilder;
import org.elasticsearch.index.query.QueryBuilder;
/**
*
*/
public class ValidateRequestBuilder extends BaseRequestBuilder<ValidateRequest, ValidateResponse> {
public ValidateRequestBuilder(Client client) {
super(client, new ValidateRequest());
}
/**
* Sets the indices the query validation will run against.
*/
public ValidateRequestBuilder setIndices(String... indices) {
request.indices(indices);
return this;
}
/**
* The types of documents the query will run against. Defaults to all types.
*/
public ValidateRequestBuilder setTypes(String... types) {
request.types(types);
return this;
}
/**
* The query source to validate.
*
* @see org.elasticsearch.index.query.QueryBuilders
*/
public ValidateRequestBuilder setQuery(QueryBuilder queryBuilder) {
request.query(queryBuilder);
return this;
}
/**
* The query source to validate.
*
* @see org.elasticsearch.index.query.QueryBuilders
*/
public ValidateRequestBuilder setQuery(byte[] querySource) {
request.query(querySource);
return this;
}
/**
* Controls the operation threading model.
*/
public ValidateRequestBuilder setOperationThreading(BroadcastOperationThreading operationThreading) {
request.operationThreading(operationThreading);
return this;
}
/**
* Should the listener be called on a separate thread if needed.
*/
public ValidateRequestBuilder setListenerThreaded(boolean threadedListener) {
request.listenerThreaded(threadedListener);
return this;
}
@Override
protected void doExecute(ActionListener<ValidateResponse> listener) {
client.validate(request, listener);
}
}

View File

@ -43,11 +43,7 @@ import org.elasticsearch.action.percolate.PercolateRequest;
import org.elasticsearch.action.percolate.PercolateResponse;
import org.elasticsearch.action.percolate.TransportPercolateAction;
import org.elasticsearch.action.search.*;
import org.elasticsearch.action.validate.TransportValidateAction;
import org.elasticsearch.action.validate.ValidateRequest;
import org.elasticsearch.action.validate.ValidateResponse;
import org.elasticsearch.client.AdminClient;
import org.elasticsearch.client.action.validate.ValidateRequestBuilder;
import org.elasticsearch.client.internal.InternalClient;
import org.elasticsearch.client.support.AbstractClient;
import org.elasticsearch.common.inject.Inject;
@ -77,8 +73,6 @@ public class NodeClient extends AbstractClient implements InternalClient {
private final TransportCountAction countAction;
private final TransportValidateAction validateAction;
private final TransportSearchAction searchAction;
private final TransportSearchScrollAction searchScrollAction;
@ -91,7 +85,7 @@ public class NodeClient extends AbstractClient implements InternalClient {
public NodeClient(Settings settings, ThreadPool threadPool, NodeAdminClient admin,
TransportIndexAction indexAction, TransportDeleteAction deleteAction, TransportBulkAction bulkAction,
TransportDeleteByQueryAction deleteByQueryAction, TransportGetAction getAction, TransportMultiGetAction multiGetAction, TransportCountAction countAction,
TransportSearchAction searchAction, TransportValidateAction validateAction, TransportSearchScrollAction searchScrollAction,
TransportSearchAction searchAction, TransportSearchScrollAction searchScrollAction,
TransportMoreLikeThisAction moreLikeThisAction, TransportPercolateAction percolateAction) {
this.threadPool = threadPool;
this.admin = admin;
@ -102,7 +96,6 @@ public class NodeClient extends AbstractClient implements InternalClient {
this.getAction = getAction;
this.multiGetAction = multiGetAction;
this.countAction = countAction;
this.validateAction = validateAction;
this.searchAction = searchAction;
this.searchScrollAction = searchScrollAction;
this.moreLikeThisAction = moreLikeThisAction;
@ -194,16 +187,6 @@ public class NodeClient extends AbstractClient implements InternalClient {
countAction.execute(request, listener);
}
@Override
public ActionFuture<ValidateResponse> validate(ValidateRequest request) {
return validateAction.execute(request);
}
@Override
public void validate(ValidateRequest request, ActionListener<ValidateResponse> listener) {
validateAction.execute(request, listener);
}
@Override
public ActionFuture<SearchResponse> search(SearchRequest request) {
return searchAction.execute(request);

View File

@ -81,6 +81,9 @@ import org.elasticsearch.action.admin.indices.template.delete.TransportDeleteInd
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse;
import org.elasticsearch.action.admin.indices.template.put.TransportPutIndexTemplateAction;
import org.elasticsearch.action.admin.indices.validate.query.TransportValidateQueryAction;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.support.AbstractIndicesAdminClient;
import org.elasticsearch.common.inject.Inject;
@ -134,6 +137,8 @@ public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implement
private final TransportDeleteIndexTemplateAction deleteIndexTemplateAction;
private final TransportValidateQueryAction validateQueryAction;
@Inject
public NodeIndicesAdminClient(Settings settings, ThreadPool threadPool, TransportIndicesExistsAction indicesExistsAction, TransportIndicesStatsAction indicesStatsAction, TransportIndicesStatusAction indicesStatusAction, TransportIndicesSegmentsAction indicesSegmentsAction,
TransportCreateIndexAction createIndexAction, TransportDeleteIndexAction deleteIndexAction,
@ -142,7 +147,7 @@ public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implement
TransportPutMappingAction putMappingAction, TransportDeleteMappingAction deleteMappingAction, TransportGatewaySnapshotAction gatewaySnapshotAction,
TransportIndicesAliasesAction indicesAliasesAction, TransportClearIndicesCacheAction clearIndicesCacheAction,
TransportUpdateSettingsAction updateSettingsAction, TransportAnalyzeAction analyzeAction,
TransportPutIndexTemplateAction putIndexTemplateAction, TransportDeleteIndexTemplateAction deleteIndexTemplateAction) {
TransportPutIndexTemplateAction putIndexTemplateAction, TransportDeleteIndexTemplateAction deleteIndexTemplateAction, TransportValidateQueryAction validateQueryAction) {
this.threadPool = threadPool;
this.indicesExistsAction = indicesExistsAction;
this.indicesStatsAction = indicesStatsAction;
@ -164,6 +169,7 @@ public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implement
this.analyzeAction = analyzeAction;
this.putIndexTemplateAction = putIndexTemplateAction;
this.deleteIndexTemplateAction = deleteIndexTemplateAction;
this.validateQueryAction = validateQueryAction;
}
@Override
@ -370,4 +376,14 @@ public class NodeIndicesAdminClient extends AbstractIndicesAdminClient implement
public void deleteTemplate(DeleteIndexTemplateRequest request, ActionListener<DeleteIndexTemplateResponse> listener) {
deleteIndexTemplateAction.execute(request, listener);
}
@Override
public ActionFuture<ValidateQueryResponse> validateQuery(ValidateQueryRequest request) {
return validateQueryAction.execute(request);
}
@Override
public void validateQuery(ValidateQueryRequest request, ActionListener<ValidateQueryResponse> listener) {
validateQueryAction.execute(request, listener);
}
}

View File

@ -30,7 +30,6 @@ import org.elasticsearch.client.action.mlt.MoreLikeThisRequestBuilder;
import org.elasticsearch.client.action.percolate.PercolateRequestBuilder;
import org.elasticsearch.client.action.search.SearchRequestBuilder;
import org.elasticsearch.client.action.search.SearchScrollRequestBuilder;
import org.elasticsearch.client.action.validate.ValidateRequestBuilder;
import org.elasticsearch.client.internal.InternalClient;
import org.elasticsearch.common.Nullable;
@ -104,11 +103,6 @@ public abstract class AbstractClient implements InternalClient {
return new CountRequestBuilder(this).setIndices(indices);
}
@Override
public ValidateRequestBuilder prepareValidate(String... indices) {
return new ValidateRequestBuilder(this).setIndices(indices);
}
@Override
public MoreLikeThisRequestBuilder prepareMoreLikeThis(String index, String type, String id) {
return new MoreLikeThisRequestBuilder(this, index, type, id);

View File

@ -39,6 +39,7 @@ import org.elasticsearch.client.action.admin.indices.stats.IndicesStatsRequestBu
import org.elasticsearch.client.action.admin.indices.status.IndicesStatusRequestBuilder;
import org.elasticsearch.client.action.admin.indices.template.delete.DeleteIndexTemplateRequestBuilder;
import org.elasticsearch.client.action.admin.indices.template.put.PutIndexTemplateRequestBuilder;
import org.elasticsearch.client.action.admin.indices.validate.query.ValidateQueryRequestBuilder;
import org.elasticsearch.client.internal.InternalIndicesAdminClient;
import org.elasticsearch.common.Nullable;
@ -151,4 +152,9 @@ public abstract class AbstractIndicesAdminClient implements InternalIndicesAdmin
public DeleteIndexTemplateRequestBuilder prepareDeleteTemplate(String name) {
return new DeleteIndexTemplateRequestBuilder(this, name);
}
@Override
public ValidateQueryRequestBuilder prepareValidateQuery(String... indices) {
return new ValidateQueryRequestBuilder(this).setIndices(indices);
}
}

View File

@ -43,8 +43,6 @@ import org.elasticsearch.action.percolate.PercolateResponse;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchScrollRequest;
import org.elasticsearch.action.validate.ValidateRequest;
import org.elasticsearch.action.validate.ValidateResponse;
import org.elasticsearch.client.AdminClient;
import org.elasticsearch.client.support.AbstractClient;
import org.elasticsearch.client.transport.action.ClientTransportActionModule;
@ -321,16 +319,6 @@ public class TransportClient extends AbstractClient {
internalClient.count(request, listener);
}
@Override
public ActionFuture<ValidateResponse> validate(ValidateRequest request) {
return internalClient.validate(request);
}
@Override
public void validate(ValidateRequest request, ActionListener<ValidateResponse> listener) {
internalClient.validate(request, listener);
}
@Override
public ActionFuture<SearchResponse> search(SearchRequest request) {
return internalClient.search(request);

View File

@ -0,0 +1,25 @@
package org.elasticsearch.client.transport.action.admin.indices.validate.query;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
import org.elasticsearch.client.transport.action.support.BaseClientTransportAction;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.transport.TransportService;
/**
*
*/
public class ClientTransportValidateQueryAction extends BaseClientTransportAction<ValidateQueryRequest, ValidateQueryResponse> {
@Inject
public ClientTransportValidateQueryAction(Settings settings, TransportService transportService) {
super(settings, transportService, ValidateQueryResponse.class);
}
@Override
protected String action() {
return TransportActions.Admin.Indices.VALIDATE_QUERY;
}
}

View File

@ -1,25 +0,0 @@
package org.elasticsearch.client.transport.action.validate;
import org.elasticsearch.action.TransportActions;
import org.elasticsearch.action.validate.ValidateRequest;
import org.elasticsearch.action.validate.ValidateResponse;
import org.elasticsearch.client.transport.action.support.BaseClientTransportAction;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.transport.TransportService;
/**
*
*/
public class ClientTransportValidateAction extends BaseClientTransportAction<ValidateRequest, ValidateResponse> {
@Inject
public ClientTransportValidateAction(Settings settings, TransportService transportService) {
super(settings, transportService, ValidateResponse.class);
}
@Override
protected String action() {
return TransportActions.VALIDATE;
}
}

View File

@ -42,8 +42,6 @@ import org.elasticsearch.action.percolate.PercolateResponse;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchScrollRequest;
import org.elasticsearch.action.validate.ValidateRequest;
import org.elasticsearch.action.validate.ValidateResponse;
import org.elasticsearch.client.AdminClient;
import org.elasticsearch.client.internal.InternalClient;
import org.elasticsearch.client.support.AbstractClient;
@ -59,7 +57,6 @@ import org.elasticsearch.client.transport.action.mlt.ClientTransportMoreLikeThis
import org.elasticsearch.client.transport.action.percolate.ClientTransportPercolateAction;
import org.elasticsearch.client.transport.action.search.ClientTransportSearchAction;
import org.elasticsearch.client.transport.action.search.ClientTransportSearchScrollAction;
import org.elasticsearch.client.transport.action.validate.ClientTransportValidateAction;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
@ -90,8 +87,6 @@ public class InternalTransportClient extends AbstractClient implements InternalC
private final ClientTransportCountAction countAction;
private final ClientTransportValidateAction validateAction;
private final ClientTransportSearchAction searchAction;
private final ClientTransportSearchScrollAction searchScrollAction;
@ -104,7 +99,7 @@ public class InternalTransportClient extends AbstractClient implements InternalC
public InternalTransportClient(Settings settings, ThreadPool threadPool,
TransportClientNodesService nodesService, InternalTransportAdminClient adminClient,
ClientTransportIndexAction indexAction, ClientTransportDeleteAction deleteAction, ClientTransportBulkAction bulkAction, ClientTransportGetAction getAction, ClientTransportMultiGetAction multiGetAction,
ClientTransportDeleteByQueryAction deleteByQueryAction, ClientTransportCountAction countAction, ClientTransportValidateAction validateAction,
ClientTransportDeleteByQueryAction deleteByQueryAction, ClientTransportCountAction countAction,
ClientTransportSearchAction searchAction, ClientTransportSearchScrollAction searchScrollAction,
ClientTransportMoreLikeThisAction moreLikeThisAction, ClientTransportPercolateAction percolateAction) {
this.threadPool = threadPool;
@ -118,7 +113,6 @@ public class InternalTransportClient extends AbstractClient implements InternalC
this.multiGetAction = multiGetAction;
this.deleteByQueryAction = deleteByQueryAction;
this.countAction = countAction;
this.validateAction = validateAction;
this.searchAction = searchAction;
this.searchScrollAction = searchScrollAction;
this.moreLikeThisAction = moreLikeThisAction;
@ -280,26 +274,6 @@ public class InternalTransportClient extends AbstractClient implements InternalC
}, listener);
}
@Override
public ActionFuture<ValidateResponse> validate(final ValidateRequest request) {
return nodesService.execute(new TransportClientNodesService.NodeCallback<ActionFuture<ValidateResponse>>() {
@Override
public ActionFuture<ValidateResponse> doWithNode(DiscoveryNode node) throws ElasticSearchException {
return validateAction.execute(node, request);
}
});
}
@Override
public void validate(final ValidateRequest request, final ActionListener<ValidateResponse> listener) {
nodesService.execute(new TransportClientNodesService.NodeListenerCallback<ValidateResponse>() {
@Override
public void doWithNode(DiscoveryNode node, ActionListener<ValidateResponse> listener) throws ElasticSearchException {
validateAction.execute(node, request, listener);
}
}, listener);
}
@Override
public ActionFuture<SearchResponse> search(final SearchRequest request) {
return nodesService.execute(new TransportClientNodesService.NodeCallback<ActionFuture<SearchResponse>>() {

View File

@ -62,6 +62,8 @@ import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplat
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
import org.elasticsearch.client.IndicesAdminClient;
import org.elasticsearch.client.support.AbstractIndicesAdminClient;
import org.elasticsearch.client.transport.TransportClientNodesService;
@ -85,6 +87,7 @@ import org.elasticsearch.client.transport.action.admin.indices.stats.ClientTrans
import org.elasticsearch.client.transport.action.admin.indices.status.ClientTransportIndicesStatusAction;
import org.elasticsearch.client.transport.action.admin.indices.template.delete.ClientTransportDeleteIndexTemplateAction;
import org.elasticsearch.client.transport.action.admin.indices.template.put.ClientTransportPutIndexTemplateAction;
import org.elasticsearch.client.transport.action.admin.indices.validate.query.ClientTransportValidateQueryAction;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
@ -139,6 +142,8 @@ public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminCli
private final ClientTransportDeleteIndexTemplateAction deleteIndexTemplateAction;
private final ClientTransportValidateQueryAction validateQueryAction;
@Inject
public InternalTransportIndicesAdminClient(Settings settings, TransportClientNodesService nodesService, ThreadPool threadPool,
ClientTransportIndicesExistsAction indicesExistsAction, ClientTransportIndicesStatusAction indicesStatusAction, ClientTransportIndicesStatsAction indicesStatsAction, ClientTransportIndicesSegmentsAction indicesSegmentsAction,
@ -147,7 +152,7 @@ public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminCli
ClientTransportRefreshAction refreshAction, ClientTransportFlushAction flushAction, ClientTransportOptimizeAction optimizeAction,
ClientTransportPutMappingAction putMappingAction, ClientTransportDeleteMappingAction deleteMappingAction, ClientTransportGatewaySnapshotAction gatewaySnapshotAction,
ClientTransportIndicesAliasesAction indicesAliasesAction, ClientTransportClearIndicesCacheAction clearIndicesCacheAction,
ClientTransportUpdateSettingsAction updateSettingsAction, ClientTransportAnalyzeAction analyzeAction,
ClientTransportUpdateSettingsAction updateSettingsAction, ClientTransportAnalyzeAction analyzeAction, ClientTransportValidateQueryAction validateQueryAction,
ClientTransportPutIndexTemplateAction putIndexTemplateAction, ClientTransportDeleteIndexTemplateAction deleteIndexTemplateAction) {
this.nodesService = nodesService;
this.threadPool = threadPool;
@ -171,6 +176,7 @@ public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminCli
this.analyzeAction = analyzeAction;
this.putIndexTemplateAction = putIndexTemplateAction;
this.deleteIndexTemplateAction = deleteIndexTemplateAction;
this.validateQueryAction = validateQueryAction;
}
@Override
@ -577,4 +583,24 @@ public class InternalTransportIndicesAdminClient extends AbstractIndicesAdminCli
}
}, listener);
}
@Override
public ActionFuture<ValidateQueryResponse> validateQuery(final ValidateQueryRequest request) {
return nodesService.execute(new TransportClientNodesService.NodeCallback<ActionFuture<ValidateQueryResponse>>() {
@Override
public ActionFuture<ValidateQueryResponse> doWithNode(DiscoveryNode node) throws ElasticSearchException {
return validateQueryAction.execute(node, request);
}
});
}
@Override
public void validateQuery(final ValidateQueryRequest request, final ActionListener<ValidateQueryResponse> listener) {
nodesService.execute(new TransportClientNodesService.NodeListenerCallback<ValidateQueryResponse>() {
@Override
public void doWithNode(DiscoveryNode node, ActionListener<ValidateQueryResponse> listener) throws ElasticSearchException {
validateQueryAction.execute(node, request, listener);
}
}, listener);
}
}

View File

@ -105,10 +105,6 @@ public interface IndexShard extends IndexShardComponent {
Engine.Searcher searcher();
boolean validate(byte[] querySource, @Nullable String[] filteringAliases, String... types) throws ElasticSearchException;
boolean validate(byte[] querySource, int querySourceOffset, int querySourceLength, @Nullable String[] filteringAliases, String... types) throws ElasticSearchException;
/**
* Returns <tt>true</tt> if this shard can ignore a recovery attempt made to it (since the already doing/done it)
*/

View File

@ -51,7 +51,6 @@ import org.elasticsearch.index.mapper.*;
import org.elasticsearch.index.merge.MergeStats;
import org.elasticsearch.index.merge.scheduler.MergeSchedulerProvider;
import org.elasticsearch.index.query.IndexQueryParserService;
import org.elasticsearch.index.query.QueryParsingException;
import org.elasticsearch.index.refresh.RefreshStats;
import org.elasticsearch.index.search.stats.SearchStats;
import org.elasticsearch.index.search.stats.ShardSearchService;
@ -519,28 +518,6 @@ public class InternalIndexShard extends AbstractIndexShardComponent implements I
return engine.searcher();
}
@Override
public boolean validate(byte[] querySource, @Nullable String[] filteringAliases, String... types) throws ElasticSearchException {
return validate(querySource, 0, querySource.length, filteringAliases, types);
}
@Override
public boolean validate(byte[] querySource, int querySourceOffset, int querySourceLength, @Nullable String[] filteringAliases, String... types) throws ElasticSearchException {
readAllowed();
if (querySourceLength == 0) {
return true;
} else {
try {
queryParserService.parse(querySource, querySourceOffset, querySourceLength);
} catch (QueryParsingException e) {
return false;
} catch (AssertionError e) {
return false;
}
}
return true;
}
public void close(String reason) {
synchronized (mutex) {
indexSettingsService.removeListener(applyRefreshSettings);

View File

@ -58,6 +58,7 @@ import org.elasticsearch.rest.action.admin.indices.status.RestIndicesStatusActio
import org.elasticsearch.rest.action.admin.indices.template.delete.RestDeleteIndexTemplateAction;
import org.elasticsearch.rest.action.admin.indices.template.get.RestGetIndexTemplateAction;
import org.elasticsearch.rest.action.admin.indices.template.put.RestPutIndexTemplateAction;
import org.elasticsearch.rest.action.admin.indices.validate.query.RestValidateQueryAction;
import org.elasticsearch.rest.action.bulk.RestBulkAction;
import org.elasticsearch.rest.action.count.RestCountAction;
import org.elasticsearch.rest.action.delete.RestDeleteAction;
@ -70,7 +71,6 @@ import org.elasticsearch.rest.action.mlt.RestMoreLikeThisAction;
import org.elasticsearch.rest.action.percolate.RestPercolateAction;
import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.rest.action.search.RestSearchScrollAction;
import org.elasticsearch.rest.action.validate.RestValidateAction;
import java.util.List;
@ -151,7 +151,7 @@ public class RestActionModule extends AbstractModule {
bind(RestSearchAction.class).asEagerSingleton();
bind(RestSearchScrollAction.class).asEagerSingleton();
bind(RestValidateAction.class).asEagerSingleton();
bind(RestValidateQueryAction.class).asEagerSingleton();
bind(RestMoreLikeThisAction.class).asEagerSingleton();

View File

@ -17,12 +17,12 @@
* under the License.
*/
package org.elasticsearch.rest.action.validate;
package org.elasticsearch.rest.action.admin.indices.validate.query;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.broadcast.BroadcastOperationThreading;
import org.elasticsearch.action.validate.ValidateRequest;
import org.elasticsearch.action.validate.ValidateResponse;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequest;
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
@ -43,45 +43,45 @@ import static org.elasticsearch.rest.action.support.RestActions.splitTypes;
/**
*
*/
public class RestValidateAction extends BaseRestHandler {
public class RestValidateQueryAction extends BaseRestHandler {
@Inject
public RestValidateAction(Settings settings, Client client, RestController controller) {
public RestValidateQueryAction(Settings settings, Client client, RestController controller) {
super(settings, client);
controller.registerHandler(GET, "/_validate", this);
controller.registerHandler(POST, "/_validate", this);
controller.registerHandler(GET, "/{index}/_validate", this);
controller.registerHandler(POST, "/{index}/_validate", this);
controller.registerHandler(GET, "/{index}/{type}/_validate", this);
controller.registerHandler(POST, "/{index}/{type}/_validate", this);
controller.registerHandler(GET, "/_validate/query", this);
controller.registerHandler(POST, "/_validate/query", this);
controller.registerHandler(GET, "/{index}/_validate/query", this);
controller.registerHandler(POST, "/{index}/_validate/query", this);
controller.registerHandler(GET, "/{index}/{type}/_validate/query", this);
controller.registerHandler(POST, "/{index}/{type}/_validate/query", this);
}
@Override
public void handleRequest(final RestRequest request, final RestChannel channel) {
ValidateRequest validateRequest = new ValidateRequest(RestActions.splitIndices(request.param("index")));
ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest(RestActions.splitIndices(request.param("index")));
// we just send back a response, no need to fork a listener
validateRequest.listenerThreaded(false);
validateQueryRequest.listenerThreaded(false);
try {
BroadcastOperationThreading operationThreading = BroadcastOperationThreading.fromString(request.param("operation_threading"), BroadcastOperationThreading.SINGLE_THREAD);
if (operationThreading == BroadcastOperationThreading.NO_THREADS) {
// since we don't spawn, don't allow no_threads, but change it to a single thread
operationThreading = BroadcastOperationThreading.SINGLE_THREAD;
}
validateRequest.operationThreading(operationThreading);
validateQueryRequest.operationThreading(operationThreading);
if (request.hasContent()) {
validateRequest.query(request.contentByteArray(), request.contentByteArrayOffset(), request.contentLength(), true);
validateQueryRequest.query(request.contentByteArray(), request.contentByteArrayOffset(), request.contentLength(), true);
} else {
String source = request.param("source");
if (source != null) {
validateRequest.query(source);
validateQueryRequest.query(source);
} else {
byte[] querySource = RestActions.parseQuerySource(request);
if (querySource != null) {
validateRequest.query(querySource);
validateQueryRequest.query(querySource);
}
}
}
validateRequest.types(splitTypes(request.param("type")));
validateQueryRequest.types(splitTypes(request.param("type")));
} catch (Exception e) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
@ -92,9 +92,9 @@ public class RestValidateAction extends BaseRestHandler {
return;
}
client.validate(validateRequest, new ActionListener<ValidateResponse>() {
client.admin().indices().validateQuery(validateQueryRequest, new ActionListener<ValidateQueryResponse>() {
@Override
public void onResponse(ValidateResponse response) {
public void onResponse(ValidateQueryResponse response) {
try {
XContentBuilder builder = RestXContentBuilder.restContentBuilder(request);
builder.startObject();

View File

@ -34,7 +34,7 @@ import static org.hamcrest.Matchers.*;
/**
*
*/
public class SimpleValidateTests extends AbstractNodesTests {
public class SimpleValidateQueryTests extends AbstractNodesTests {
private Client client;
@ -70,15 +70,15 @@ public class SimpleValidateTests extends AbstractNodesTests {
client.admin().indices().prepareRefresh().execute().actionGet();
assertThat(client.prepareValidate("test").setQuery("foo".getBytes()).execute().actionGet().valid(), equalTo(false));
assertThat(client.prepareValidate("test").setQuery(QueryBuilders.queryString("_id:1")).execute().actionGet().valid(), equalTo(true));
assertThat(client.prepareValidate("test").setQuery(QueryBuilders.queryString("_i:d:1")).execute().actionGet().valid(), equalTo(false));
assertThat(client.admin().indices().prepareValidateQuery("test").setQuery("foo".getBytes()).execute().actionGet().valid(), equalTo(false));
assertThat(client.admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryString("_id:1")).execute().actionGet().valid(), equalTo(true));
assertThat(client.admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryString("_i:d:1")).execute().actionGet().valid(), equalTo(false));
assertThat(client.prepareValidate("test").setQuery(QueryBuilders.queryString("foo:1")).execute().actionGet().valid(), equalTo(true));
assertThat(client.prepareValidate("test").setQuery(QueryBuilders.queryString("bar:hey")).execute().actionGet().valid(), equalTo(false));
assertThat(client.admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryString("foo:1")).execute().actionGet().valid(), equalTo(true));
assertThat(client.admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryString("bar:hey")).execute().actionGet().valid(), equalTo(false));
assertThat(client.prepareValidate("test").setQuery(QueryBuilders.queryString("nonexistent:hello")).execute().actionGet().valid(), equalTo(true));
assertThat(client.admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryString("nonexistent:hello")).execute().actionGet().valid(), equalTo(true));
assertThat(client.prepareValidate("test").setQuery(QueryBuilders.queryString("foo:1 AND")).execute().actionGet().valid(), equalTo(false));
assertThat(client.admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryString("foo:1 AND")).execute().actionGet().valid(), equalTo(false));
}
}