parent
15a63f3ec7
commit
a6e7a5f307
|
@ -1,47 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.action.count;
|
||||
|
||||
import org.elasticsearch.action.Action;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
|
||||
/**
|
||||
* Action that shortcuts to the search api with size set to 0. It doesn't have a corresponding
|
||||
* transport action, it just runs the search api internally.
|
||||
*/
|
||||
public class CountAction extends Action<CountRequest, CountResponse, CountRequestBuilder> {
|
||||
|
||||
public static final CountAction INSTANCE = new CountAction();
|
||||
public static final String NAME = "indices:data/read/count";
|
||||
|
||||
private CountAction() {
|
||||
super(NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CountResponse newResponse() {
|
||||
throw new UnsupportedOperationException("CountAction doesn't have its own transport action, gets executed as a SearchAction internally");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CountRequestBuilder newRequestBuilder(ElasticsearchClient client) {
|
||||
return new CountRequestBuilder(client, this);
|
||||
}
|
||||
}
|
|
@ -1,175 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.action.count;
|
||||
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastRequest;
|
||||
import org.elasticsearch.common.Nullable;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* A request to count the number of documents matching a specific query. Best created with
|
||||
* {@link org.elasticsearch.client.Requests#countRequest(String...)}.
|
||||
*
|
||||
* @see CountResponse
|
||||
* @see org.elasticsearch.client.Client#count(CountRequest)
|
||||
* @see org.elasticsearch.client.Requests#countRequest(String...)
|
||||
*/
|
||||
public class CountRequest extends BroadcastRequest<CountRequest> {
|
||||
|
||||
@Nullable
|
||||
protected String routing;
|
||||
|
||||
@Nullable
|
||||
private String preference;
|
||||
|
||||
private String[] types = Strings.EMPTY_ARRAY;
|
||||
|
||||
private final SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
|
||||
/**
|
||||
* Constructs a new count request against the provided indices. No indices provided means it will
|
||||
* run against all indices.
|
||||
*/
|
||||
public CountRequest(String... indices) {
|
||||
super(indices);
|
||||
searchSourceBuilder.size(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* The minimum score of the documents to include in the count.
|
||||
*/
|
||||
public Float minScore() {
|
||||
return searchSourceBuilder.minScore();
|
||||
}
|
||||
|
||||
/**
|
||||
* The minimum score of the documents to include in the count. Defaults to <tt>-1</tt> which means all
|
||||
* documents will be included in the count.
|
||||
*/
|
||||
public CountRequest minScore(float minScore) {
|
||||
this.searchSourceBuilder.minScore(minScore);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The query to execute
|
||||
*/
|
||||
public CountRequest query(QueryBuilder<?> queryBuilder) {
|
||||
this.searchSourceBuilder.query(queryBuilder);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The types of documents the query will run against. Defaults to all types.
|
||||
*/
|
||||
public String[] types() {
|
||||
return this.types;
|
||||
}
|
||||
|
||||
/**
|
||||
* The types of documents the query will run against. Defaults to all types.
|
||||
*/
|
||||
public CountRequest types(String... types) {
|
||||
this.types = types;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A comma separated list of routing values to control the shards the search will be executed on.
|
||||
*/
|
||||
public String routing() {
|
||||
return this.routing;
|
||||
}
|
||||
|
||||
/**
|
||||
* A comma separated list of routing values to control the shards the search will be executed on.
|
||||
*/
|
||||
public CountRequest routing(String routing) {
|
||||
this.routing = routing;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The routing values to control the shards that the search will be executed on.
|
||||
*/
|
||||
public CountRequest routing(String... routings) {
|
||||
this.routing = Strings.arrayToCommaDelimitedString(routings);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CountRequest preference(String preference) {
|
||||
this.preference = preference;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String preference() {
|
||||
return this.preference;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upon reaching <code>terminateAfter</code> counts, the count request will early terminate
|
||||
*/
|
||||
public CountRequest terminateAfter(int terminateAfterCount) {
|
||||
this.searchSourceBuilder.terminateAfter(terminateAfterCount);
|
||||
return this;
|
||||
}
|
||||
|
||||
public int terminateAfter() {
|
||||
return this.searchSourceBuilder.terminateAfter();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
throw new UnsupportedOperationException("CountRequest doesn't support being sent over the wire, just a shortcut to the search api");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
throw new UnsupportedOperationException("CountRequest doesn't support being sent over the wire, just a shortcut to the search api");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "count request indices:" + Arrays.toString(indices) +
|
||||
", types:" + Arrays.toString(types) +
|
||||
", routing: " + routing +
|
||||
", preference: " + preference +
|
||||
", source:" + searchSourceBuilder.toString();
|
||||
}
|
||||
|
||||
public SearchRequest toSearchRequest() {
|
||||
SearchRequest searchRequest = new SearchRequest(indices());
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
searchRequest.indicesOptions(indicesOptions());
|
||||
searchRequest.types(types());
|
||||
searchRequest.routing(routing());
|
||||
searchRequest.preference(preference());
|
||||
return searchRequest;
|
||||
}
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.action.count;
|
||||
|
||||
import org.elasticsearch.action.ActionListener;
|
||||
import org.elasticsearch.action.search.SearchAction;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.support.DelegatingActionListener;
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastOperationRequestBuilder;
|
||||
import org.elasticsearch.client.ElasticsearchClient;
|
||||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
|
||||
/**
|
||||
* A count action request builder.
|
||||
*/
|
||||
public class CountRequestBuilder extends BroadcastOperationRequestBuilder<CountRequest, CountResponse, CountRequestBuilder> {
|
||||
|
||||
public CountRequestBuilder(ElasticsearchClient client, CountAction action) {
|
||||
super(client, action, new CountRequest());
|
||||
}
|
||||
|
||||
/**
|
||||
* The types of documents the query will run against. Defaults to all types.
|
||||
*/
|
||||
public CountRequestBuilder setTypes(String... types) {
|
||||
request.types(types);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The minimum score of the documents to include in the count. Defaults to <tt>-1</tt> which means all
|
||||
* documents will be included in the count.
|
||||
*/
|
||||
public CountRequestBuilder setMinScore(float minScore) {
|
||||
request.minScore(minScore);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* A comma separated list of routing values to control the shards the search will be executed on.
|
||||
*/
|
||||
public CountRequestBuilder setRouting(String routing) {
|
||||
request.routing(routing);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the preference to execute the search. Defaults to randomize across shards. Can be set to
|
||||
* <tt>_local</tt> to prefer local shards, <tt>_primary</tt> to execute only on primary shards,
|
||||
* _shards:x,y to operate on shards x & y, or a custom value, which guarantees that the same order
|
||||
* will be used across different requests.
|
||||
*/
|
||||
public CountRequestBuilder setPreference(String preference) {
|
||||
request.preference(preference);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The routing values to control the shards that the search will be executed on.
|
||||
*/
|
||||
public CountRequestBuilder setRouting(String... routing) {
|
||||
request.routing(routing);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* The query source to execute.
|
||||
*/
|
||||
public CountRequestBuilder setQuery(QueryBuilder<?> builder) {
|
||||
request.query(builder);
|
||||
return this;
|
||||
}
|
||||
|
||||
public CountRequestBuilder setTerminateAfter(int terminateAfter) {
|
||||
request().terminateAfter(terminateAfter);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(ActionListener<CountResponse> listener) {
|
||||
CountRequest countRequest = beforeExecute(request);
|
||||
client.execute(SearchAction.INSTANCE, countRequest.toSearchRequest(), new DelegatingActionListener<SearchResponse, CountResponse>(listener) {
|
||||
@Override
|
||||
protected CountResponse getDelegatedFromInstigator(SearchResponse response) {
|
||||
return new CountResponse(response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return request.toString();
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.action.count;
|
||||
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.support.broadcast.BroadcastResponse;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* The response of the count action.
|
||||
*/
|
||||
public class CountResponse extends BroadcastResponse {
|
||||
|
||||
private final boolean terminatedEarly;
|
||||
private final long count;
|
||||
|
||||
public CountResponse(SearchResponse searchResponse) {
|
||||
super(searchResponse.getTotalShards(), searchResponse.getSuccessfulShards(), searchResponse.getFailedShards(), Arrays.asList(searchResponse.getShardFailures()));
|
||||
this.count = searchResponse.getHits().totalHits();
|
||||
this.terminatedEarly = searchResponse.isTerminatedEarly() != null && searchResponse.isTerminatedEarly();
|
||||
}
|
||||
|
||||
/**
|
||||
* The count of documents matching the query provided.
|
||||
*/
|
||||
public long getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* True if the request has been terminated early due to enough count
|
||||
*/
|
||||
public boolean terminatedEarly() {
|
||||
return this.terminatedEarly;
|
||||
}
|
||||
|
||||
public RestStatus status() {
|
||||
return RestStatus.status(getSuccessfulShards(), getTotalShards(), getShardFailures());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFrom(StreamInput in) throws IOException {
|
||||
throw new UnsupportedOperationException("CountResponse doesn't support being sent over the wire, just a shortcut to the search api");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeTo(StreamOutput out) throws IOException {
|
||||
throw new UnsupportedOperationException("CountResponse doesn't support being sent over the wire, just a shortcut to the search api");
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Count action.
|
||||
*/
|
||||
package org.elasticsearch.action.count;
|
|
@ -24,9 +24,6 @@ import org.elasticsearch.action.ActionListener;
|
|||
import org.elasticsearch.action.bulk.BulkRequest;
|
||||
import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
||||
import org.elasticsearch.action.bulk.BulkResponse;
|
||||
import org.elasticsearch.action.count.CountRequest;
|
||||
import org.elasticsearch.action.count.CountRequestBuilder;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.delete.DeleteRequest;
|
||||
import org.elasticsearch.action.delete.DeleteRequestBuilder;
|
||||
import org.elasticsearch.action.delete.DeleteResponse;
|
||||
|
@ -337,29 +334,6 @@ public interface Client extends ElasticsearchClient, Releasable {
|
|||
*/
|
||||
MultiGetRequestBuilder prepareMultiGet();
|
||||
|
||||
/**
|
||||
* A count of all the documents matching a specific query.
|
||||
*
|
||||
* @param request The count request
|
||||
* @return The result future
|
||||
* @see Requests#countRequest(String...)
|
||||
*/
|
||||
ActionFuture<CountResponse> count(CountRequest 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 count(CountRequest request, ActionListener<CountResponse> listener);
|
||||
|
||||
/**
|
||||
* A count of all the documents matching a specific query.
|
||||
*/
|
||||
CountRequestBuilder prepareCount(String... indices);
|
||||
|
||||
/**
|
||||
* Checks existence of any documents matching a specific query.
|
||||
*
|
||||
|
|
|
@ -725,7 +725,6 @@ public interface IndicesAdminClient extends ElasticsearchClient {
|
|||
*
|
||||
* @param request The count request
|
||||
* @return The result future
|
||||
* @see Requests#countRequest(String...)
|
||||
*/
|
||||
ActionFuture<ValidateQueryResponse> validateQuery(ValidateQueryRequest request);
|
||||
|
||||
|
@ -734,7 +733,6 @@ public interface IndicesAdminClient extends ElasticsearchClient {
|
|||
*
|
||||
* @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);
|
||||
|
||||
|
|
|
@ -52,7 +52,6 @@ import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest
|
|||
import org.elasticsearch.action.admin.indices.shards.IndicesShardStoresRequest;
|
||||
import org.elasticsearch.action.admin.indices.upgrade.post.UpgradeRequest;
|
||||
import org.elasticsearch.action.bulk.BulkRequest;
|
||||
import org.elasticsearch.action.count.CountRequest;
|
||||
import org.elasticsearch.action.delete.DeleteRequest;
|
||||
import org.elasticsearch.action.exists.ExistsRequest;
|
||||
import org.elasticsearch.action.get.GetRequest;
|
||||
|
@ -124,18 +123,6 @@ public class Requests {
|
|||
return new GetRequest(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a count request which counts the hits matched against a query. Note, the query itself must be set
|
||||
* either using the JSON source of the query, or using a {@link org.elasticsearch.index.query.QueryBuilder} (using {@link org.elasticsearch.index.query.QueryBuilders}).
|
||||
*
|
||||
* @param indices The indices to count matched documents against a query. Use <tt>null</tt> or <tt>_all</tt> to execute against all indices
|
||||
* @return The count request
|
||||
* @see org.elasticsearch.client.Client#count(org.elasticsearch.action.count.CountRequest)
|
||||
*/
|
||||
public static CountRequest countRequest(String... indices) {
|
||||
return new CountRequest(indices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a exists request which checks if any of the hits matched against a query exists. Note, the query itself must be set
|
||||
* either using the JSON source of the query, or using a {@link org.elasticsearch.index.query.QueryBuilder} (using {@link org.elasticsearch.index.query.QueryBuilders}).
|
||||
|
|
|
@ -228,10 +228,6 @@ import org.elasticsearch.action.bulk.BulkAction;
|
|||
import org.elasticsearch.action.bulk.BulkRequest;
|
||||
import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
||||
import org.elasticsearch.action.bulk.BulkResponse;
|
||||
import org.elasticsearch.action.count.CountAction;
|
||||
import org.elasticsearch.action.count.CountRequest;
|
||||
import org.elasticsearch.action.count.CountRequestBuilder;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.delete.DeleteAction;
|
||||
import org.elasticsearch.action.delete.DeleteRequest;
|
||||
import org.elasticsearch.action.delete.DeleteRequestBuilder;
|
||||
|
@ -605,33 +601,6 @@ public abstract class AbstractClient extends AbstractComponent implements Client
|
|||
return new MultiSearchRequestBuilder(this, MultiSearchAction.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionFuture<CountResponse> count(final CountRequest request) {
|
||||
AdapterActionFuture<CountResponse, SearchResponse> actionFuture = new AdapterActionFuture<CountResponse, SearchResponse>() {
|
||||
@Override
|
||||
protected CountResponse convert(SearchResponse listenerResponse) {
|
||||
return new CountResponse(listenerResponse);
|
||||
}
|
||||
};
|
||||
execute(SearchAction.INSTANCE, request.toSearchRequest(), actionFuture);
|
||||
return actionFuture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void count(final CountRequest request, final ActionListener<CountResponse> listener) {
|
||||
execute(SearchAction.INSTANCE, request.toSearchRequest(), new DelegatingActionListener<SearchResponse, CountResponse>(listener) {
|
||||
@Override
|
||||
protected CountResponse getDelegatedFromInstigator(SearchResponse response) {
|
||||
return new CountResponse(response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public CountRequestBuilder prepareCount(String... indices) {
|
||||
return new CountRequestBuilder(this, CountAction.INSTANCE).setIndices(indices);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionFuture<ExistsResponse> exists(final ExistsRequest request) {
|
||||
return execute(ExistsAction.INSTANCE, request);
|
||||
|
|
|
@ -19,9 +19,8 @@
|
|||
|
||||
package org.elasticsearch.rest.action.cat;
|
||||
|
||||
import org.elasticsearch.action.count.CountRequest;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.support.QuerySourceBuilder;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.Table;
|
||||
|
@ -38,6 +37,7 @@ import org.elasticsearch.rest.RestResponse;
|
|||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestResponseListener;
|
||||
import org.elasticsearch.rest.action.support.RestTable;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
|
||||
|
@ -66,23 +66,23 @@ public class RestCountAction extends AbstractCatAction {
|
|||
@Override
|
||||
public void doRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
|
||||
CountRequest countRequest = new CountRequest(indices);
|
||||
SearchRequest countRequest = new SearchRequest(indices);
|
||||
String source = request.param("source");
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0);
|
||||
countRequest.source(searchSourceBuilder);
|
||||
if (source != null) {
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry);
|
||||
context.parseFieldMatcher(parseFieldMatcher);
|
||||
countRequest.query(RestActions.getQueryContent(new BytesArray(source), context));
|
||||
searchSourceBuilder.query(RestActions.getQueryContent(new BytesArray(source), context));
|
||||
} else {
|
||||
QueryBuilder<?> queryBuilder = RestActions.urlParamsToQueryBuilder(request);
|
||||
if (queryBuilder != null) {
|
||||
QuerySourceBuilder querySourceBuilder = new QuerySourceBuilder();
|
||||
querySourceBuilder.setQuery(queryBuilder);
|
||||
countRequest.query(queryBuilder);
|
||||
searchSourceBuilder.query(queryBuilder);
|
||||
}
|
||||
}
|
||||
client.count(countRequest, new RestResponseListener<CountResponse>(channel) {
|
||||
client.search(countRequest, new RestResponseListener<SearchResponse>(channel) {
|
||||
@Override
|
||||
public RestResponse buildResponse(CountResponse countResponse) throws Exception {
|
||||
public RestResponse buildResponse(SearchResponse countResponse) throws Exception {
|
||||
return RestTable.buildResponse(buildTable(request, countResponse), channel);
|
||||
}
|
||||
});
|
||||
|
@ -101,13 +101,13 @@ public class RestCountAction extends AbstractCatAction {
|
|||
|
||||
private DateTimeFormatter dateFormat = DateTimeFormat.forPattern("HH:mm:ss");
|
||||
|
||||
private Table buildTable(RestRequest request, CountResponse response) {
|
||||
private Table buildTable(RestRequest request, SearchResponse response) {
|
||||
Table table = getTableWithHeader(request);
|
||||
long time = System.currentTimeMillis();
|
||||
table.startRow();
|
||||
table.addCell(TimeUnit.SECONDS.convert(time, TimeUnit.MILLISECONDS));
|
||||
table.addCell(dateFormat.print(time));
|
||||
table.addCell(response.getCount());
|
||||
table.addCell(response.getHits().totalHits());
|
||||
table.endRow();
|
||||
|
||||
return table;
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
package org.elasticsearch.rest.action.count;
|
||||
|
||||
import org.elasticsearch.action.count.CountRequest;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.common.Strings;
|
||||
|
@ -31,14 +31,10 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.index.query.QueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
|
||||
import org.elasticsearch.rest.BaseRestHandler;
|
||||
import org.elasticsearch.rest.BytesRestResponse;
|
||||
import org.elasticsearch.rest.RestChannel;
|
||||
import org.elasticsearch.rest.RestController;
|
||||
import org.elasticsearch.rest.RestRequest;
|
||||
import org.elasticsearch.rest.RestResponse;
|
||||
import org.elasticsearch.rest.*;
|
||||
import org.elasticsearch.rest.action.support.RestActions;
|
||||
import org.elasticsearch.rest.action.support.RestBuilderListener;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
|
||||
import static org.elasticsearch.rest.RestRequest.Method.GET;
|
||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||
|
@ -66,23 +62,25 @@ public class RestCountAction extends BaseRestHandler {
|
|||
|
||||
@Override
|
||||
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
|
||||
CountRequest countRequest = new CountRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
SearchRequest countRequest = new SearchRequest(Strings.splitStringByCommaToArray(request.param("index")));
|
||||
countRequest.indicesOptions(IndicesOptions.fromRequest(request, countRequest.indicesOptions()));
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder().size(0);
|
||||
countRequest.source(searchSourceBuilder);
|
||||
if (RestActions.hasBodyContent(request)) {
|
||||
BytesReference restContent = RestActions.getRestContent(request);
|
||||
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry);
|
||||
context.parseFieldMatcher(parseFieldMatcher);
|
||||
countRequest.query(RestActions.getQueryContent(restContent, context));
|
||||
searchSourceBuilder.query(RestActions.getQueryContent(restContent, context));
|
||||
} else {
|
||||
QueryBuilder<?> queryBuilder = RestActions.urlParamsToQueryBuilder(request);
|
||||
if (queryBuilder != null) {
|
||||
countRequest.query(queryBuilder);
|
||||
searchSourceBuilder.query(queryBuilder);
|
||||
}
|
||||
}
|
||||
countRequest.routing(request.param("routing"));
|
||||
float minScore = request.paramAsFloat("min_score", -1f);
|
||||
if (minScore != -1f) {
|
||||
countRequest.minScore(minScore);
|
||||
searchSourceBuilder.minScore(minScore);
|
||||
}
|
||||
countRequest.types(Strings.splitStringByCommaToArray(request.param("type")));
|
||||
countRequest.preference(request.param("preference"));
|
||||
|
@ -91,17 +89,18 @@ public class RestCountAction extends BaseRestHandler {
|
|||
if (terminateAfter < 0) {
|
||||
throw new IllegalArgumentException("terminateAfter must be > 0");
|
||||
} else if (terminateAfter > 0) {
|
||||
countRequest.terminateAfter(terminateAfter);
|
||||
searchSourceBuilder.terminateAfter(terminateAfter);
|
||||
}
|
||||
client.count(countRequest, new RestBuilderListener<CountResponse>(channel) {
|
||||
client.search(countRequest, new RestBuilderListener<SearchResponse>(channel) {
|
||||
@Override
|
||||
public RestResponse buildResponse(CountResponse response, XContentBuilder builder) throws Exception {
|
||||
public RestResponse buildResponse(SearchResponse response, XContentBuilder builder) throws Exception {
|
||||
builder.startObject();
|
||||
if (terminateAfter != DEFAULT_TERMINATE_AFTER) {
|
||||
builder.field("terminated_early", response.terminatedEarly());
|
||||
builder.field("terminated_early", response.isTerminatedEarly());
|
||||
}
|
||||
builder.field("count", response.getCount());
|
||||
buildBroadcastShardsHeader(builder, request, response);
|
||||
builder.field("count", response.getHits().totalHits());
|
||||
buildBroadcastShardsHeader(builder, request, response.getTotalShards(), response.getSuccessfulShards(),
|
||||
response.getFailedShards(), response.getShardFailures());
|
||||
|
||||
builder.endObject();
|
||||
return new BytesRestResponse(response.status(), builder);
|
||||
|
|
|
@ -120,8 +120,7 @@ public class RestActions {
|
|||
QueryParseContext queryParseContext = new QueryParseContext(queryRegistry);
|
||||
queryParseContext.reset(parser);
|
||||
queryParseContext.parseFieldMatcher(parseFieldMatcher);
|
||||
SearchSourceBuilder source = SearchSourceBuilder.parseSearchSource(parser, queryParseContext);
|
||||
return source;
|
||||
return SearchSourceBuilder.parseSearchSource(parser, queryParseContext);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,83 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.action.count;
|
||||
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.transport.TransportClient;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
||||
public class CountRequestBuilderTests extends ESTestCase {
|
||||
|
||||
private static Client client;
|
||||
|
||||
@BeforeClass
|
||||
public static void initClient() {
|
||||
//this client will not be hit by any request, but it needs to be a non null proper client
|
||||
//that is why we create it but we don't add any transport address to it
|
||||
Settings settings = Settings.builder()
|
||||
.put("path.home", createTempDir().toString())
|
||||
.build();
|
||||
client = TransportClient.builder().settings(settings).build();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void closeClient() {
|
||||
client.close();
|
||||
client = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptySourceToString() {
|
||||
CountRequestBuilder countRequestBuilder = client.prepareCount();
|
||||
assertThat(countRequestBuilder.toString(), equalTo(new CountRequest().toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryBuilderQueryToString() {
|
||||
CountRequestBuilder countRequestBuilder = client.prepareCount();
|
||||
countRequestBuilder.setQuery(QueryBuilders.matchAllQuery());
|
||||
assertThat(countRequestBuilder.toString(), equalTo(new CountRequest().query(QueryBuilders.matchAllQuery()).toString()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringQueryToString() {
|
||||
CountRequestBuilder countRequestBuilder = client.prepareCount();
|
||||
countRequestBuilder.setQuery(new MatchAllQueryBuilder());
|
||||
assertThat(countRequestBuilder.toString(), containsString("match_all"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatToStringDoesntWipeSource() {
|
||||
CountRequestBuilder countRequestBuilder = client.prepareCount().setQuery(QueryBuilders.termQuery("field", "value"));
|
||||
String preToString = countRequestBuilder.request().toString();
|
||||
assertThat(countRequestBuilder.toString(), equalTo(new CountRequest().query(QueryBuilders.termQuery("field", "value")).toString()));
|
||||
String postToString = countRequestBuilder.request().toString();
|
||||
assertThat(preToString, equalTo(postToString));
|
||||
}
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.action.count;
|
||||
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
|
||||
public class CountRequestTests extends ESTestCase {
|
||||
|
||||
@Test
|
||||
public void testToSearchRequest() {
|
||||
CountRequest countRequest;
|
||||
if (randomBoolean()) {
|
||||
countRequest = new CountRequest(randomStringArray());
|
||||
} else {
|
||||
countRequest = new CountRequest();
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
countRequest.indicesOptions(IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
countRequest.types(randomStringArray());
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
countRequest.routing(randomStringArray());
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
countRequest.preference(randomAsciiOfLengthBetween(1, 10));
|
||||
}
|
||||
final boolean querySet = randomBoolean();
|
||||
if (querySet) {
|
||||
countRequest.query(QueryBuilders.termQuery("field", "value"));
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
countRequest.minScore(randomFloat());
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
countRequest.terminateAfter(randomIntBetween(1, 1000));
|
||||
}
|
||||
|
||||
SearchRequest searchRequest = countRequest.toSearchRequest();
|
||||
assertThat(searchRequest.indices(), equalTo(countRequest.indices()));
|
||||
assertThat(searchRequest.indicesOptions(), equalTo(countRequest.indicesOptions()));
|
||||
assertThat(searchRequest.types(), equalTo(countRequest.types()));
|
||||
assertThat(searchRequest.routing(), equalTo(countRequest.routing()));
|
||||
assertThat(searchRequest.preference(), equalTo(countRequest.preference()));
|
||||
SearchSourceBuilder source = searchRequest.source();
|
||||
assertThat(source.size(), equalTo(0));
|
||||
if (querySet) {
|
||||
assertThat(source.query(), notNullValue());
|
||||
} else {
|
||||
assertNull(source.query());
|
||||
}
|
||||
assertThat(source.minScore(), equalTo(countRequest.minScore()));
|
||||
assertThat(source.terminateAfter(), equalTo(countRequest.terminateAfter()));
|
||||
}
|
||||
|
||||
private static String[] randomStringArray() {
|
||||
int count = randomIntBetween(1, 5);
|
||||
String[] indices = new String[count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
indices[i] = randomAsciiOfLengthBetween(1, 10);
|
||||
}
|
||||
return indices;
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.action.count;
|
||||
|
||||
import org.elasticsearch.action.ShardOperationFailedException;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.search.ShardSearchFailure;
|
||||
import org.elasticsearch.search.internal.InternalSearchHits;
|
||||
import org.elasticsearch.search.internal.InternalSearchResponse;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
|
||||
public class CountResponseTests extends ESTestCase {
|
||||
|
||||
@Test
|
||||
public void testFromSearchResponse() {
|
||||
InternalSearchResponse internalSearchResponse = new InternalSearchResponse(new InternalSearchHits(null, randomLong(), randomFloat()), null, null, randomBoolean(), randomBoolean());
|
||||
ShardSearchFailure[] shardSearchFailures = new ShardSearchFailure[randomIntBetween(0, 5)];
|
||||
for (int i = 0; i < shardSearchFailures.length; i++) {
|
||||
shardSearchFailures[i] = new ShardSearchFailure(new IllegalArgumentException());
|
||||
}
|
||||
SearchResponse searchResponse = new SearchResponse(internalSearchResponse, null, randomIntBetween(0, 100), randomIntBetween(0, 100), randomIntBetween(0, 100), shardSearchFailures);
|
||||
|
||||
CountResponse countResponse = new CountResponse(searchResponse);
|
||||
assertThat(countResponse.getTotalShards(), equalTo(searchResponse.getTotalShards()));
|
||||
assertThat(countResponse.getSuccessfulShards(), equalTo(searchResponse.getSuccessfulShards()));
|
||||
assertThat(countResponse.getFailedShards(), equalTo(searchResponse.getFailedShards()));
|
||||
assertThat(countResponse.getShardFailures(), equalTo((ShardOperationFailedException[])searchResponse.getShardFailures()));
|
||||
assertThat(countResponse.getCount(), equalTo(searchResponse.getHits().totalHits()));
|
||||
assertThat(countResponse.terminatedEarly(), equalTo(searchResponse.isTerminatedEarly()));
|
||||
}
|
||||
}
|
|
@ -280,32 +280,32 @@ public class IndexAliasesIT extends ESIntegTestCase {
|
|||
logger.info("--> checking filtering alias for two indices");
|
||||
SearchResponse searchResponse = client().prepareSearch("foos").setQuery(QueryBuilders.matchAllQuery()).get();
|
||||
assertHits(searchResponse.getHits(), "1", "5");
|
||||
assertThat(client().prepareCount("foos").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(2L));
|
||||
assertThat(client().prepareSearch("foos").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().totalHits(), equalTo(2L));
|
||||
|
||||
logger.info("--> checking filtering alias for one index");
|
||||
searchResponse = client().prepareSearch("bars").setQuery(QueryBuilders.matchAllQuery()).get();
|
||||
assertHits(searchResponse.getHits(), "2");
|
||||
assertThat(client().prepareCount("bars").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(1L));
|
||||
assertThat(client().prepareSearch("bars").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().totalHits(), equalTo(1L));
|
||||
|
||||
logger.info("--> checking filtering alias for two indices and one complete index");
|
||||
searchResponse = client().prepareSearch("foos", "test1").setQuery(QueryBuilders.matchAllQuery()).get();
|
||||
assertHits(searchResponse.getHits(), "1", "2", "3", "4", "5");
|
||||
assertThat(client().prepareCount("foos", "test1").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(5L));
|
||||
assertThat(client().prepareSearch("foos", "test1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().totalHits(), equalTo(5L));
|
||||
|
||||
logger.info("--> checking filtering alias for two indices and non-filtering alias for one index");
|
||||
searchResponse = client().prepareSearch("foos", "aliasToTest1").setQuery(QueryBuilders.matchAllQuery()).get();
|
||||
assertHits(searchResponse.getHits(), "1", "2", "3", "4", "5");
|
||||
assertThat(client().prepareCount("foos", "aliasToTest1").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(5L));
|
||||
assertThat(client().prepareSearch("foos", "aliasToTest1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().totalHits(), equalTo(5L));
|
||||
|
||||
logger.info("--> checking filtering alias for two indices and non-filtering alias for both indices");
|
||||
searchResponse = client().prepareSearch("foos", "aliasToTests").setQuery(QueryBuilders.matchAllQuery()).get();
|
||||
assertThat(searchResponse.getHits().totalHits(), equalTo(8L));
|
||||
assertThat(client().prepareCount("foos", "aliasToTests").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(8L));
|
||||
assertThat(client().prepareSearch("foos", "aliasToTests").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().totalHits(), equalTo(8L));
|
||||
|
||||
logger.info("--> checking filtering alias for two indices and non-filtering alias for both indices");
|
||||
searchResponse = client().prepareSearch("foos", "aliasToTests").setQuery(QueryBuilders.termQuery("name", "something")).get();
|
||||
assertHits(searchResponse.getHits(), "4", "8");
|
||||
assertThat(client().prepareCount("foos", "aliasToTests").setQuery(QueryBuilders.termQuery("name", "something")).get().getCount(), equalTo(2L));
|
||||
assertThat(client().prepareSearch("foos", "aliasToTests").setSize(0).setQuery(QueryBuilders.termQuery("name", "something")).get().getHits().totalHits(), equalTo(2L));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -350,27 +350,27 @@ public class IndexAliasesIT extends ESIntegTestCase {
|
|||
logger.info("--> checking filtering alias for multiple indices");
|
||||
SearchResponse searchResponse = client().prepareSearch("filter23", "filter13").setQuery(QueryBuilders.matchAllQuery()).get();
|
||||
assertHits(searchResponse.getHits(), "21", "31", "13", "33");
|
||||
assertThat(client().prepareCount("filter23", "filter13").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(4L));
|
||||
assertThat(client().prepareSearch("filter23", "filter13").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().totalHits(), equalTo(4L));
|
||||
|
||||
searchResponse = client().prepareSearch("filter23", "filter1").setQuery(QueryBuilders.matchAllQuery()).get();
|
||||
assertHits(searchResponse.getHits(), "21", "31", "11", "12", "13");
|
||||
assertThat(client().prepareCount("filter23", "filter1").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(5L));
|
||||
assertThat(client().prepareSearch("filter23", "filter1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().totalHits(), equalTo(5L));
|
||||
|
||||
searchResponse = client().prepareSearch("filter13", "filter1").setQuery(QueryBuilders.matchAllQuery()).get();
|
||||
assertHits(searchResponse.getHits(), "11", "12", "13", "33");
|
||||
assertThat(client().prepareCount("filter13", "filter1").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(4L));
|
||||
assertThat(client().prepareSearch("filter13", "filter1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().totalHits(), equalTo(4L));
|
||||
|
||||
searchResponse = client().prepareSearch("filter13", "filter1", "filter23").setQuery(QueryBuilders.matchAllQuery()).get();
|
||||
assertHits(searchResponse.getHits(), "11", "12", "13", "21", "31", "33");
|
||||
assertThat(client().prepareCount("filter13", "filter1", "filter23").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(6L));
|
||||
assertThat(client().prepareSearch("filter13", "filter1", "filter23").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().totalHits(), equalTo(6L));
|
||||
|
||||
searchResponse = client().prepareSearch("filter23", "filter13", "test2").setQuery(QueryBuilders.matchAllQuery()).get();
|
||||
assertHits(searchResponse.getHits(), "21", "22", "23", "31", "13", "33");
|
||||
assertThat(client().prepareCount("filter23", "filter13", "test2").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(6L));
|
||||
assertThat(client().prepareSearch("filter23", "filter13", "test2").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().totalHits(), equalTo(6L));
|
||||
|
||||
searchResponse = client().prepareSearch("filter23", "filter13", "test1", "test2").setQuery(QueryBuilders.matchAllQuery()).get();
|
||||
assertHits(searchResponse.getHits(), "11", "12", "13", "21", "22", "23", "31", "33");
|
||||
assertThat(client().prepareCount("filter23", "filter13", "test1", "test2").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(8L));
|
||||
assertThat(client().prepareSearch("filter23", "filter13", "test1", "test2").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().totalHits(), equalTo(8L));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -408,7 +408,7 @@ public class IndexAliasesIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
logger.info("--> checking counts before delete");
|
||||
assertThat(client().prepareCount("bars").setQuery(QueryBuilders.matchAllQuery()).get().getCount(), equalTo(1L));
|
||||
assertThat(client().prepareSearch("bars").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get().getHits().totalHits(), equalTo(1L));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -103,7 +103,7 @@ public class SuggestSearchBenchMark {
|
|||
System.out.println("Indexing took " + stopWatch.totalTime());
|
||||
|
||||
client.admin().indices().prepareRefresh().execute().actionGet();
|
||||
System.out.println("Count: " + client.prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount());
|
||||
System.out.println("Count: " + client.prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits());
|
||||
} catch (Exception e) {
|
||||
System.out.println("--> Index already exists, ignoring indexing phase, waiting for green");
|
||||
ClusterHealthResponse clusterHealthResponse = client.admin().cluster().prepareHealth().setWaitForGreenStatus().setTimeout("10m").execute().actionGet();
|
||||
|
@ -111,7 +111,7 @@ public class SuggestSearchBenchMark {
|
|||
System.err.println("--> Timed out waiting for cluster health");
|
||||
}
|
||||
client.admin().indices().prepareRefresh().execute().actionGet();
|
||||
System.out.println("Count: " + client.prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount());
|
||||
System.out.println("Count: " + client.prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -160,7 +160,7 @@ public class GlobalOrdinalsBenchmark {
|
|||
.get();
|
||||
|
||||
client.admin().indices().prepareRefresh(INDEX_NAME).execute().actionGet();
|
||||
COUNT = client.prepareCount(INDEX_NAME).setQuery(matchAllQuery()).execute().actionGet().getCount();
|
||||
COUNT = client.prepareSearch(INDEX_NAME).setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits();
|
||||
System.out.println("--> Number of docs in index: " + COUNT);
|
||||
|
||||
List<StatsResult> stats = new ArrayList<>();
|
||||
|
|
|
@ -139,7 +139,7 @@ public class HistogramAggregationSearchBenchmark {
|
|||
System.err.println("--> Timed out waiting for cluster health");
|
||||
}
|
||||
}
|
||||
if (client.prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount() != COUNT) {
|
||||
if (client.prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits() != COUNT) {
|
||||
throw new Error();
|
||||
}
|
||||
System.out.println("--> Number of docs in index: " + COUNT);
|
||||
|
|
|
@ -169,7 +169,7 @@ public class PercentilesAggregationSearchBenchmark {
|
|||
System.out.println("## Precision");
|
||||
for (Distribution d : Distribution.values()) {
|
||||
System.out.println("#### " + d);
|
||||
final long count = client.prepareCount(d.indexName()).setQuery(matchAllQuery()).execute().actionGet().getCount();
|
||||
final long count = client.prepareSearch(d.indexName()).setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits();
|
||||
if (count != NUM_DOCS + 1) {
|
||||
throw new Error("Expected " + NUM_DOCS + " documents, got " + (count - 1));
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ public class QueryFilterAggregationSearchBenchmark {
|
|||
}
|
||||
}
|
||||
client.admin().indices().prepareRefresh().execute().actionGet();
|
||||
if (client.prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount() != COUNT) {
|
||||
if (client.prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits() != COUNT) {
|
||||
throw new Error();
|
||||
}
|
||||
System.out.println("--> Number of docs in index: " + COUNT);
|
||||
|
|
|
@ -204,7 +204,7 @@ public class SubAggregationSearchCollectModeBenchmark {
|
|||
}
|
||||
}
|
||||
client.admin().indices().prepareRefresh().execute().actionGet();
|
||||
COUNT = client.prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount();
|
||||
COUNT = client.prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits();
|
||||
System.out.println("--> Number of docs in index: " + COUNT);
|
||||
|
||||
List<StatsResult> stats = new ArrayList<>();
|
||||
|
|
|
@ -151,7 +151,7 @@ public class TermsAggregationSearchAndIndexingBenchmark {
|
|||
.setSource(generateMapping("lazy", "lazy"))
|
||||
.get();
|
||||
client.admin().indices().prepareRefresh().execute().actionGet();
|
||||
System.out.println("--> Number of docs in index: " + client.prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount());
|
||||
System.out.println("--> Number of docs in index: " + client.prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits());
|
||||
|
||||
|
||||
String[] nodeIds = new String[nodes.length];
|
||||
|
|
|
@ -230,7 +230,7 @@ public class TermsAggregationSearchBenchmark {
|
|||
}
|
||||
}
|
||||
client.admin().indices().prepareRefresh().execute().actionGet();
|
||||
COUNT = client.prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount();
|
||||
COUNT = client.prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits();
|
||||
System.out.println("--> Number of docs in index: " + COUNT);
|
||||
|
||||
|
||||
|
|
|
@ -152,7 +152,7 @@ public class TimeDataHistogramAggregationBenchmark {
|
|||
}
|
||||
}
|
||||
client.admin().indices().prepareRefresh().execute().actionGet();
|
||||
COUNT = client.prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount();
|
||||
COUNT = client.prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits();
|
||||
System.out.println("--> Number of docs in index: " + COUNT);
|
||||
|
||||
// load with the reverse options to make sure jit doesn't optimize one away
|
||||
|
|
|
@ -87,7 +87,7 @@ public class ChildSearchAndIndexingBenchmark {
|
|||
}
|
||||
}
|
||||
client.admin().indices().prepareRefresh().execute().actionGet();
|
||||
System.out.println("--> Number of docs in index: " + client.prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount());
|
||||
System.out.println("--> Number of docs in index: " + client.prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits());
|
||||
|
||||
SearchThread searchThread = new SearchThread(client);
|
||||
new Thread(searchThread).start();
|
||||
|
|
|
@ -107,7 +107,7 @@ public class ChildSearchBenchmark {
|
|||
}
|
||||
}
|
||||
client.admin().indices().prepareRefresh().execute().actionGet();
|
||||
System.out.println("--> Number of docs in index: " + client.prepareCount(indexName).setQuery(matchAllQuery()).execute().actionGet().getCount());
|
||||
System.out.println("--> Number of docs in index: " + client.prepareSearch(indexName).setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits());
|
||||
|
||||
System.out.println("--> Running just child query");
|
||||
// run just the child query, warm up first
|
||||
|
|
|
@ -123,7 +123,7 @@ public class ChildSearchShortCircuitBenchmark {
|
|||
}
|
||||
}
|
||||
client.admin().indices().prepareRefresh().execute().actionGet();
|
||||
System.out.println("--> Number of docs in index: " + client.prepareCount(indexName).setQuery(matchAllQuery()).execute().actionGet().getCount());
|
||||
System.out.println("--> Number of docs in index: " + client.prepareSearch(indexName).setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits());
|
||||
|
||||
System.out.println("--> Running just child query");
|
||||
// run just the child query, warm up first
|
||||
|
|
|
@ -54,7 +54,7 @@ public class GeoDistanceSearchBenchmark {
|
|||
final long NUM_RUNS = 100;
|
||||
|
||||
if (client.admin().indices().prepareExists("test").execute().actionGet().isExists()) {
|
||||
System.out.println("Found an index, count: " + client.prepareCount("test").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount());
|
||||
System.out.println("Found an index, count: " + client.prepareSearch("test").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits());
|
||||
} else {
|
||||
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type1")
|
||||
.startObject("properties").startObject("location").field("type", "geo_point").field("lat_lon", true).endObject().endObject()
|
||||
|
|
|
@ -137,7 +137,7 @@ public class NestedSearchBenchMark {
|
|||
}
|
||||
}
|
||||
client.admin().indices().prepareRefresh().execute().actionGet();
|
||||
System.out.println("--> Number of docs in index: " + client.prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount());
|
||||
System.out.println("--> Number of docs in index: " + client.prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits());
|
||||
|
||||
NodesStatsResponse statsResponse = client.admin().cluster().prepareNodesStats()
|
||||
.setJvm(true).execute().actionGet();
|
||||
|
|
|
@ -93,7 +93,7 @@ public class ScrollSearchBenchmark {
|
|||
}
|
||||
|
||||
client.admin().indices().prepareRefresh(indexName).get();
|
||||
System.out.printf(Locale.ENGLISH, "--> Number of docs in index: %d\n", client.prepareCount().get().getCount());
|
||||
System.out.printf(Locale.ENGLISH, "--> Number of docs in index: %d\n", client.prepareSearch().setSize(0).get().getHits().totalHits());
|
||||
|
||||
Long counter = numDocs;
|
||||
SearchResponse searchResponse = client.prepareSearch(indexName)
|
||||
|
|
|
@ -19,9 +19,7 @@
|
|||
|
||||
package org.elasticsearch.broadcast;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
|
@ -29,7 +27,6 @@ import org.junit.Test;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.client.Requests.countRequest;
|
||||
import static org.elasticsearch.client.Requests.indexRequest;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
|
@ -60,10 +57,10 @@ public class BroadcastActionsIT extends ESIntegTestCase {
|
|||
// check count
|
||||
for (int i = 0; i < 5; i++) {
|
||||
// test successful
|
||||
CountResponse countResponse = client().prepareCount("test")
|
||||
SearchResponse countResponse = client().prepareSearch("test").setSize(0)
|
||||
.setQuery(termQuery("_type", "type1"))
|
||||
.get();
|
||||
assertThat(countResponse.getCount(), equalTo(2l));
|
||||
assertThat(countResponse.getHits().totalHits(), equalTo(2l));
|
||||
assertThat(countResponse.getTotalShards(), equalTo(numShards.numPrimaries));
|
||||
assertThat(countResponse.getSuccessfulShards(), equalTo(numShards.numPrimaries));
|
||||
assertThat(countResponse.getFailedShards(), equalTo(0));
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.elasticsearch.action.admin.indices.alias.Alias;
|
|||
import org.elasticsearch.action.admin.indices.analyze.AnalyzeResponse;
|
||||
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
|
||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.delete.DeleteResponse;
|
||||
import org.elasticsearch.action.explain.ExplainResponse;
|
||||
import org.elasticsearch.action.get.*;
|
||||
|
@ -162,7 +162,7 @@ public class BasicBackwardsCompatibilityIT extends ESBackcompatTestCase {
|
|||
docs[i] = client().prepareIndex("test", "type1", id).setSource("field1", English.intToEnglish(i));
|
||||
}
|
||||
indexRandom(true, docs);
|
||||
CountResponse countResponse = client().prepareCount().get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
|
||||
if (randomBoolean()) {
|
||||
|
@ -223,11 +223,11 @@ public class BasicBackwardsCompatibilityIT extends ESBackcompatTestCase {
|
|||
backwardsCluster().startNewNode();
|
||||
}
|
||||
assertAllShardsOnNodes("test", backwardsCluster().newNodePattern());
|
||||
CountResponse countResponse = client().prepareCount().get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
final int numIters = randomIntBetween(10, 20);
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
countResponse = client().prepareCount().get();
|
||||
countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
assertSimpleSort("num_double", "num_int");
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ public class BasicBackwardsCompatibilityIT extends ESBackcompatTestCase {
|
|||
assertAllShardsOnNodes("test", backwardsCluster().backwardsNodePattern());
|
||||
disableAllocation("test");
|
||||
backwardsCluster().allowOnAllNodes("test");
|
||||
CountResponse countResponse = client().prepareCount().get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
backwardsCluster().upgradeOneNode();
|
||||
ensureYellow();
|
||||
|
@ -297,7 +297,7 @@ public class BasicBackwardsCompatibilityIT extends ESBackcompatTestCase {
|
|||
ensureYellow();
|
||||
final int numIters = randomIntBetween(1, 20);
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
assertHitCount(client().prepareCount().get(), numDocs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).get(), numDocs);
|
||||
assertSimpleSort("num_double", "num_int");
|
||||
}
|
||||
assertVersionCreated(compatibilityVersion(), "test");
|
||||
|
@ -332,12 +332,12 @@ public class BasicBackwardsCompatibilityIT extends ESBackcompatTestCase {
|
|||
boolean upgraded;
|
||||
do {
|
||||
logClusterState();
|
||||
CountResponse countResponse = client().prepareCount().get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
assertSimpleSort("num_double", "num_int");
|
||||
upgraded = backwardsCluster().upgradeOneNode();
|
||||
ensureYellow();
|
||||
countResponse = client().prepareCount().get();
|
||||
countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
for (int i = 0; i < numDocs; i++) {
|
||||
docs[i] = client().prepareIndex(indexForDoc[i], "type1", String.valueOf(i)).setSource("field1", English.intToEnglish(i), "num_int", randomInt(), "num_double", randomDouble());
|
||||
|
@ -346,7 +346,7 @@ public class BasicBackwardsCompatibilityIT extends ESBackcompatTestCase {
|
|||
} while (upgraded);
|
||||
enableAllocation(indices);
|
||||
ensureYellow();
|
||||
CountResponse countResponse = client().prepareCount().get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
assertSimpleSort("num_double", "num_int");
|
||||
|
||||
|
@ -414,47 +414,47 @@ public class BasicBackwardsCompatibilityIT extends ESBackcompatTestCase {
|
|||
client().prepareIndex(indexName, "type1", "3").setSource(jsonBuilder().startObject().startObject("obj2").field("obj2_val", "1").endObject().field("y1", "y_1").field("field2", "value2_3").endObject()),
|
||||
client().prepareIndex(indexName, "type1", "4").setSource(jsonBuilder().startObject().startObject("obj2").field("obj2_val", "1").endObject().field("y2", "y_2").field("field3", "value3_4").endObject()));
|
||||
|
||||
CountResponse countResponse = client().prepareCount().setQuery(existsQuery("field1")).get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).setQuery(existsQuery("field1")).get();
|
||||
assertHitCount(countResponse, 2l);
|
||||
|
||||
countResponse = client().prepareCount().setQuery(constantScoreQuery(existsQuery("field1"))).get();
|
||||
countResponse = client().prepareSearch().setSize(0).setQuery(constantScoreQuery(existsQuery("field1"))).get();
|
||||
assertHitCount(countResponse, 2l);
|
||||
|
||||
countResponse = client().prepareCount().setQuery(queryStringQuery("_exists_:field1")).get();
|
||||
countResponse = client().prepareSearch().setSize(0).setQuery(queryStringQuery("_exists_:field1")).get();
|
||||
assertHitCount(countResponse, 2l);
|
||||
|
||||
countResponse = client().prepareCount().setQuery(existsQuery("field2")).get();
|
||||
countResponse = client().prepareSearch().setSize(0).setQuery(existsQuery("field2")).get();
|
||||
assertHitCount(countResponse, 2l);
|
||||
|
||||
countResponse = client().prepareCount().setQuery(existsQuery("field3")).get();
|
||||
countResponse = client().prepareSearch().setSize(0).setQuery(existsQuery("field3")).get();
|
||||
assertHitCount(countResponse, 1l);
|
||||
|
||||
// wildcard check
|
||||
countResponse = client().prepareCount().setQuery(existsQuery("x*")).get();
|
||||
countResponse = client().prepareSearch().setSize(0).setQuery(existsQuery("x*")).get();
|
||||
assertHitCount(countResponse, 2l);
|
||||
|
||||
// object check
|
||||
countResponse = client().prepareCount().setQuery(existsQuery("obj1")).get();
|
||||
countResponse = client().prepareSearch().setSize(0).setQuery(existsQuery("obj1")).get();
|
||||
assertHitCount(countResponse, 2l);
|
||||
|
||||
countResponse = client().prepareCount().setQuery(missingQuery("field1")).get();
|
||||
countResponse = client().prepareSearch().setSize(0).setQuery(missingQuery("field1")).get();
|
||||
assertHitCount(countResponse, 2l);
|
||||
|
||||
countResponse = client().prepareCount().setQuery(missingQuery("field1")).get();
|
||||
countResponse = client().prepareSearch().setSize(0).setQuery(missingQuery("field1")).get();
|
||||
assertHitCount(countResponse, 2l);
|
||||
|
||||
countResponse = client().prepareCount().setQuery(constantScoreQuery(missingQuery("field1"))).get();
|
||||
countResponse = client().prepareSearch().setSize(0).setQuery(constantScoreQuery(missingQuery("field1"))).get();
|
||||
assertHitCount(countResponse, 2l);
|
||||
|
||||
countResponse = client().prepareCount().setQuery(queryStringQuery("_missing_:field1")).get();
|
||||
countResponse = client().prepareSearch().setSize(0).setQuery(queryStringQuery("_missing_:field1")).get();
|
||||
assertHitCount(countResponse, 2l);
|
||||
|
||||
// wildcard check
|
||||
countResponse = client().prepareCount().setQuery(missingQuery("x*")).get();
|
||||
countResponse = client().prepareSearch().setSize(0).setQuery(missingQuery("x*")).get();
|
||||
assertHitCount(countResponse, 2l);
|
||||
|
||||
// object check
|
||||
countResponse = client().prepareCount().setQuery(missingQuery("obj1")).get();
|
||||
countResponse = client().prepareSearch().setSize(0).setQuery(missingQuery("obj1")).get();
|
||||
assertHitCount(countResponse, 2l);
|
||||
if (!backwardsCluster().upgradeOneNode()) {
|
||||
break;
|
||||
|
|
|
@ -109,7 +109,7 @@ public class MinimumMasterNodesIT extends ESIntegTestCase {
|
|||
|
||||
logger.info("--> verify we the data back");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertThat(client().prepareCount().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(100l));
|
||||
assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(100l));
|
||||
}
|
||||
|
||||
internalCluster().stopCurrentMasterNode();
|
||||
|
@ -140,7 +140,7 @@ public class MinimumMasterNodesIT extends ESIntegTestCase {
|
|||
|
||||
logger.info("--> verify we the data back after cluster reform");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(), 100);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(), 100);
|
||||
}
|
||||
|
||||
internalCluster().stopRandomNonMasterNode();
|
||||
|
@ -173,7 +173,7 @@ public class MinimumMasterNodesIT extends ESIntegTestCase {
|
|||
|
||||
logger.info("--> verify we the data back");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(), 100);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(), 100);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ public class MinimumMasterNodesIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
logger.info("--> verify we the data back");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(), 100);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(), 100);
|
||||
}
|
||||
|
||||
internalCluster().stopRandomNonMasterNode();
|
||||
|
@ -250,7 +250,7 @@ public class MinimumMasterNodesIT extends ESIntegTestCase {
|
|||
|
||||
logger.info("--> verify we the data back");
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(), 100);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(), 100);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ package org.elasticsearch.cluster;
|
|||
import org.elasticsearch.action.ActionRequestBuilder;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
||||
import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.percolate.PercolateSourceBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
|
@ -127,11 +126,11 @@ public class NoMasterNodeIT extends ESIntegTestCase {
|
|||
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
|
||||
);
|
||||
|
||||
assertThrows(client().prepareCount("test"),
|
||||
assertThrows(client().prepareSearch("test").setSize(0),
|
||||
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
|
||||
);
|
||||
|
||||
assertThrows(client().prepareCount("no_index"),
|
||||
assertThrows(client().prepareSearch("no_index").setSize(0),
|
||||
ClusterBlockException.class, RestStatus.SERVICE_UNAVAILABLE
|
||||
);
|
||||
|
||||
|
@ -248,13 +247,13 @@ public class NoMasterNodeIT extends ESIntegTestCase {
|
|||
GetResponse getResponse = client().prepareGet("test1", "type1", "1").get();
|
||||
assertExists(getResponse);
|
||||
|
||||
CountResponse countResponse = client().prepareCount("test1").get();
|
||||
SearchResponse countResponse = client().prepareSearch("test1").setSize(0).get();
|
||||
assertHitCount(countResponse, 1l);
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("test1").get();
|
||||
assertHitCount(searchResponse, 1l);
|
||||
|
||||
countResponse = client().prepareCount("test2").get();
|
||||
countResponse = client().prepareSearch("test2").setSize(0).get();
|
||||
assertThat(countResponse.getTotalShards(), equalTo(2));
|
||||
assertThat(countResponse.getSuccessfulShards(), equalTo(1));
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ public class FilteringAllocationIT extends ESIntegTestCase {
|
|||
client().prepareIndex("test", "type", Integer.toString(i)).setSource("field", "value" + i).execute().actionGet();
|
||||
}
|
||||
client().admin().indices().prepareRefresh().execute().actionGet();
|
||||
assertThat(client().prepareCount().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(100l));
|
||||
assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(100l));
|
||||
|
||||
logger.info("--> decommission the second node");
|
||||
client().admin().cluster().prepareUpdateSettings()
|
||||
|
@ -79,7 +79,7 @@ public class FilteringAllocationIT extends ESIntegTestCase {
|
|||
}
|
||||
|
||||
client().admin().indices().prepareRefresh().execute().actionGet();
|
||||
assertThat(client().prepareCount().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(100l));
|
||||
assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(100l));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -102,7 +102,7 @@ public class FilteringAllocationIT extends ESIntegTestCase {
|
|||
client().prepareIndex("test", "type", Integer.toString(i)).setSource("field", "value" + i).execute().actionGet();
|
||||
}
|
||||
client().admin().indices().prepareRefresh().execute().actionGet();
|
||||
assertThat(client().prepareCount().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(100l));
|
||||
assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(100l));
|
||||
ClusterState clusterState = client().admin().cluster().prepareState().execute().actionGet().getState();
|
||||
IndexRoutingTable indexRoutingTable = clusterState.routingTable().index("test");
|
||||
int numShardsOnNode1 = 0;
|
||||
|
|
|
@ -1,217 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.elasticsearch.count.simple;
|
||||
|
||||
import org.apache.lucene.util.Constants;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static com.carrotsearch.randomizedtesting.RandomizedTest.systemPropertyAsBoolean;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_REPLICAS;
|
||||
import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.rangeQuery;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
public class SimpleCountIT extends ESIntegTestCase {
|
||||
|
||||
@Test
|
||||
public void testCountRandomPreference() throws InterruptedException, ExecutionException {
|
||||
createIndex("test");
|
||||
indexRandom(true, client().prepareIndex("test", "type", "1").setSource("field", "value"),
|
||||
client().prepareIndex("test", "type", "2").setSource("field", "value"),
|
||||
client().prepareIndex("test", "type", "3").setSource("field", "value"),
|
||||
client().prepareIndex("test", "type", "4").setSource("field", "value"),
|
||||
client().prepareIndex("test", "type", "5").setSource("field", "value"),
|
||||
client().prepareIndex("test", "type", "6").setSource("field", "value"));
|
||||
|
||||
int iters = scaledRandomIntBetween(10, 100);
|
||||
for (int i = 0; i < iters; i++) {
|
||||
|
||||
String randomPreference = randomUnicodeOfLengthBetween(0, 4);
|
||||
// randomPreference should not start with '_' (reserved for known preference types (e.g. _shards, _primary)
|
||||
while (randomPreference.startsWith("_")) {
|
||||
randomPreference = randomUnicodeOfLengthBetween(0, 4);
|
||||
}
|
||||
// id is not indexed, but lets see that we automatically convert to
|
||||
CountResponse countResponse = client().prepareCount().setQuery(QueryBuilders.matchAllQuery()).setPreference(randomPreference).get();
|
||||
assertHitCount(countResponse, 6l);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleIpTests() throws Exception {
|
||||
createIndex("test");
|
||||
|
||||
client().admin().indices().preparePutMapping("test").setType("type1")
|
||||
.setSource(XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
|
||||
.startObject("from").field("type", "ip").endObject()
|
||||
.startObject("to").field("type", "ip").endObject()
|
||||
.endObject().endObject().endObject())
|
||||
.execute().actionGet();
|
||||
|
||||
client().prepareIndex("test", "type1", "1").setSource("from", "192.168.0.5", "to", "192.168.0.10").setRefresh(true).execute().actionGet();
|
||||
|
||||
CountResponse countResponse = client().prepareCount()
|
||||
.setQuery(boolQuery().must(rangeQuery("from").lt("192.168.0.7")).must(rangeQuery("to").gt("192.168.0.7")))
|
||||
.execute().actionGet();
|
||||
|
||||
assertHitCount(countResponse, 1l);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleIdTests() {
|
||||
createIndex("test");
|
||||
|
||||
client().prepareIndex("test", "type", "XXX1").setSource("field", "value").setRefresh(true).execute().actionGet();
|
||||
// id is not indexed, but lets see that we automatically convert to
|
||||
CountResponse countResponse = client().prepareCount().setQuery(QueryBuilders.termQuery("_id", "XXX1")).execute().actionGet();
|
||||
assertHitCount(countResponse, 1l);
|
||||
|
||||
countResponse = client().prepareCount().setQuery(QueryBuilders.queryStringQuery("_id:XXX1")).execute().actionGet();
|
||||
assertHitCount(countResponse, 1l);
|
||||
|
||||
// id is not index, but we can automatically support prefix as well
|
||||
countResponse = client().prepareCount().setQuery(QueryBuilders.prefixQuery("_id", "XXX")).execute().actionGet();
|
||||
assertHitCount(countResponse, 1l);
|
||||
|
||||
countResponse = client().prepareCount().setQuery(QueryBuilders.queryStringQuery("_id:XXX*").lowercaseExpandedTerms(false)).execute().actionGet();
|
||||
assertHitCount(countResponse, 1l);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleCountEarlyTerminationTests() throws Exception {
|
||||
// set up one shard only to test early termination
|
||||
prepareCreate("test").setSettings(
|
||||
SETTING_NUMBER_OF_SHARDS, 1,
|
||||
SETTING_NUMBER_OF_REPLICAS, 0).get();
|
||||
ensureGreen();
|
||||
int max = randomIntBetween(3, 29);
|
||||
List<IndexRequestBuilder> docbuilders = new ArrayList<>(max);
|
||||
|
||||
for (int i = 1; i <= max; i++) {
|
||||
String id = String.valueOf(i);
|
||||
docbuilders.add(client().prepareIndex("test", "type1", id).setSource("field", i));
|
||||
}
|
||||
|
||||
indexRandom(true, docbuilders);
|
||||
ensureGreen();
|
||||
refresh();
|
||||
|
||||
// sanity check
|
||||
CountResponse countResponse = client().prepareCount("test").setQuery(QueryBuilders.rangeQuery("field").gte(1).lte(max)).execute().actionGet();
|
||||
assertHitCount(countResponse, max);
|
||||
|
||||
// threshold <= actual count
|
||||
for (int i = 1; i <= max; i++) {
|
||||
countResponse = client().prepareCount("test").setQuery(QueryBuilders.rangeQuery("field").gte(1).lte(max)).setTerminateAfter(i).execute().actionGet();
|
||||
assertHitCount(countResponse, i);
|
||||
assertTrue(countResponse.terminatedEarly());
|
||||
}
|
||||
|
||||
// threshold > actual count
|
||||
countResponse = client().prepareCount("test").setQuery(QueryBuilders.rangeQuery("field").gte(1).lte(max)).setTerminateAfter(max + randomIntBetween(1, max)).execute().actionGet();
|
||||
assertHitCount(countResponse, max);
|
||||
assertFalse(countResponse.terminatedEarly());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void localDependentDateTests() throws Exception {
|
||||
assumeFalse("Locals are buggy on JDK9EA", Constants.JRE_IS_MINIMUM_JAVA9 && systemPropertyAsBoolean("tests.security.manager", false));
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1",
|
||||
jsonBuilder().startObject()
|
||||
.startObject("type1")
|
||||
.startObject("properties")
|
||||
.startObject("date_field")
|
||||
.field("type", "date")
|
||||
.field("format", "E, d MMM yyyy HH:mm:ss Z")
|
||||
.field("locale", "de")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()));
|
||||
ensureGreen();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
client().prepareIndex("test", "type1", "" + i).setSource("date_field", "Mi, 06 Dez 2000 02:55:00 -0800").execute().actionGet();
|
||||
client().prepareIndex("test", "type1", "" + (10 + i)).setSource("date_field", "Do, 07 Dez 2000 02:55:00 -0800").execute().actionGet();
|
||||
}
|
||||
|
||||
refresh();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
CountResponse countResponse = client().prepareCount("test")
|
||||
.setQuery(QueryBuilders.rangeQuery("date_field").gte("Di, 05 Dez 2000 02:55:00 -0800").lte("Do, 07 Dez 2000 00:00:00 -0800"))
|
||||
.execute().actionGet();
|
||||
assertHitCount(countResponse, 10l);
|
||||
|
||||
countResponse = client().prepareCount("test")
|
||||
.setQuery(QueryBuilders.rangeQuery("date_field").gte("Di, 05 Dez 2000 02:55:00 -0800").lte("Fr, 08 Dez 2000 00:00:00 -0800"))
|
||||
.execute().actionGet();
|
||||
assertHitCount(countResponse, 20l);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testThatNonEpochDatesCanBeSearched() throws Exception {
|
||||
assertAcked(prepareCreate("test")
|
||||
.addMapping("type1",
|
||||
jsonBuilder().startObject().startObject("type1")
|
||||
.startObject("properties").startObject("date_field").field("type", "date").field("format", "yyyyMMddHH").endObject().endObject()
|
||||
.endObject().endObject()));
|
||||
ensureGreen("test");
|
||||
|
||||
XContentBuilder document = jsonBuilder()
|
||||
.startObject()
|
||||
.field("date_field", "2015060210")
|
||||
.endObject();
|
||||
assertThat(client().prepareIndex("test", "type1").setSource(document).get().isCreated(), is(true));
|
||||
|
||||
document = jsonBuilder()
|
||||
.startObject()
|
||||
.field("date_field", "2014060210")
|
||||
.endObject();
|
||||
assertThat(client().prepareIndex("test", "type1").setSource(document).get().isCreated(), is(true));
|
||||
|
||||
refresh();
|
||||
|
||||
assertHitCount(client().prepareCount("test").get(), 2);
|
||||
|
||||
CountResponse countResponse = client().prepareCount("test").setQuery(QueryBuilders.rangeQuery("date_field").from("2015010100").to("2015123123")).get();
|
||||
assertHitCount(countResponse, 1);
|
||||
|
||||
countResponse = client().prepareCount("test").setQuery(QueryBuilders.rangeQuery("date_field").from(2015010100).to(2015123123)).get();
|
||||
assertHitCount(countResponse, 1);
|
||||
|
||||
countResponse = client().prepareCount("test").setQuery(QueryBuilders.rangeQuery("date_field").from(2015010100).to(2015123123).timeZone("UTC")).get();
|
||||
assertHitCount(countResponse, 1);
|
||||
}
|
||||
}
|
|
@ -969,7 +969,7 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase {
|
|||
// wait for relocation to finish
|
||||
endRelocationLatch.await();
|
||||
// now search for the documents and see if we get a reply
|
||||
assertThat(client().prepareCount().get().getCount(), equalTo(100l));
|
||||
assertThat(client().prepareSearch().setSize(0).get().getHits().totalHits(), equalTo(100l));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -25,15 +25,12 @@ import org.elasticsearch.action.admin.indices.flush.FlushResponse;
|
|||
import org.elasticsearch.action.admin.indices.optimize.OptimizeResponse;
|
||||
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
|
||||
import org.elasticsearch.action.bulk.BulkResponse;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.delete.DeleteResponse;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.search.MultiMatchQuery;
|
||||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -159,16 +156,16 @@ public class DocumentActionsIT extends ESIntegTestCase {
|
|||
// check count
|
||||
for (int i = 0; i < 5; i++) {
|
||||
// test successful
|
||||
CountResponse countResponse = client().prepareCount("test").setQuery(termQuery("_type", "type1")).execute().actionGet();
|
||||
SearchResponse countResponse = client().prepareSearch("test").setSize(0).setQuery(termQuery("_type", "type1")).execute().actionGet();
|
||||
assertNoFailures(countResponse);
|
||||
assertThat(countResponse.getCount(), equalTo(2l));
|
||||
assertThat(countResponse.getHits().totalHits(), equalTo(2l));
|
||||
assertThat(countResponse.getSuccessfulShards(), equalTo(numShards.numPrimaries));
|
||||
assertThat(countResponse.getFailedShards(), equalTo(0));
|
||||
|
||||
// count with no query is a match all one
|
||||
countResponse = client().prepareCount("test").execute().actionGet();
|
||||
countResponse = client().prepareSearch("test").setSize(0).execute().actionGet();
|
||||
assertThat("Failures " + countResponse.getShardFailures(), countResponse.getShardFailures() == null ? 0 : countResponse.getShardFailures().length, equalTo(0));
|
||||
assertThat(countResponse.getCount(), equalTo(2l));
|
||||
assertThat(countResponse.getHits().totalHits(), equalTo(2l));
|
||||
assertThat(countResponse.getSuccessfulShards(), equalTo(numShards.numPrimaries));
|
||||
assertThat(countResponse.getFailedShards(), equalTo(0));
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ public class QuorumGatewayIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).get(), 2l);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get(), 2l);
|
||||
}
|
||||
|
||||
final String nodeToRemove = nodes[between(0,2)];
|
||||
|
@ -111,7 +111,7 @@ public class QuorumGatewayIT extends ESIntegTestCase {
|
|||
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.YELLOW));
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).get(), 2l);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get(), 2l);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -136,7 +136,7 @@ public class QuorumGatewayIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).get(), 2l);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get(), 2l);
|
||||
}
|
||||
logger.info("--> restart all nodes");
|
||||
internalCluster().fullRestart(new RestartCallback() {
|
||||
|
@ -158,7 +158,7 @@ public class QuorumGatewayIT extends ESIntegTestCase {
|
|||
activeClient.prepareIndex("test", "type1", "3").setSource(jsonBuilder().startObject().field("field", "value3").endObject()).get();
|
||||
assertNoFailures(activeClient.admin().indices().prepareRefresh().get());
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(activeClient.prepareCount().setQuery(matchAllQuery()).get(), 3l);
|
||||
assertHitCount(activeClient.prepareSearch().setSize(0).setQuery(matchAllQuery()).get(), 3l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ public class QuorumGatewayIT extends ESIntegTestCase {
|
|||
ensureGreen();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).get(), 3l);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get(), 3l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
package org.elasticsearch.gateway;
|
||||
|
||||
import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -83,7 +83,7 @@ public class RecoveryBackwardsCompatibilityIT extends ESBackcompatTestCase {
|
|||
|
||||
logger.info("--> upgrade cluster");
|
||||
logClusterState();
|
||||
CountResponse countResponse = client().prepareCount().get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
|
||||
client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.settingsBuilder().put(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE, "none")).execute().actionGet();
|
||||
|
@ -91,7 +91,7 @@ public class RecoveryBackwardsCompatibilityIT extends ESBackcompatTestCase {
|
|||
client().admin().cluster().prepareUpdateSettings().setTransientSettings(Settings.settingsBuilder().put(EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE, "all")).execute().actionGet();
|
||||
ensureGreen();
|
||||
|
||||
countResponse = client().prepareCount().get();
|
||||
countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
|
||||
RecoveryResponse recoveryResponse = client().admin().indices().prepareRecoveries("test").setDetailed(true).get();
|
||||
|
|
|
@ -78,7 +78,7 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
.startArray("appAccountIds").value(14).endArray().endObject()).execute().actionGet();
|
||||
|
||||
refresh();
|
||||
assertHitCount(client().prepareCount().setQuery(termQuery("appAccountIds", 179)).execute().actionGet(), 2);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(termQuery("appAccountIds", 179)).execute().actionGet(), 2);
|
||||
ensureYellow("test"); // wait for primary allocations here otherwise if we have a lot of shards we might have a
|
||||
// shard that is still in post recovery when we restart and the ensureYellow() below will timeout
|
||||
internalCluster().fullRestart();
|
||||
|
@ -87,7 +87,7 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
ensureYellow();
|
||||
|
||||
client().admin().indices().prepareRefresh().execute().actionGet();
|
||||
assertHitCount(client().prepareCount().setQuery(termQuery("appAccountIds", 179)).execute().actionGet(), 2);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(termQuery("appAccountIds", 179)).execute().actionGet(), 2);
|
||||
|
||||
internalCluster().fullRestart();
|
||||
|
||||
|
@ -95,7 +95,7 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
ensureYellow();
|
||||
|
||||
client().admin().indices().prepareRefresh().execute().actionGet();
|
||||
assertHitCount(client().prepareCount().setQuery(termQuery("appAccountIds", 179)).execute().actionGet(), 2);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(termQuery("appAccountIds", 179)).execute().actionGet(), 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -148,10 +148,10 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
for (int i = 0; i <= randomInt(10); i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).get(), value1Docs + value2Docs);
|
||||
assertHitCount(client().prepareCount().setQuery(termQuery("field", "value1")).get(), value1Docs);
|
||||
assertHitCount(client().prepareCount().setQuery(termQuery("field", "value2")).get(), value2Docs);
|
||||
assertHitCount(client().prepareCount().setQuery(termQuery("num", 179)).get(), value1Docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get(), value1Docs + value2Docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(termQuery("field", "value1")).get(), value1Docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(termQuery("field", "value2")).get(), value2Docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(termQuery("num", 179)).get(), value1Docs);
|
||||
}
|
||||
if (!indexToAllShards) {
|
||||
// we have to verify primaries are started for them to be restored
|
||||
|
@ -164,10 +164,10 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
ensureYellow();
|
||||
|
||||
for (int i = 0; i <= randomInt(10); i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).get(), value1Docs + value2Docs);
|
||||
assertHitCount(client().prepareCount().setQuery(termQuery("field", "value1")).get(), value1Docs);
|
||||
assertHitCount(client().prepareCount().setQuery(termQuery("field", "value2")).get(), value2Docs);
|
||||
assertHitCount(client().prepareCount().setQuery(termQuery("num", 179)).get(), value1Docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get(), value1Docs + value2Docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(termQuery("field", "value1")).get(), value1Docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(termQuery("field", "value2")).get(), value2Docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(termQuery("num", 179)).get(), value1Docs);
|
||||
}
|
||||
|
||||
internalCluster().fullRestart();
|
||||
|
@ -177,10 +177,10 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
ensureYellow();
|
||||
|
||||
for (int i = 0; i <= randomInt(10); i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).get(), value1Docs + value2Docs);
|
||||
assertHitCount(client().prepareCount().setQuery(termQuery("field", "value1")).get(), value1Docs);
|
||||
assertHitCount(client().prepareCount().setQuery(termQuery("field", "value2")).get(), value2Docs);
|
||||
assertHitCount(client().prepareCount().setQuery(termQuery("num", 179)).get(), value1Docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get(), value1Docs + value2Docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(termQuery("field", "value1")).get(), value1Docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(termQuery("field", "value2")).get(), value2Docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(termQuery("num", 179)).get(), value1Docs);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,7 +193,7 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
client().prepareIndex("test", "type1", "2").setSource(jsonBuilder().startObject().field("field", "value2").endObject()).execute().actionGet();
|
||||
refresh();
|
||||
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).execute().actionGet(), 2);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet(), 2);
|
||||
|
||||
ensureYellow("test"); // wait for primary allocations here otherwise if we have a lot of shards we might have a
|
||||
// shard that is still in post recovery when we restart and the ensureYellow() below will timeout
|
||||
|
@ -204,7 +204,7 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
ensureYellow();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).execute().actionGet(), 2);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet(), 2);
|
||||
}
|
||||
|
||||
internalCluster().fullRestart();
|
||||
|
@ -213,7 +213,7 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
ensureYellow();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).execute().actionGet(), 2);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet(), 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
ensureGreen();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).execute().actionGet(), 2);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet(), 2);
|
||||
}
|
||||
|
||||
internalCluster().fullRestart(new RestartCallback() {
|
||||
|
@ -252,7 +252,7 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
ensureGreen();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).execute().actionGet(), 2);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet(), 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -270,7 +270,7 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
ensureGreen();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).execute().actionGet(), 2);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet(), 2);
|
||||
}
|
||||
|
||||
String metaDataUuid = client().admin().cluster().prepareState().execute().get().getState().getMetaData().clusterUUID();
|
||||
|
@ -290,7 +290,7 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
client.admin().indices().prepareRefresh().execute().actionGet();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client.prepareCount().setQuery(matchAllQuery()).execute().actionGet(), 3);
|
||||
assertHitCount(client.prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet(), 3);
|
||||
}
|
||||
|
||||
logger.info("--> add some metadata, additional type and template");
|
||||
|
@ -319,7 +319,7 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
assertThat(client().admin().cluster().prepareState().execute().get().getState().getMetaData().clusterUUID(), equalTo(metaDataUuid));
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).execute().actionGet(), 3);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet(), 3);
|
||||
}
|
||||
|
||||
ClusterState state = client().admin().cluster().prepareState().execute().actionGet().getState();
|
||||
|
@ -461,7 +461,7 @@ public class RecoveryFromGatewayIT extends ESIntegTestCase {
|
|||
ensureYellow();
|
||||
|
||||
assertThat(client().admin().indices().prepareExists("test").execute().actionGet().isExists(), equalTo(true));
|
||||
assertHitCount(client().prepareCount("test").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(), 1);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(), 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
package org.elasticsearch.index.mapper.multifield;
|
||||
|
||||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
||||
import org.elasticsearch.common.unit.DistanceUnit;
|
||||
|
@ -33,9 +32,7 @@ import org.junit.Test;
|
|||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.elasticsearch.index.query.QueryBuilders.geoDistanceQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.constantScoreQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
|
@ -124,12 +121,12 @@ public class MultiFieldsIntegrationIT extends ESIntegTestCase {
|
|||
assertThat(bField.get("index").toString(), equalTo("not_analyzed"));
|
||||
|
||||
client().prepareIndex("my-index", "my-type", "1").setSource("a", "51,19").setRefresh(true).get();
|
||||
CountResponse countResponse = client().prepareCount("my-index")
|
||||
SearchResponse countResponse = client().prepareSearch("my-index").setSize(0)
|
||||
.setQuery(constantScoreQuery(geoDistanceQuery("a").point(51, 19).distance(50, DistanceUnit.KILOMETERS)))
|
||||
.get();
|
||||
assertThat(countResponse.getCount(), equalTo(1l));
|
||||
countResponse = client().prepareCount("my-index").setQuery(matchQuery("a.b", "51,19")).get();
|
||||
assertThat(countResponse.getCount(), equalTo(1l));
|
||||
assertThat(countResponse.getHits().totalHits(), equalTo(1l));
|
||||
countResponse = client().prepareSearch("my-index").setSize(0).setQuery(matchQuery("a.b", "51,19")).get();
|
||||
assertThat(countResponse.getHits().totalHits(), equalTo(1l));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -167,8 +164,8 @@ public class MultiFieldsIntegrationIT extends ESIntegTestCase {
|
|||
assertThat(bField.get("index").toString(), equalTo("not_analyzed"));
|
||||
|
||||
client().prepareIndex("my-index", "my-type", "1").setSource("a", "my tokens").setRefresh(true).get();
|
||||
CountResponse countResponse = client().prepareCount("my-index").setQuery(matchQuery("a.b", "my tokens")).get();
|
||||
assertThat(countResponse.getCount(), equalTo(1l));
|
||||
SearchResponse countResponse = client().prepareSearch("my-index").setSize(0).setQuery(matchQuery("a.b", "my tokens")).get();
|
||||
assertThat(countResponse.getHits().totalHits(), equalTo(1l));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -193,8 +190,8 @@ public class MultiFieldsIntegrationIT extends ESIntegTestCase {
|
|||
assertThat(bField.get("index").toString(), equalTo("not_analyzed"));
|
||||
|
||||
client().prepareIndex("my-index", "my-type", "1").setSource("a", "complete me").setRefresh(true).get();
|
||||
CountResponse countResponse = client().prepareCount("my-index").setQuery(matchQuery("a.b", "complete me")).get();
|
||||
assertThat(countResponse.getCount(), equalTo(1l));
|
||||
SearchResponse countResponse = client().prepareSearch("my-index").setSize(0).setQuery(matchQuery("a.b", "complete me")).get();
|
||||
assertThat(countResponse.getHits().totalHits(), equalTo(1l));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -219,8 +216,8 @@ public class MultiFieldsIntegrationIT extends ESIntegTestCase {
|
|||
assertThat(bField.get("index").toString(), equalTo("not_analyzed"));
|
||||
|
||||
client().prepareIndex("my-index", "my-type", "1").setSource("a", "127.0.0.1").setRefresh(true).get();
|
||||
CountResponse countResponse = client().prepareCount("my-index").setQuery(matchQuery("a.b", "127.0.0.1")).get();
|
||||
assertThat(countResponse.getCount(), equalTo(1l));
|
||||
SearchResponse countResponse = client().prepareSearch("my-index").setSize(0).setQuery(matchQuery("a.b", "127.0.0.1")).get();
|
||||
assertThat(countResponse.getHits().totalHits(), equalTo(1l));
|
||||
}
|
||||
|
||||
private XContentBuilder createMappingSource(String fieldType) throws IOException {
|
||||
|
|
|
@ -29,7 +29,7 @@ import org.elasticsearch.action.admin.cluster.node.stats.NodeStats;
|
|||
import org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse;
|
||||
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse;
|
||||
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.client.Requests;
|
||||
|
@ -162,7 +162,7 @@ public class CorruptedFileIT extends ESIntegTestCase {
|
|||
ensureGreen();
|
||||
assertAllSuccessful(client().admin().indices().prepareFlush().setForce(true).setWaitIfOngoing(true).execute().actionGet());
|
||||
// we have to flush at least once here since we don't corrupt the translog
|
||||
CountResponse countResponse = client().prepareCount().get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
|
||||
final int numShards = numShards("test");
|
||||
|
@ -267,7 +267,7 @@ public class CorruptedFileIT extends ESIntegTestCase {
|
|||
ensureGreen();
|
||||
assertAllSuccessful(client().admin().indices().prepareFlush().setForce(true).setWaitIfOngoing(true).execute().actionGet());
|
||||
// we have to flush at least once here since we don't corrupt the translog
|
||||
CountResponse countResponse = client().prepareCount().get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
|
||||
ShardRouting shardRouting = corruptRandomPrimaryFile();
|
||||
|
@ -413,7 +413,7 @@ public class CorruptedFileIT extends ESIntegTestCase {
|
|||
ensureGreen();
|
||||
assertAllSuccessful(client().admin().indices().prepareFlush().setForce(true).setWaitIfOngoing(true).execute().actionGet());
|
||||
// we have to flush at least once here since we don't corrupt the translog
|
||||
CountResponse countResponse = client().prepareCount().get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
final boolean truncate = randomBoolean();
|
||||
for (NodeStats dataNode : dataNodeStats) {
|
||||
|
@ -495,7 +495,7 @@ public class CorruptedFileIT extends ESIntegTestCase {
|
|||
ensureGreen();
|
||||
assertAllSuccessful(client().admin().indices().prepareFlush().setForce(true).setWaitIfOngoing(true).execute().actionGet());
|
||||
// we have to flush at least once here since we don't corrupt the translog
|
||||
CountResponse countResponse = client().prepareCount().get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
|
||||
ShardRouting shardRouting = corruptRandomPrimaryFile(false);
|
||||
|
@ -551,7 +551,7 @@ public class CorruptedFileIT extends ESIntegTestCase {
|
|||
ensureGreen();
|
||||
assertAllSuccessful(client().admin().indices().prepareFlush().setForce(true).setWaitIfOngoing(true).execute().actionGet());
|
||||
// we have to flush at least once here since we don't corrupt the translog
|
||||
CountResponse countResponse = client().prepareCount().get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
|
||||
final Map<String, List<Path>> filesToCorrupt = findFilesToCorruptForReplica();
|
||||
|
|
|
@ -37,7 +37,6 @@ import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
|
|||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequestBuilder;
|
||||
import org.elasticsearch.action.admin.indices.validate.query.ValidateQueryRequestBuilder;
|
||||
import org.elasticsearch.action.admin.indices.warmer.get.GetWarmersRequestBuilder;
|
||||
import org.elasticsearch.action.count.CountRequestBuilder;
|
||||
import org.elasticsearch.action.percolate.MultiPercolateRequestBuilder;
|
||||
import org.elasticsearch.action.percolate.PercolateRequestBuilder;
|
||||
import org.elasticsearch.action.percolate.PercolateSourceBuilder;
|
||||
|
@ -75,7 +74,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
// Verify defaults
|
||||
verify(search("test1", "test2"), true);
|
||||
verify(msearch(null, "test1", "test2"), true);
|
||||
verify(count("test1", "test2"), true);
|
||||
verify(clearCache("test1", "test2"), true);
|
||||
verify(_flush("test1", "test2"),true);
|
||||
verify(segments("test1", "test2"), true);
|
||||
|
@ -97,7 +95,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
IndicesOptions options = IndicesOptions.strictExpandOpen();
|
||||
verify(search("test1", "test2").setIndicesOptions(options), true);
|
||||
verify(msearch(options, "test1", "test2"), true);
|
||||
verify(count("test1", "test2").setIndicesOptions(options), true);
|
||||
verify(clearCache("test1", "test2").setIndicesOptions(options), true);
|
||||
verify(_flush("test1", "test2").setIndicesOptions(options),true);
|
||||
verify(segments("test1", "test2").setIndicesOptions(options), true);
|
||||
|
@ -119,7 +116,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
options = IndicesOptions.lenientExpandOpen();
|
||||
verify(search("test1", "test2").setIndicesOptions(options), false);
|
||||
verify(msearch(options, "test1", "test2").setIndicesOptions(options), false);
|
||||
verify(count("test1", "test2").setIndicesOptions(options), false);
|
||||
verify(clearCache("test1", "test2").setIndicesOptions(options), false);
|
||||
verify(_flush("test1", "test2").setIndicesOptions(options), false);
|
||||
verify(segments("test1", "test2").setIndicesOptions(options), false);
|
||||
|
@ -143,7 +139,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
ensureYellow();
|
||||
verify(search("test1", "test2").setIndicesOptions(options), false);
|
||||
verify(msearch(options, "test1", "test2").setIndicesOptions(options), false);
|
||||
verify(count("test1", "test2").setIndicesOptions(options), false);
|
||||
verify(clearCache("test1", "test2").setIndicesOptions(options), false);
|
||||
verify(_flush("test1", "test2").setIndicesOptions(options),false);
|
||||
verify(segments("test1", "test2").setIndicesOptions(options), false);
|
||||
|
@ -176,7 +171,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
IndicesOptions options = IndicesOptions.strictExpandOpenAndForbidClosed();
|
||||
verify(search("test1").setIndicesOptions(options), true);
|
||||
verify(msearch(options, "test1"), true);
|
||||
verify(count("test1").setIndicesOptions(options), true);
|
||||
verify(clearCache("test1").setIndicesOptions(options), true);
|
||||
verify(_flush("test1").setIndicesOptions(options),true);
|
||||
verify(segments("test1").setIndicesOptions(options), true);
|
||||
|
@ -198,7 +192,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
options = IndicesOptions.fromOptions(true, options.allowNoIndices(), options.expandWildcardsOpen(), options.expandWildcardsClosed(), options);
|
||||
verify(search("test1").setIndicesOptions(options), false);
|
||||
verify(msearch(options, "test1"), false);
|
||||
verify(count("test1").setIndicesOptions(options), false);
|
||||
verify(clearCache("test1").setIndicesOptions(options), false);
|
||||
verify(_flush("test1").setIndicesOptions(options),false);
|
||||
verify(segments("test1").setIndicesOptions(options), false);
|
||||
|
@ -223,7 +216,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
options = IndicesOptions.strictExpandOpenAndForbidClosed();
|
||||
verify(search("test1").setIndicesOptions(options), false);
|
||||
verify(msearch(options, "test1"), false);
|
||||
verify(count("test1").setIndicesOptions(options), false);
|
||||
verify(clearCache("test1").setIndicesOptions(options), false);
|
||||
verify(_flush("test1").setIndicesOptions(options),false);
|
||||
verify(segments("test1").setIndicesOptions(options), false);
|
||||
|
@ -248,7 +240,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
IndicesOptions options = IndicesOptions.strictExpandOpenAndForbidClosed();
|
||||
verify(search("test1").setIndicesOptions(options), true);
|
||||
verify(msearch(options, "test1"), true);
|
||||
verify(count("test1").setIndicesOptions(options), true);
|
||||
verify(clearCache("test1").setIndicesOptions(options), true);
|
||||
verify(_flush("test1").setIndicesOptions(options),true);
|
||||
verify(segments("test1").setIndicesOptions(options), true);
|
||||
|
@ -269,7 +260,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
options = IndicesOptions.fromOptions(true, options.allowNoIndices(), options.expandWildcardsOpen(), options.expandWildcardsClosed(), options);
|
||||
verify(search("test1").setIndicesOptions(options), false);
|
||||
verify(msearch(options, "test1"), false);
|
||||
verify(count("test1").setIndicesOptions(options), false);
|
||||
verify(clearCache("test1").setIndicesOptions(options), false);
|
||||
verify(_flush("test1").setIndicesOptions(options),false);
|
||||
verify(segments("test1").setIndicesOptions(options), false);
|
||||
|
@ -293,7 +283,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
options = IndicesOptions.strictExpandOpenAndForbidClosed();
|
||||
verify(search("test1").setIndicesOptions(options), false);
|
||||
verify(msearch(options, "test1"), false);
|
||||
verify(count("test1").setIndicesOptions(options), false);
|
||||
verify(clearCache("test1").setIndicesOptions(options), false);
|
||||
verify(_flush("test1").setIndicesOptions(options),false);
|
||||
verify(segments("test1").setIndicesOptions(options), false);
|
||||
|
@ -349,7 +338,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
String[] indices = Strings.EMPTY_ARRAY;
|
||||
verify(search(indices), false);
|
||||
verify(msearch(null, indices), false);
|
||||
verify(count(indices), false);
|
||||
verify(clearCache(indices), false);
|
||||
verify(_flush(indices),false);
|
||||
verify(segments(indices), false);
|
||||
|
@ -372,7 +360,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
IndicesOptions options = IndicesOptions.fromOptions(false, true, true, false);
|
||||
verify(search(indices).setIndicesOptions(options), false);
|
||||
verify(msearch(options, indices).setIndicesOptions(options), false);
|
||||
verify(count(indices).setIndicesOptions(options), false);
|
||||
verify(clearCache(indices).setIndicesOptions(options), false);
|
||||
verify(_flush(indices).setIndicesOptions(options),false);
|
||||
verify(segments(indices).setIndicesOptions(options), false);
|
||||
|
@ -398,7 +385,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
indices = new String[]{"foo*"};
|
||||
verify(search(indices), false, 1);
|
||||
verify(msearch(null, indices), false, 1);
|
||||
verify(count(indices), false, 1);
|
||||
verify(clearCache(indices), false);
|
||||
verify(_flush(indices),false);
|
||||
verify(segments(indices), false);
|
||||
|
@ -421,7 +407,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
indices = new String[]{"foo*", "bar*"};
|
||||
verify(search(indices), false, 1);
|
||||
verify(msearch(null, indices), false, 1);
|
||||
verify(count(indices), false, 1);
|
||||
verify(clearCache(indices), false);
|
||||
verify(_flush(indices),false);
|
||||
verify(segments(indices), false);
|
||||
|
@ -444,7 +429,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
options = IndicesOptions.fromOptions(false, true, true, false);
|
||||
verify(search(indices).setIndicesOptions(options), false, 1);
|
||||
verify(msearch(options, indices).setIndicesOptions(options), false, 1);
|
||||
verify(count(indices).setIndicesOptions(options), false, 1);
|
||||
verify(clearCache(indices).setIndicesOptions(options), false);
|
||||
verify(_flush(indices).setIndicesOptions(options),false);
|
||||
verify(segments(indices).setIndicesOptions(options), false);
|
||||
|
@ -549,21 +533,16 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
createIndex("test1", "test2");
|
||||
ensureGreen();
|
||||
verify(search("test1", "test2"), false);
|
||||
verify(count("test1", "test2"), false);
|
||||
assertAcked(client().admin().indices().prepareClose("test2").get());
|
||||
|
||||
verify(search("test1", "test2"), true);
|
||||
verify(count("test1", "test2"), true);
|
||||
|
||||
IndicesOptions options = IndicesOptions.fromOptions(true, true, true, false, IndicesOptions.strictExpandOpenAndForbidClosed());
|
||||
verify(search("test1", "test2").setIndicesOptions(options), false);
|
||||
verify(count("test1", "test2").setIndicesOptions(options), false);
|
||||
|
||||
verify(search(), false);
|
||||
verify(count(), false);
|
||||
|
||||
verify(search("t*"), false);
|
||||
verify(count("t*"), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -793,10 +772,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
return multiSearchRequestBuilder.add(client().prepareSearch(indices).setQuery(matchAllQuery()));
|
||||
}
|
||||
|
||||
private static CountRequestBuilder count(String... indices) {
|
||||
return client().prepareCount(indices).setQuery(matchAllQuery());
|
||||
}
|
||||
|
||||
private static ClearIndicesCacheRequestBuilder clearCache(String... indices) {
|
||||
return client().admin().indices().prepareClearCache(indices);
|
||||
}
|
||||
|
@ -902,9 +877,6 @@ public class IndicesOptionsIntegrationIT extends ESIntegTestCase {
|
|||
if (requestBuilder instanceof SearchRequestBuilder) {
|
||||
SearchRequestBuilder searchRequestBuilder = (SearchRequestBuilder) requestBuilder;
|
||||
assertHitCount(searchRequestBuilder.get(), expectedCount);
|
||||
} else if (requestBuilder instanceof CountRequestBuilder) {
|
||||
CountRequestBuilder countRequestBuilder = (CountRequestBuilder) requestBuilder;
|
||||
assertHitCount(countRequestBuilder.get(), expectedCount);
|
||||
} else if (requestBuilder instanceof MultiSearchRequestBuilder) {
|
||||
MultiSearchResponse multiSearchResponse = ((MultiSearchRequestBuilder) requestBuilder).get();
|
||||
assertThat(multiSearchResponse.getResponses().length, equalTo(1));
|
||||
|
|
|
@ -181,12 +181,12 @@ public class FlushIT extends ESIntegTestCase {
|
|||
indexStats = client().admin().indices().prepareStats("test").get().getIndex("test");
|
||||
assertFlushResponseEqualsShardStats(indexStats.getShards(), syncedFlushResult.getShardsResultPerIndex().get("test"));
|
||||
refresh();
|
||||
assertThat(client().prepareCount().get().getCount(), equalTo((long) numDocs.get()));
|
||||
logger.info("indexed {} docs", client().prepareCount().get().getCount());
|
||||
assertThat(client().prepareSearch().setSize(0).get().getHits().totalHits(), equalTo((long) numDocs.get()));
|
||||
logger.info("indexed {} docs", client().prepareSearch().setSize(0).get().getHits().totalHits());
|
||||
logClusterState();
|
||||
internalCluster().fullRestart();
|
||||
ensureGreen();
|
||||
assertThat(client().prepareCount().get().getCount(), equalTo((long) numDocs.get()));
|
||||
assertThat(client().prepareSearch().setSize(0).get().getHits().totalHits(), equalTo((long) numDocs.get()));
|
||||
}
|
||||
|
||||
private void assertFlushResponseEqualsShardStats(ShardStats[] shardsStats, List<ShardsSyncedFlushResult> syncedFlushResults) {
|
||||
|
|
|
@ -22,7 +22,7 @@ package org.elasticsearch.indices.mapping;
|
|||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
|
||||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
|
||||
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
||||
|
@ -75,8 +75,8 @@ public class UpdateMappingIntegrationIT extends ESIntegTestCase {
|
|||
logger.info("checking all the documents are there");
|
||||
RefreshResponse refreshResponse = client().admin().indices().prepareRefresh().execute().actionGet();
|
||||
assertThat(refreshResponse.getFailedShards(), equalTo(0));
|
||||
CountResponse response = client().prepareCount("test").execute().actionGet();
|
||||
assertThat(response.getCount(), equalTo((long) recCount));
|
||||
SearchResponse response = client().prepareSearch("test").setSize(0).execute().actionGet();
|
||||
assertThat(response.getHits().totalHits(), equalTo((long) recCount));
|
||||
|
||||
logger.info("checking all the fields are in the mappings");
|
||||
|
||||
|
|
|
@ -516,7 +516,7 @@ public class IndexRecoveryIT extends ESIntegTestCase {
|
|||
|
||||
indexRandom(true, docs);
|
||||
flush();
|
||||
assertThat(client().prepareCount(INDEX_NAME).get().getCount(), equalTo((long) numDocs));
|
||||
assertThat(client().prepareSearch(INDEX_NAME).setSize(0).get().getHits().totalHits(), equalTo((long) numDocs));
|
||||
return client().admin().indices().prepareStats(INDEX_NAME).execute().actionGet();
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.indices.settings;
|
|||
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.Priority;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
|
@ -70,7 +70,7 @@ public class UpdateNumberOfReplicasIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
CountResponse countResponse = client().prepareCount().setQuery(matchAllQuery()).get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get();
|
||||
assertHitCount(countResponse, 10l);
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ public class UpdateNumberOfReplicasIT extends ESIntegTestCase {
|
|||
assertThat(clusterHealth.getIndices().get("test").getActiveShards(), equalTo(numShards.numPrimaries * 3));
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
CountResponse countResponse = client().prepareCount().setQuery(matchAllQuery()).get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get();
|
||||
assertHitCount(countResponse, 10l);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.elasticsearch.action.admin.indices.alias.Alias;
|
|||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesResponse;
|
||||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
|
||||
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.percolate.PercolateResponse;
|
||||
import org.elasticsearch.action.percolate.PercolateSourceBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
|
@ -328,10 +328,10 @@ public class PercolatorIT extends ESIntegTestCase {
|
|||
.execute().actionGet();
|
||||
|
||||
refresh();
|
||||
CountResponse countResponse = client().prepareCount()
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0)
|
||||
.setQuery(matchAllQuery()).setTypes(PercolatorService.TYPE_NAME)
|
||||
.execute().actionGet();
|
||||
assertThat(countResponse.getCount(), equalTo(1l));
|
||||
assertThat(countResponse.getHits().totalHits(), equalTo(1l));
|
||||
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
@ -357,7 +357,7 @@ public class PercolatorIT extends ESIntegTestCase {
|
|||
logger.info("--> delete the index");
|
||||
client().admin().indices().prepareDelete("test").execute().actionGet();
|
||||
logger.info("--> make sure percolated queries for it have been deleted as well");
|
||||
countResponse = client().prepareCount()
|
||||
countResponse = client().prepareSearch().setSize(0)
|
||||
.setQuery(matchAllQuery()).setTypes(PercolatorService.TYPE_NAME)
|
||||
.execute().actionGet();
|
||||
assertHitCount(countResponse, 0l);
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.percolator;
|
|||
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.percolate.MultiPercolateRequestBuilder;
|
||||
import org.elasticsearch.action.percolate.MultiPercolateResponse;
|
||||
import org.elasticsearch.action.percolate.PercolateRequestBuilder;
|
||||
|
@ -118,7 +118,7 @@ public class RecoveryPercolatorIT extends ESIntegTestCase {
|
|||
.setRefresh(true)
|
||||
.get();
|
||||
|
||||
assertThat(client().prepareCount().setTypes(PercolatorService.TYPE_NAME).setQuery(matchAllQuery()).get().getCount(), equalTo(1l));
|
||||
assertThat(client().prepareSearch().setSize(0).setTypes(PercolatorService.TYPE_NAME).setQuery(matchAllQuery()).get().getHits().totalHits(), equalTo(1l));
|
||||
|
||||
PercolateResponse percolate = client().preparePercolate()
|
||||
.setIndices("test").setDocumentType("type1")
|
||||
|
@ -135,7 +135,7 @@ public class RecoveryPercolatorIT extends ESIntegTestCase {
|
|||
ClusterHealthResponse clusterHealth = client().admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
|
||||
logger.info("Done Cluster Health, status " + clusterHealth.getStatus());
|
||||
assertThat(clusterHealth.isTimedOut(), equalTo(false));
|
||||
CountResponse countResponse = client().prepareCount().setTypes(PercolatorService.TYPE_NAME).setQuery(matchAllQuery()).get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).setTypes(PercolatorService.TYPE_NAME).setQuery(matchAllQuery()).get();
|
||||
assertHitCount(countResponse, 1l);
|
||||
|
||||
DeleteIndexResponse actionGet = client().admin().indices().prepareDelete("test").get();
|
||||
|
@ -144,7 +144,7 @@ public class RecoveryPercolatorIT extends ESIntegTestCase {
|
|||
clusterHealth = client().admin().cluster().health(clusterHealthRequest().waitForYellowStatus().waitForActiveShards(1)).actionGet();
|
||||
logger.info("Done Cluster Health, status " + clusterHealth.getStatus());
|
||||
assertThat(clusterHealth.isTimedOut(), equalTo(false));
|
||||
assertThat(client().prepareCount().setTypes(PercolatorService.TYPE_NAME).setQuery(matchAllQuery()).get().getCount(), equalTo(0l));
|
||||
assertThat(client().prepareSearch().setSize(0).setTypes(PercolatorService.TYPE_NAME).setQuery(matchAllQuery()).get().getHits().totalHits(), equalTo(0l));
|
||||
|
||||
percolate = client().preparePercolate()
|
||||
.setIndices("test").setDocumentType("type1")
|
||||
|
@ -164,7 +164,7 @@ public class RecoveryPercolatorIT extends ESIntegTestCase {
|
|||
.setRefresh(true)
|
||||
.get();
|
||||
|
||||
assertThat(client().prepareCount().setTypes(PercolatorService.TYPE_NAME).setQuery(matchAllQuery()).get().getCount(), equalTo(1l));
|
||||
assertThat(client().prepareSearch().setSize(0).setTypes(PercolatorService.TYPE_NAME).setQuery(matchAllQuery()).get().getHits().totalHits(), equalTo(1l));
|
||||
|
||||
percolate = client().preparePercolate()
|
||||
.setIndices("test").setDocumentType("type1")
|
||||
|
|
|
@ -88,7 +88,7 @@ public class FullRollingRestartIT extends ESIntegTestCase {
|
|||
logger.info("--> refreshing and checking data");
|
||||
refresh();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).get(), 2000l);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get(), 2000l);
|
||||
}
|
||||
|
||||
// now start shutting nodes down
|
||||
|
@ -106,7 +106,7 @@ public class FullRollingRestartIT extends ESIntegTestCase {
|
|||
logger.info("--> stopped two nodes, verifying data");
|
||||
refresh();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).get(), 2000l);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get(), 2000l);
|
||||
}
|
||||
|
||||
// closing the 3rd node
|
||||
|
@ -124,7 +124,7 @@ public class FullRollingRestartIT extends ESIntegTestCase {
|
|||
logger.info("--> one node left, verifying data");
|
||||
refresh();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
assertHitCount(client().prepareCount().setQuery(matchAllQuery()).get(), 2000l);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).get(), 2000l);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -114,7 +114,7 @@ public class RelocationIT extends ESIntegTestCase {
|
|||
|
||||
logger.info("--> verifying count");
|
||||
client().admin().indices().prepareRefresh().execute().actionGet();
|
||||
assertThat(client().prepareCount("test").execute().actionGet().getCount(), equalTo(20l));
|
||||
assertThat(client().prepareSearch("test").setSize(0).execute().actionGet().getHits().totalHits(), equalTo(20l));
|
||||
|
||||
logger.info("--> start another node");
|
||||
final String node_2 = internalCluster().startNode();
|
||||
|
@ -133,7 +133,7 @@ public class RelocationIT extends ESIntegTestCase {
|
|||
|
||||
logger.info("--> verifying count again...");
|
||||
client().admin().indices().prepareRefresh().execute().actionGet();
|
||||
assertThat(client().prepareCount("test").execute().actionGet().getCount(), equalTo(20l));
|
||||
assertThat(client().prepareSearch("test").setSize(0).execute().actionGet().getHits().totalHits(), equalTo(20l));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -131,17 +131,17 @@ public class AliasRoutingIT extends ESIntegTestCase {
|
|||
logger.info("--> search with wrong routing, should not find");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(0l));
|
||||
assertThat(client().prepareCount().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(0l));
|
||||
assertThat(client().prepareSearch().setSize(0).setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(0l));
|
||||
assertThat(client().prepareSearch("alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(0l));
|
||||
assertThat(client().prepareCount("alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(0l));
|
||||
assertThat(client().prepareSearch("alias1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(0l));
|
||||
}
|
||||
|
||||
logger.info("--> search with correct routing, should find");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch().setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
assertThat(client().prepareCount().setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
|
||||
assertThat(client().prepareSearch().setSize(0).setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
assertThat(client().prepareSearch("alias0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
assertThat(client().prepareCount("alias0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
|
||||
assertThat(client().prepareSearch("alias0").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
}
|
||||
|
||||
logger.info("--> indexing with id [2], and routing [1] using alias");
|
||||
|
@ -150,49 +150,49 @@ public class AliasRoutingIT extends ESIntegTestCase {
|
|||
logger.info("--> search with no routing, should fine two");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
assertThat(client().prepareCount().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(2l));
|
||||
assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
}
|
||||
|
||||
logger.info("--> search with 0 routing, should find one");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch().setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
assertThat(client().prepareCount().setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
|
||||
assertThat(client().prepareSearch().setSize(0).setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
assertThat(client().prepareSearch("alias0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
assertThat(client().prepareCount("alias0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
|
||||
assertThat(client().prepareSearch("alias0").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
}
|
||||
|
||||
logger.info("--> search with 1 routing, should find one");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
assertThat(client().prepareCount().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
|
||||
assertThat(client().prepareSearch().setSize(0).setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
assertThat(client().prepareSearch("alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
assertThat(client().prepareCount("alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
|
||||
assertThat(client().prepareSearch("alias1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
}
|
||||
|
||||
logger.info("--> search with 0,1 routings , should find two");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch().setRouting("0", "1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
assertThat(client().prepareCount().setRouting("0", "1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(2l));
|
||||
assertThat(client().prepareSearch().setSize(0).setRouting("0", "1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
assertThat(client().prepareSearch("alias01").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
assertThat(client().prepareCount("alias01").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(2l));
|
||||
assertThat(client().prepareSearch("alias01").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
}
|
||||
|
||||
logger.info("--> search with two routing aliases , should find two");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch("alias0", "alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
assertThat(client().prepareCount("alias0", "alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(2l));
|
||||
assertThat(client().prepareSearch("alias0", "alias1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
}
|
||||
|
||||
logger.info("--> search with alias0, alias1 and alias01, should find two");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch("alias0", "alias1", "alias01").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
assertThat(client().prepareCount("alias0", "alias1", "alias01").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(2l));
|
||||
assertThat(client().prepareSearch("alias0", "alias1", "alias01").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
}
|
||||
|
||||
logger.info("--> search with test, alias0 and alias1, should find two");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch("test", "alias0", "alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
assertThat(client().prepareCount("test", "alias0", "alias1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(2l));
|
||||
assertThat(client().prepareSearch("test", "alias0", "alias1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -236,19 +236,19 @@ public class AliasRoutingIT extends ESIntegTestCase {
|
|||
logger.info("--> search with alias-a1,alias-b0, should not find");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch("alias-a1", "alias-b0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(0l));
|
||||
assertThat(client().prepareCount("alias-a1", "alias-b0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(0l));
|
||||
assertThat(client().prepareSearch("alias-a1", "alias-b0").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(0l));
|
||||
}
|
||||
|
||||
logger.info("--> search with alias-ab, should find two");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch("alias-ab").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
assertThat(client().prepareCount("alias-ab").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(2l));
|
||||
assertThat(client().prepareSearch("alias-ab").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
}
|
||||
|
||||
logger.info("--> search with alias-a0,alias-b1 should find two");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch("alias-a0", "alias-b1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
assertThat(client().prepareCount("alias-a0", "alias-b1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(2l));
|
||||
assertThat(client().prepareSearch("alias-a0", "alias-b1").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -321,7 +321,7 @@ public class AliasRoutingIT extends ESIntegTestCase {
|
|||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareGet("test", "type1", "0").setRouting("3").execute().actionGet().isExists(), equalTo(true));
|
||||
assertThat(client().prepareSearch("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
assertThat(client().prepareCount("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
|
||||
assertThat(client().prepareSearch("alias").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
}
|
||||
|
||||
logger.info("--> creating alias with routing [4]");
|
||||
|
@ -331,7 +331,7 @@ public class AliasRoutingIT extends ESIntegTestCase {
|
|||
logger.info("--> verifying search with wrong routing should not find");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(0l));
|
||||
assertThat(client().prepareCount("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(0l));
|
||||
assertThat(client().prepareSearch("alias").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(0l));
|
||||
}
|
||||
|
||||
logger.info("--> creating alias with search routing [3,4] and index routing 4");
|
||||
|
@ -347,7 +347,7 @@ public class AliasRoutingIT extends ESIntegTestCase {
|
|||
assertThat(client().prepareGet("test", "type1", "0").setRouting("3").execute().actionGet().isExists(), equalTo(true));
|
||||
assertThat(client().prepareGet("test", "type1", "1").setRouting("4").execute().actionGet().isExists(), equalTo(true));
|
||||
assertThat(client().prepareSearch("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
assertThat(client().prepareCount("alias").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(2l));
|
||||
assertThat(client().prepareSearch("alias").setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -111,13 +111,13 @@ public class SimpleRoutingIT extends ESIntegTestCase {
|
|||
logger.info("--> search with wrong routing, should not find");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(0l));
|
||||
assertThat(client().prepareCount().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(0l));
|
||||
assertThat(client().prepareSearch().setSize(0).setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(0l));
|
||||
}
|
||||
|
||||
logger.info("--> search with correct routing, should find");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch().setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
assertThat(client().prepareCount().setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
|
||||
assertThat(client().prepareSearch().setSize(0).setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
}
|
||||
|
||||
logger.info("--> indexing with id [2], and routing [1]");
|
||||
|
@ -126,31 +126,31 @@ public class SimpleRoutingIT extends ESIntegTestCase {
|
|||
logger.info("--> search with no routing, should fine two");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
assertThat(client().prepareCount().setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(2l));
|
||||
assertThat(client().prepareSearch().setSize(0).setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
}
|
||||
|
||||
logger.info("--> search with 0 routing, should find one");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch().setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
assertThat(client().prepareCount().setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
|
||||
assertThat(client().prepareSearch().setSize(0).setRouting("0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
}
|
||||
|
||||
logger.info("--> search with 1 routing, should find one");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
assertThat(client().prepareCount().setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(1l));
|
||||
assertThat(client().prepareSearch().setSize(0).setRouting("1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(1l));
|
||||
}
|
||||
|
||||
logger.info("--> search with 0,1 routings , should find two");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch().setRouting("0", "1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
assertThat(client().prepareCount().setRouting("0", "1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(2l));
|
||||
assertThat(client().prepareSearch().setSize(0).setRouting("0", "1").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
}
|
||||
|
||||
logger.info("--> search with 0,1,0 routings , should find two");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertThat(client().prepareSearch().setRouting("0", "1", "0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
assertThat(client().prepareCount().setRouting("0", "1", "0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getCount(), equalTo(2l));
|
||||
assertThat(client().prepareSearch().setSize(0).setRouting("0", "1", "0").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(2l));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ package org.elasticsearch.search.child;
|
|||
import org.apache.lucene.search.join.ScoreMode;
|
||||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
|
||||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.explain.ExplainResponse;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
||||
|
@ -558,19 +558,19 @@ public class ChildQuerySearchIT extends ESIntegTestCase {
|
|||
client().prepareIndex("test", "child", "c1").setSource("c_field", "1").setParent(parentId).get();
|
||||
refresh();
|
||||
|
||||
CountResponse countResponse = client().prepareCount("test").setQuery(hasChildQuery("child", termQuery("c_field", "1")).scoreMode(ScoreMode.Max))
|
||||
SearchResponse countResponse = client().prepareSearch("test").setSize(0).setQuery(hasChildQuery("child", termQuery("c_field", "1")).scoreMode(ScoreMode.Max))
|
||||
.get();
|
||||
assertHitCount(countResponse, 1l);
|
||||
|
||||
countResponse = client().prepareCount("test").setQuery(hasParentQuery("parent", termQuery("p_field", "1")).score(true))
|
||||
countResponse = client().prepareSearch("test").setSize(0).setQuery(hasParentQuery("parent", termQuery("p_field", "1")).score(true))
|
||||
.get();
|
||||
assertHitCount(countResponse, 1l);
|
||||
|
||||
countResponse = client().prepareCount("test").setQuery(constantScoreQuery(hasChildQuery("child", termQuery("c_field", "1"))))
|
||||
countResponse = client().prepareSearch("test").setSize(0).setQuery(constantScoreQuery(hasChildQuery("child", termQuery("c_field", "1"))))
|
||||
.get();
|
||||
assertHitCount(countResponse, 1l);
|
||||
|
||||
countResponse = client().prepareCount("test").setQuery(constantScoreQuery(hasParentQuery("parent", termQuery("p_field", "1"))))
|
||||
countResponse = client().prepareSearch("test").setSize(0).setQuery(constantScoreQuery(hasParentQuery("parent", termQuery("p_field", "1"))))
|
||||
.get();
|
||||
assertHitCount(countResponse, 1l);
|
||||
}
|
||||
|
|
|
@ -19,15 +19,12 @@
|
|||
package org.elasticsearch.search.query;
|
||||
|
||||
import com.carrotsearch.randomizedtesting.generators.RandomPicks;
|
||||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.*;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.common.util.set.Sets;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.index.engine.Engine;
|
||||
import org.elasticsearch.index.query.*;
|
||||
import org.elasticsearch.index.search.MatchQuery;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
|
@ -39,9 +36,7 @@ import org.junit.Before;
|
|||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -278,8 +273,8 @@ public class MultiMatchQueryIT extends ESIntegTestCase {
|
|||
|
||||
@Test
|
||||
public void testCutoffFreq() throws ExecutionException, InterruptedException {
|
||||
final long numDocs = client().prepareCount("test")
|
||||
.setQuery(matchAllQuery()).get().getCount();
|
||||
final long numDocs = client().prepareSearch("test").setSize(0)
|
||||
.setQuery(matchAllQuery()).get().getHits().totalHits();
|
||||
MatchQuery.Type type = randomBoolean() ? MatchQueryBuilder.DEFAULT_TYPE : MatchQuery.Type.BOOLEAN;
|
||||
Float cutoffFrequency = randomBoolean() ? Math.min(1, numDocs * 1.f / between(10, 20)) : 1.f / between(10, 20);
|
||||
SearchResponse searchResponse = client().prepareSearch("test")
|
||||
|
@ -340,8 +335,8 @@ public class MultiMatchQueryIT extends ESIntegTestCase {
|
|||
@Test
|
||||
public void testEquivalence() {
|
||||
|
||||
final int numDocs = (int) client().prepareCount("test")
|
||||
.setQuery(matchAllQuery()).get().getCount();
|
||||
final int numDocs = (int) client().prepareSearch("test").setSize(0)
|
||||
.setQuery(matchAllQuery()).get().getHits().totalHits();
|
||||
int numIters = scaledRandomIntBetween(5, 10);
|
||||
for (int i = 0; i < numIters; i++) {
|
||||
{
|
||||
|
|
|
@ -193,11 +193,11 @@ public class SearchScrollIT extends ESIntegTestCase {
|
|||
|
||||
client().admin().indices().prepareRefresh().execute().actionGet();
|
||||
|
||||
assertThat(client().prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(500l));
|
||||
assertThat(client().prepareCount().setQuery(termQuery("message", "test")).execute().actionGet().getCount(), equalTo(500l));
|
||||
assertThat(client().prepareCount().setQuery(termQuery("message", "test")).execute().actionGet().getCount(), equalTo(500l));
|
||||
assertThat(client().prepareCount().setQuery(termQuery("message", "update")).execute().actionGet().getCount(), equalTo(0l));
|
||||
assertThat(client().prepareCount().setQuery(termQuery("message", "update")).execute().actionGet().getCount(), equalTo(0l));
|
||||
assertThat(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(500l));
|
||||
assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).execute().actionGet().getHits().totalHits(), equalTo(500l));
|
||||
assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).execute().actionGet().getHits().totalHits(), equalTo(500l));
|
||||
assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).execute().actionGet().getHits().totalHits(), equalTo(0l));
|
||||
assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).execute().actionGet().getHits().totalHits(), equalTo(0l));
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch()
|
||||
.setQuery(queryStringQuery("user:kimchy"))
|
||||
|
@ -216,11 +216,11 @@ public class SearchScrollIT extends ESIntegTestCase {
|
|||
} while (searchResponse.getHits().hits().length > 0);
|
||||
|
||||
client().admin().indices().prepareRefresh().execute().actionGet();
|
||||
assertThat(client().prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount(), equalTo(500l));
|
||||
assertThat(client().prepareCount().setQuery(termQuery("message", "test")).execute().actionGet().getCount(), equalTo(0l));
|
||||
assertThat(client().prepareCount().setQuery(termQuery("message", "test")).execute().actionGet().getCount(), equalTo(0l));
|
||||
assertThat(client().prepareCount().setQuery(termQuery("message", "update")).execute().actionGet().getCount(), equalTo(500l));
|
||||
assertThat(client().prepareCount().setQuery(termQuery("message", "update")).execute().actionGet().getCount(), equalTo(500l));
|
||||
assertThat(client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits(), equalTo(500l));
|
||||
assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).execute().actionGet().getHits().totalHits(), equalTo(0l));
|
||||
assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "test")).execute().actionGet().getHits().totalHits(), equalTo(0l));
|
||||
assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).execute().actionGet().getHits().totalHits(), equalTo(500l));
|
||||
assertThat(client().prepareSearch().setSize(0).setQuery(termQuery("message", "update")).execute().actionGet().getHits().totalHits(), equalTo(500l));
|
||||
} finally {
|
||||
clearScroll(searchResponse.getScrollId());
|
||||
}
|
||||
|
|
|
@ -981,7 +981,7 @@ public class CompletionSuggestSearchIT extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
assertSuggestions("b");
|
||||
assertThat(2l, equalTo(client().prepareCount(INDEX).get().getCount()));
|
||||
assertThat(2l, equalTo(client().prepareSearch(INDEX).setSize(0).get().getHits().totalHits()));
|
||||
for (IndexShardSegments seg : client().admin().indices().prepareSegments().get().getIndices().get(INDEX)) {
|
||||
ShardSegments[] shards = seg.getShards();
|
||||
for (ShardSegments shardSegments : shards) {
|
||||
|
|
|
@ -299,7 +299,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest
|
|||
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> create repository");
|
||||
logger.info("--> creating repository");
|
||||
|
@ -348,7 +348,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest
|
|||
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> creating repository");
|
||||
Path repo = randomRepoPath();
|
||||
|
@ -414,7 +414,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest
|
|||
index("test-idx-some", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client().prepareCount("test-idx-some").get().getCount(), equalTo(100L));
|
||||
assertThat(client().prepareSearch("test-idx-some").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> shutdown one of the nodes");
|
||||
internalCluster().stopRandomDataNode();
|
||||
|
@ -435,7 +435,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest
|
|||
index("test-idx-closed", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client().prepareCount("test-idx-all").get().getCount(), equalTo(100L));
|
||||
assertThat(client().prepareSearch("test-idx-all").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertAcked(client().admin().indices().prepareClose("test-idx-closed"));
|
||||
|
||||
logger.info("--> create an index that will have no allocated shards");
|
||||
|
@ -522,7 +522,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest
|
|||
assertThat(restoreSnapshotResponse.getRestoreInfo().successfulShards(), equalTo(6));
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), equalTo(0));
|
||||
|
||||
assertThat(client().prepareCount("test-idx-all").get().getCount(), equalTo(100L));
|
||||
assertThat(client().prepareSearch("test-idx-all").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> restore snapshot for the partial index");
|
||||
cluster().wipeIndices("test-idx-some");
|
||||
|
@ -533,7 +533,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest
|
|||
assertThat(restoreSnapshotResponse.getRestoreInfo().successfulShards(), allOf(greaterThan(0), lessThan(6)));
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), greaterThan(0));
|
||||
|
||||
assertThat(client().prepareCount("test-idx-some").get().getCount(), allOf(greaterThan(0L), lessThan(100L)));
|
||||
assertThat(client().prepareSearch("test-idx-some").setSize(0).get().getHits().totalHits(), allOf(greaterThan(0L), lessThan(100L)));
|
||||
|
||||
logger.info("--> restore snapshot for the index that didn't have any shards snapshotted successfully");
|
||||
cluster().wipeIndices("test-idx-none");
|
||||
|
@ -544,7 +544,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest
|
|||
assertThat(restoreSnapshotResponse.getRestoreInfo().successfulShards(), equalTo(0));
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), equalTo(6));
|
||||
|
||||
assertThat(client().prepareCount("test-idx-some").get().getCount(), allOf(greaterThan(0L), lessThan(100L)));
|
||||
assertThat(client().prepareSearch("test-idx-some").setSize(0).get().getHits().totalHits(), allOf(greaterThan(0L), lessThan(100L)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -573,7 +573,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest
|
|||
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client().prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client().prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> start snapshot");
|
||||
assertThat(client().admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-1").setIndices("test-idx").setWaitForCompletion(true).get().getSnapshotInfo().state(), equalTo(SnapshotState.SUCCESS));
|
||||
|
@ -595,7 +595,7 @@ public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest
|
|||
assertThat(client().admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap-1").setRestoreGlobalState(false).setWaitForCompletion(true).get().getRestoreInfo().successfulShards(), equalTo(6));
|
||||
|
||||
ensureGreen("test-idx");
|
||||
assertThat(client().prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client().prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
IntSet reusedShards = new IntHashSet();
|
||||
for (RecoveryState recoveryState : client().admin().indices().prepareRecoveries("test-idx").get().shardRecoveryStates().get("test-idx")) {
|
||||
|
|
|
@ -37,7 +37,7 @@ import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
|
|||
import org.elasticsearch.action.admin.indices.flush.FlushResponse;
|
||||
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse;
|
||||
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.cluster.ClusterService;
|
||||
|
@ -126,9 +126,9 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
index("test-idx-3", "doc", Integer.toString(i), "foo", "baz" + i);
|
||||
}
|
||||
refresh();
|
||||
assertHitCount(client.prepareCount("test-idx-1").get(), 100L);
|
||||
assertHitCount(client.prepareCount("test-idx-2").get(), 100L);
|
||||
assertHitCount(client.prepareCount("test-idx-3").get(), 100L);
|
||||
assertHitCount(client.prepareSearch("test-idx-1").setSize(0).get(), 100L);
|
||||
assertHitCount(client.prepareSearch("test-idx-2").setSize(0).get(), 100L);
|
||||
assertHitCount(client.prepareSearch("test-idx-3").setSize(0).get(), 100L);
|
||||
|
||||
ListenableActionFuture<FlushResponse> flushResponseFuture = null;
|
||||
if (randomBoolean()) {
|
||||
|
@ -164,9 +164,9 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
client.prepareDelete("test-idx-3", "doc", Integer.toString(i)).get();
|
||||
}
|
||||
assertAllSuccessful(refresh());
|
||||
assertHitCount(client.prepareCount("test-idx-1").get(), 50L);
|
||||
assertHitCount(client.prepareCount("test-idx-2").get(), 50L);
|
||||
assertHitCount(client.prepareCount("test-idx-3").get(), 50L);
|
||||
assertHitCount(client.prepareSearch("test-idx-1").setSize(0).get(), 50L);
|
||||
assertHitCount(client.prepareSearch("test-idx-2").setSize(0).get(), 50L);
|
||||
assertHitCount(client.prepareSearch("test-idx-3").setSize(0).get(), 50L);
|
||||
|
||||
logger.info("--> close indices");
|
||||
client.admin().indices().prepareClose("test-idx-1", "test-idx-2").get();
|
||||
|
@ -177,9 +177,9 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
|
||||
ensureGreen();
|
||||
for (int i=0; i<5; i++) {
|
||||
assertHitCount(client.prepareCount("test-idx-1").get(), 100L);
|
||||
assertHitCount(client.prepareCount("test-idx-2").get(), 100L);
|
||||
assertHitCount(client.prepareCount("test-idx-3").get(), 50L);
|
||||
assertHitCount(client.prepareSearch("test-idx-1").setSize(0).get(), 100L);
|
||||
assertHitCount(client.prepareSearch("test-idx-2").setSize(0).get(), 100L);
|
||||
assertHitCount(client.prepareSearch("test-idx-3").setSize(0).get(), 50L);
|
||||
}
|
||||
|
||||
// Test restore after index deletion
|
||||
|
@ -191,7 +191,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
|
||||
ensureGreen();
|
||||
for (int i=0; i<5; i++) {
|
||||
assertHitCount(client.prepareCount("test-idx-1").get(), 100L);
|
||||
assertHitCount(client.prepareSearch("test-idx-1").setSize(0).get(), 100L);
|
||||
}
|
||||
ClusterState clusterState = client.admin().cluster().prepareState().get().getState();
|
||||
assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true));
|
||||
|
@ -502,7 +502,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> snapshot without global state but with indices");
|
||||
createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap-no-global-state-with-index").setIndices("test-idx").setIncludeGlobalState(false).setWaitForCompletion(true).get();
|
||||
|
@ -524,7 +524,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
logger.info("--> check that template wasn't restored but index was");
|
||||
getIndexTemplatesResponse = client().admin().indices().prepareGetTemplates().get();
|
||||
assertIndexTemplateMissing(getIndexTemplatesResponse, "test-template");
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
}
|
||||
|
||||
|
@ -549,7 +549,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> snapshot");
|
||||
try {
|
||||
|
@ -598,7 +598,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> snapshot");
|
||||
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").get();
|
||||
|
@ -662,7 +662,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> snapshot");
|
||||
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").get();
|
||||
|
@ -683,8 +683,8 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
logger.info("--> restore index after deletion");
|
||||
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
CountResponse countResponse = client.prepareCount("test-idx").get();
|
||||
assertThat(countResponse.getCount(), equalTo(100L));
|
||||
SearchResponse countResponse = client.prepareSearch("test-idx").setSize(0).get();
|
||||
assertThat(countResponse.getHits().totalHits(), equalTo(100L));
|
||||
logger.info("--> total number of simulated failures during restore: [{}]", getFailureCount("test-repo"));
|
||||
}
|
||||
|
||||
|
@ -705,7 +705,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> snapshot");
|
||||
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").get();
|
||||
|
@ -748,8 +748,8 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().failedShards(), equalTo(0));
|
||||
CountResponse countResponse = client.prepareCount("test-idx").get();
|
||||
assertThat(countResponse.getCount(), equalTo(100L));
|
||||
SearchResponse countResponse = client.prepareSearch("test-idx").setSize(0).get();
|
||||
assertThat(countResponse.getHits().totalHits(), equalTo(100L));
|
||||
|
||||
}
|
||||
|
||||
|
@ -803,7 +803,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
// Store number of files after each snapshot
|
||||
numberOfFiles[i] = numberOfFiles(repo);
|
||||
}
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(10L * numberOfSnapshots));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(10L * numberOfSnapshots));
|
||||
int numberOfFilesBeforeDeletion = numberOfFiles(repo);
|
||||
|
||||
logger.info("--> delete all snapshots except the first one and last one");
|
||||
|
@ -823,7 +823,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", lastSnapshot).setWaitForCompletion(true).execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(10L * numberOfSnapshots));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(10L * numberOfSnapshots));
|
||||
|
||||
logger.info("--> delete the last snapshot");
|
||||
client.admin().cluster().prepareDeleteSnapshot("test-repo", lastSnapshot).get();
|
||||
|
@ -1019,8 +1019,8 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
index("test-idx-2", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> snapshot");
|
||||
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx-1", "test-idx-2").get();
|
||||
|
@ -1032,8 +1032,8 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
.setRenamePattern("(.+)").setRenameReplacement("$1-copy").setWaitForCompletion(true).execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
|
||||
assertThat(client.prepareCount("test-idx-1-copy").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-2-copy").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-1-copy").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-2-copy").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> close just restored indices");
|
||||
client.admin().indices().prepareClose("test-idx-1-copy", "test-idx-2-copy").get();
|
||||
|
@ -1043,8 +1043,8 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
.setRenamePattern("(.+)").setRenameReplacement("$1-copy").setWaitForCompletion(true).execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
|
||||
assertThat(client.prepareCount("test-idx-1-copy").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-2-copy").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-1-copy").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-2-copy").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
|
||||
logger.info("--> close indices");
|
||||
|
@ -1135,7 +1135,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
// Pick one node and block it
|
||||
String blockedNode = blockNodeWithIndex("test-idx");
|
||||
|
@ -1174,7 +1174,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1199,7 +1199,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
// Pick one node and block it
|
||||
String blockedNode = blockNodeWithIndex("test-idx");
|
||||
|
@ -1257,7 +1257,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1280,7 +1280,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> snapshot");
|
||||
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").get();
|
||||
|
@ -1301,7 +1301,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("url-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> list available shapshots");
|
||||
GetSnapshotsResponse getSnapshotsResponse = client.admin().cluster().prepareGetSnapshots("url-repo").get();
|
||||
|
@ -1361,7 +1361,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("readonly-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> list available shapshots");
|
||||
GetSnapshotsResponse getSnapshotsResponse = client.admin().cluster().prepareGetSnapshots("readonly-repo").get();
|
||||
|
@ -1399,7 +1399,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> snapshot");
|
||||
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").get();
|
||||
|
@ -1412,7 +1412,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
logger.info("--> restore index");
|
||||
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
long snapshotPause = 0L;
|
||||
long restorePause = 0L;
|
||||
|
@ -1457,7 +1457,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
// Pick one node and block it
|
||||
String blockedNode = blockNodeWithIndex("test-idx");
|
||||
|
@ -1553,7 +1553,7 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
index("test-idx", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
// Update settings to make sure that relocation is slow so we can start snapshot before relocation is finished
|
||||
assertAcked(client.admin().indices().prepareUpdateSettings("test-idx").setSettings(Settings.builder()
|
||||
|
@ -1680,8 +1680,8 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
indexRandom(true, builders);
|
||||
flushAndRefresh();
|
||||
|
||||
assertHitCount(client.prepareCount("test-idx").setQuery(matchQuery("field1", "foo")).get(), numdocs);
|
||||
assertHitCount(client.prepareCount("test-idx").setQuery(matchQuery("field1", "bar")).get(), numdocs);
|
||||
assertHitCount(client.prepareSearch("test-idx").setSize(0).setQuery(matchQuery("field1", "foo")).get(), numdocs);
|
||||
assertHitCount(client.prepareSearch("test-idx").setSize(0).setQuery(matchQuery("field1", "bar")).get(), numdocs);
|
||||
|
||||
logger.info("--> snapshot it");
|
||||
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx").get();
|
||||
|
@ -1735,8 +1735,8 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
assertThat(getSettingsResponse.getSetting("test-idx", "index.analysis.analyzer.my_analyzer.type"), equalTo("standard"));
|
||||
assertThat(getSettingsResponse.getSetting("test-idx", "index.analysis.filter.my_synonym.type"), nullValue());
|
||||
|
||||
assertHitCount(client.prepareCount("test-idx").setQuery(matchQuery("field1", "foo")).get(), 0);
|
||||
assertHitCount(client.prepareCount("test-idx").setQuery(matchQuery("field1", "bar")).get(), numdocs);
|
||||
assertHitCount(client.prepareSearch("test-idx").setSize(0).setQuery(matchQuery("field1", "foo")).get(), 0);
|
||||
assertHitCount(client.prepareSearch("test-idx").setSize(0).setQuery(matchQuery("field1", "bar")).get(), numdocs);
|
||||
|
||||
logger.info("--> delete the index and recreate it while deleting all index settings");
|
||||
cluster().wipeIndices("test-idx");
|
||||
|
@ -1755,8 +1755,8 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
// Make sure that number of shards didn't change
|
||||
assertThat(getSettingsResponse.getSetting("test-idx", SETTING_NUMBER_OF_SHARDS), equalTo("" + numberOfShards));
|
||||
|
||||
assertHitCount(client.prepareCount("test-idx").setQuery(matchQuery("field1", "foo")).get(), 0);
|
||||
assertHitCount(client.prepareCount("test-idx").setQuery(matchQuery("field1", "bar")).get(), numdocs);
|
||||
assertHitCount(client.prepareSearch("test-idx").setSize(0).setQuery(matchQuery("field1", "foo")).get(), 0);
|
||||
assertHitCount(client.prepareSearch("test-idx").setSize(0).setQuery(matchQuery("field1", "bar")).get(), numdocs);
|
||||
|
||||
}
|
||||
|
||||
|
@ -1875,9 +1875,9 @@ public class SharedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCas
|
|||
index("test-idx-3", "doc", Integer.toString(i), "foo", "baz" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> snapshot allow partial {}", allowPartial);
|
||||
ListenableActionFuture<CreateSnapshotResponse> future = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap")
|
||||
|
|
|
@ -24,7 +24,7 @@ import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRes
|
|||
import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotResponse;
|
||||
import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotIndexShardStatus;
|
||||
import org.elasticsearch.action.admin.cluster.snapshots.status.SnapshotStatus;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.index.IndexRequestBuilder;
|
||||
import org.elasticsearch.client.Client;
|
||||
|
@ -84,10 +84,10 @@ public class SnapshotBackwardsCompatibilityIT extends ESBackcompatTestCase {
|
|||
}
|
||||
indexRandom(true, buildersBefore);
|
||||
indexRandom(true, buildersAfter);
|
||||
assertThat(client().prepareCount(indices).get().getCount(), equalTo((long) (buildersBefore.length + buildersAfter.length)));
|
||||
assertThat(client().prepareSearch(indices).setSize(0).get().getHits().totalHits(), equalTo((long) (buildersBefore.length + buildersAfter.length)));
|
||||
long[] counts = new long[indices.length];
|
||||
for (int i = 0; i < indices.length; i++) {
|
||||
counts[i] = client().prepareCount(indices[i]).get().getCount();
|
||||
counts[i] = client().prepareSearch(indices[i]).setSize(0).get().getHits().totalHits();
|
||||
}
|
||||
|
||||
logger.info("--> snapshot subset of indices before upgrage");
|
||||
|
@ -106,8 +106,8 @@ public class SnapshotBackwardsCompatibilityIT extends ESBackcompatTestCase {
|
|||
client().prepareDelete(request.index(), request.type(), request.id()).get();
|
||||
}
|
||||
refresh();
|
||||
final long numDocs = client().prepareCount(indices).get().getCount();
|
||||
assertThat(client().prepareCount(indices).get().getCount(), lessThan((long) (buildersBefore.length + buildersAfter.length)));
|
||||
final long numDocs = client().prepareSearch(indices).setSize(0).get().getHits().totalHits();
|
||||
assertThat(client().prepareSearch(indices).setSize(0).get().getHits().totalHits(), lessThan((long) (buildersBefore.length + buildersAfter.length)));
|
||||
|
||||
|
||||
disableAllocation(indices);
|
||||
|
@ -116,11 +116,11 @@ public class SnapshotBackwardsCompatibilityIT extends ESBackcompatTestCase {
|
|||
boolean upgraded;
|
||||
do {
|
||||
logClusterState();
|
||||
CountResponse countResponse = client().prepareCount().get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
upgraded = backwardsCluster().upgradeOneNode();
|
||||
ensureYellow();
|
||||
countResponse = client().prepareCount().get();
|
||||
countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
} while (upgraded);
|
||||
enableAllocation(indices);
|
||||
|
@ -136,9 +136,9 @@ public class SnapshotBackwardsCompatibilityIT extends ESBackcompatTestCase {
|
|||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
|
||||
ensureYellow();
|
||||
assertThat(client().prepareCount(indices).get().getCount(), equalTo((long) (buildersBefore.length + buildersAfter.length)));
|
||||
assertThat(client().prepareSearch(indices).setSize(0).get().getHits().totalHits(), equalTo((long) (buildersBefore.length + buildersAfter.length)));
|
||||
for (int i = 0; i < indices.length; i++) {
|
||||
assertThat(counts[i], equalTo(client().prepareCount(indices[i]).get().getCount()));
|
||||
assertThat(counts[i], equalTo(client().prepareSearch(indices[i]).setSize(0).get().getHits().totalHits()));
|
||||
}
|
||||
|
||||
logger.info("--> snapshot subset of indices after upgrade");
|
||||
|
@ -154,9 +154,9 @@ public class SnapshotBackwardsCompatibilityIT extends ESBackcompatTestCase {
|
|||
restoreSnapshotResponse = client().admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap-2").setWaitForCompletion(true).setIndices(index).execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
ensureYellow();
|
||||
assertThat(client().prepareCount(indices).get().getCount(), equalTo((long) (buildersBefore.length + buildersAfter.length)));
|
||||
assertThat(client().prepareSearch(indices).setSize(0).get().getHits().totalHits(), equalTo((long) (buildersBefore.length + buildersAfter.length)));
|
||||
for (int i = 0; i < indices.length; i++) {
|
||||
assertThat(counts[i], equalTo(client().prepareCount(indices[i]).get().getCount()));
|
||||
assertThat(counts[i], equalTo(client().prepareSearch(indices[i]).setSize(0).get().getHits().totalHits()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,11 +206,11 @@ public class SnapshotBackwardsCompatibilityIT extends ESBackcompatTestCase {
|
|||
boolean upgraded;
|
||||
do {
|
||||
logClusterState();
|
||||
CountResponse countResponse = client().prepareCount().get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
upgraded = backwardsCluster().upgradeOneNode();
|
||||
ensureYellow();
|
||||
countResponse = client().prepareCount().get();
|
||||
countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
} while (upgraded);
|
||||
enableAllocation("test");
|
||||
|
|
|
@ -992,7 +992,7 @@ public abstract class ESIntegTestCase extends ESTestCase {
|
|||
}
|
||||
if (lastKnownCount.get() >= numDocs) {
|
||||
try {
|
||||
long count = client().prepareCount().setQuery(matchAllQuery()).execute().actionGet().getCount();
|
||||
long count = client().prepareSearch().setSize(0).setQuery(matchAllQuery()).execute().actionGet().getHits().totalHits();
|
||||
if (count == lastKnownCount.get()) {
|
||||
// no progress - try to refresh for the next time
|
||||
client().admin().indices().prepareRefresh().get();
|
||||
|
|
|
@ -36,7 +36,6 @@ import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder;
|
|||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
|
||||
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
|
||||
import org.elasticsearch.action.bulk.BulkResponse;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.exists.ExistsResponse;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.percolate.PercolateResponse;
|
||||
|
@ -206,17 +205,6 @@ public class ElasticsearchAssertions {
|
|||
return msg;
|
||||
}
|
||||
|
||||
/*
|
||||
* assertions
|
||||
*/
|
||||
public static void assertHitCount(SearchResponse searchResponse, long expectedHitCount) {
|
||||
if (searchResponse.getHits().totalHits() != expectedHitCount) {
|
||||
fail("Hit count is " + searchResponse.getHits().totalHits() + " but " + expectedHitCount + " was expected. "
|
||||
+ formatShardStatus(searchResponse));
|
||||
}
|
||||
assertVersionSerializable(searchResponse);
|
||||
}
|
||||
|
||||
public static void assertNoSearchHits(SearchResponse searchResponse) {
|
||||
assertEquals(0, searchResponse.getHits().getHits().length);
|
||||
}
|
||||
|
@ -256,9 +244,9 @@ public class ElasticsearchAssertions {
|
|||
assertVersionSerializable(searchResponse);
|
||||
}
|
||||
|
||||
public static void assertHitCount(CountResponse countResponse, long expectedHitCount) {
|
||||
if (countResponse.getCount() != expectedHitCount) {
|
||||
fail("Count is " + countResponse.getCount() + " but " + expectedHitCount + " was expected. " + formatShardStatus(countResponse));
|
||||
public static void assertHitCount(SearchResponse countResponse, long expectedHitCount) {
|
||||
if (countResponse.getHits().totalHits() != expectedHitCount) {
|
||||
fail("Count is " + countResponse.getHits().totalHits() + " but " + expectedHitCount + " was expected. " + formatShardStatus(countResponse));
|
||||
}
|
||||
assertVersionSerializable(countResponse);
|
||||
}
|
||||
|
|
|
@ -283,7 +283,7 @@ public class TribeIT extends ESIntegTestCase {
|
|||
tribeClient.admin().indices().prepareRefresh().get();
|
||||
|
||||
logger.info("verify they are there");
|
||||
assertHitCount(tribeClient.prepareCount().get(), 2l);
|
||||
assertHitCount(tribeClient.prepareSearch().setSize(0).get(), 2l);
|
||||
assertHitCount(tribeClient.prepareSearch().get(), 2l);
|
||||
assertBusy(new Runnable() {
|
||||
@Override
|
||||
|
@ -302,7 +302,7 @@ public class TribeIT extends ESIntegTestCase {
|
|||
|
||||
|
||||
logger.info("verify they are there");
|
||||
assertHitCount(tribeClient.prepareCount().get(), 4l);
|
||||
assertHitCount(tribeClient.prepareSearch().setSize(0).get(), 4l);
|
||||
assertHitCount(tribeClient.prepareSearch().get(), 4l);
|
||||
assertBusy(new Runnable() {
|
||||
@Override
|
||||
|
|
|
@ -1,22 +0,0 @@
|
|||
[[count]]
|
||||
== Count API
|
||||
|
||||
The count API is very similar to the
|
||||
{java}/count.html[Java count API]. The Groovy
|
||||
extension allows to provide the query to execute as a `Closure` (similar
|
||||
to GORM criteria builder):
|
||||
|
||||
[source,js]
|
||||
--------------------------------------------------
|
||||
def count = client.count {
|
||||
indices "test"
|
||||
types "type1"
|
||||
query {
|
||||
term {
|
||||
test = "value"
|
||||
}
|
||||
}
|
||||
}
|
||||
--------------------------------------------------
|
||||
|
||||
The query follows the same {ref}/query-dsl.html[Query DSL].
|
|
@ -46,5 +46,3 @@ include::get.asciidoc[]
|
|||
include::delete.asciidoc[]
|
||||
|
||||
include::search.asciidoc[]
|
||||
|
||||
include::count.asciidoc[]
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
[[count]]
|
||||
== Count API
|
||||
|
||||
The count API allows one to easily execute a query and get the number of
|
||||
matches for that query. It can be executed across one or more indices
|
||||
and across one or more types. The query can be provided using the
|
||||
{ref}/query-dsl.html[Query DSL].
|
||||
|
||||
[source,java]
|
||||
--------------------------------------------------
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
|
||||
CountResponse response = client.prepareCount("test")
|
||||
.setQuery(termQuery("_type", "type1"))
|
||||
.execute()
|
||||
.actionGet();
|
||||
--------------------------------------------------
|
||||
|
||||
For more information on the count operation, check out the REST
|
||||
{ref}/search-count.html[count] docs.
|
||||
|
||||
|
||||
=== Operation Threading
|
||||
|
||||
The count API allows one to set the threading model the operation will be
|
||||
performed when the actual execution of the API is performed on the same
|
||||
node (the API is executed on a shard that is allocated on the same
|
||||
server).
|
||||
|
||||
There are three threading modes.The `NO_THREADS` mode means that the
|
||||
count operation will be executed on the calling thread. The
|
||||
`SINGLE_THREAD` mode means that the count operation will be executed on
|
||||
a single different thread for all local shards. The `THREAD_PER_SHARD`
|
||||
mode means that the count operation will be executed on a different
|
||||
thread for each local shard.
|
||||
|
||||
The default mode is `SINGLE_THREAD`.
|
|
@ -84,8 +84,6 @@ include::docs.asciidoc[]
|
|||
|
||||
include::search.asciidoc[]
|
||||
|
||||
include::count.asciidoc[]
|
||||
|
||||
include::aggs.asciidoc[]
|
||||
|
||||
include::percolate.asciidoc[]
|
||||
|
|
|
@ -148,6 +148,22 @@ Cloud GCE plugin has been renamed to {plugins}/discovery-gce.html[Discovery GCE
|
|||
|
||||
=== Java-API
|
||||
|
||||
==== Count api has been removed
|
||||
|
||||
The deprecated count api has been removed from the Java api, use the search api instead and set size to 0.
|
||||
|
||||
The following call
|
||||
|
||||
```
|
||||
client.prepareCount(indices).setQuery(query).get();
|
||||
```
|
||||
|
||||
can be replaced with
|
||||
|
||||
```
|
||||
client.prepareSearch(indices).setSource(new SearchSourceBuilder().size(0).query(query)).get();
|
||||
```
|
||||
|
||||
==== BoostingQueryBuilder
|
||||
|
||||
Removed setters for mandatory positive/negative query. Both arguments now have
|
||||
|
|
|
@ -67,7 +67,7 @@ public class TransportDeleteByQueryActionTests extends ESSingleNodeTestCase {
|
|||
client().prepareIndex("test", "type").setSource("num", i).get();
|
||||
}
|
||||
client().admin().indices().prepareRefresh("test").get();
|
||||
assertHitCount(client().prepareCount("test").get(), numDocs);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).get(), numDocs);
|
||||
|
||||
final long limit = randomIntBetween(0, numDocs);
|
||||
DeleteByQueryRequest delete = new DeleteByQueryRequest().indices(new String[]{"test"}).query(boolQuery().must(rangeQuery("num").lte(limit)));
|
||||
|
@ -115,7 +115,7 @@ public class TransportDeleteByQueryActionTests extends ESSingleNodeTestCase {
|
|||
client().prepareIndex("test", "type").setSource("num", i).get();
|
||||
}
|
||||
client().admin().indices().prepareRefresh("test").get();
|
||||
assertHitCount(client().prepareCount("test").get(), numDocs);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).get(), numDocs);
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("test").setScroll(TimeValue.timeValueSeconds(10)).get();
|
||||
assertThat(searchResponse.getHits().getTotalHits(), equalTo(numDocs));
|
||||
|
@ -190,7 +190,7 @@ public class TransportDeleteByQueryActionTests extends ESSingleNodeTestCase {
|
|||
client().prepareIndex("test", "type").setSource("num", i).get();
|
||||
}
|
||||
client().admin().indices().prepareRefresh("test").get();
|
||||
assertHitCount(client().prepareCount("test").get(), numDocs);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).get(), numDocs);
|
||||
|
||||
final long limit = randomIntBetween(0, numDocs);
|
||||
|
||||
|
|
|
@ -80,12 +80,12 @@ public class DeleteByQueryTests extends ESIntegTestCase {
|
|||
index("test", "test", String.valueOf(i), "fields1", 1);
|
||||
}
|
||||
refresh();
|
||||
assertHitCount(client().prepareCount("test").get(), docs);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).get(), docs);
|
||||
|
||||
DeleteByQueryRequestBuilder delete = newDeleteByQuery().setIndices("t*").setQuery(QueryBuilders.matchAllQuery());
|
||||
assertDBQResponse(delete.get(), docs, docs, 0l, 0l);
|
||||
refresh();
|
||||
assertHitCount(client().prepareCount("test").get(), 0);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).get(), 0);
|
||||
assertSearchContextsClosed();
|
||||
}
|
||||
|
||||
|
@ -113,9 +113,9 @@ public class DeleteByQueryTests extends ESIntegTestCase {
|
|||
}
|
||||
refresh();
|
||||
|
||||
assertHitCount(client().prepareCount().get(), docs * indices);
|
||||
assertHitCount(client().prepareSearch().setSize(0).get(), docs * indices);
|
||||
for (int i = 0; i < indices; i++) {
|
||||
assertHitCount(client().prepareCount("test-" + i).get(), docs);
|
||||
assertHitCount(client().prepareSearch("test-" + i).setSize(0).get(), docs);
|
||||
}
|
||||
|
||||
// Deletes all the documents with candidate=true
|
||||
|
@ -136,10 +136,10 @@ public class DeleteByQueryTests extends ESIntegTestCase {
|
|||
assertThat(indexResponse.getMissing(), equalTo(0L));
|
||||
assertThat(indexResponse.getIndex(), equalTo(indexName));
|
||||
long remaining = docs - candidates[i];
|
||||
assertHitCount(client().prepareCount(indexName).get(), remaining);
|
||||
assertHitCount(client().prepareSearch(indexName).setSize(0).get(), remaining);
|
||||
}
|
||||
|
||||
assertHitCount(client().prepareCount().get(), (indices * docs) - deletions);
|
||||
assertHitCount(client().prepareSearch().setSize(0).get(), (indices * docs) - deletions);
|
||||
assertSearchContextsClosed();
|
||||
}
|
||||
|
||||
|
@ -149,7 +149,7 @@ public class DeleteByQueryTests extends ESIntegTestCase {
|
|||
.setSource(jsonBuilder().startObject().field("field1", 1).endObject())
|
||||
.setRefresh(true)
|
||||
.get();
|
||||
assertHitCount(client().prepareCount().get(), 1);
|
||||
assertHitCount(client().prepareSearch().setSize(0).get(), 1);
|
||||
|
||||
DeleteByQueryRequestBuilder delete = newDeleteByQuery().setIndices("test", "missing").setQuery(QueryBuilders.matchAllQuery());
|
||||
try {
|
||||
|
@ -162,7 +162,7 @@ public class DeleteByQueryTests extends ESIntegTestCase {
|
|||
delete.setIndicesOptions(IndicesOptions.lenientExpandOpen());
|
||||
assertDBQResponse(delete.get(), 1L, 1L, 0l, 0l);
|
||||
refresh();
|
||||
assertHitCount(client().prepareCount("test").get(), 0);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).get(), 0);
|
||||
assertSearchContextsClosed();
|
||||
}
|
||||
|
||||
|
@ -174,17 +174,17 @@ public class DeleteByQueryTests extends ESIntegTestCase {
|
|||
index(randomFrom("test1", "test2", "test3"), "type2", String.valueOf(i), "foo", "bar");
|
||||
}
|
||||
refresh();
|
||||
assertHitCount(client().prepareCount().get(), docs * 2);
|
||||
assertHitCount(client().prepareCount().setTypes("type1").get(), docs);
|
||||
assertHitCount(client().prepareCount().setTypes("type2").get(), docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).get(), docs * 2);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setTypes("type1").get(), docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setTypes("type2").get(), docs);
|
||||
|
||||
DeleteByQueryRequestBuilder delete = newDeleteByQuery().setTypes("type1").setQuery(QueryBuilders.matchAllQuery());
|
||||
assertDBQResponse(delete.get(), docs, docs, 0l, 0l);
|
||||
refresh();
|
||||
|
||||
assertHitCount(client().prepareCount().get(), docs);
|
||||
assertHitCount(client().prepareCount().setTypes("type1").get(), 0);
|
||||
assertHitCount(client().prepareCount().setTypes("type2").get(), docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).get(), docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setTypes("type1").get(), 0);
|
||||
assertHitCount(client().prepareSearch().setSize(0).setTypes("type2").get(), docs);
|
||||
assertSearchContextsClosed();
|
||||
}
|
||||
|
||||
|
@ -201,19 +201,19 @@ public class DeleteByQueryTests extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
logger.info("--> counting documents with no routing, should be equal to [{}]", docs);
|
||||
assertHitCount(client().prepareCount().get(), docs);
|
||||
assertHitCount(client().prepareSearch().setSize(0).get(), docs);
|
||||
|
||||
String routing = String.valueOf(randomIntBetween(2, docs));
|
||||
|
||||
logger.info("--> counting documents with routing [{}]", routing);
|
||||
long expected = client().prepareCount().setRouting(routing).get().getCount();
|
||||
long expected = client().prepareSearch().setSize(0).setRouting(routing).get().getHits().totalHits();
|
||||
|
||||
logger.info("--> delete all documents with routing [{}] with a delete-by-query", routing);
|
||||
DeleteByQueryRequestBuilder delete = newDeleteByQuery().setRouting(routing).setQuery(QueryBuilders.matchAllQuery());
|
||||
assertDBQResponse(delete.get(), expected, expected, 0l, 0l);
|
||||
refresh();
|
||||
|
||||
assertHitCount(client().prepareCount().get(), docs - expected);
|
||||
assertHitCount(client().prepareSearch().setSize(0).get(), docs - expected);
|
||||
assertSearchContextsClosed();
|
||||
}
|
||||
|
||||
|
@ -230,13 +230,13 @@ public class DeleteByQueryTests extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
int n = between(0, numDocs - 1);
|
||||
assertHitCount(client().prepareCount("test").setQuery(QueryBuilders.matchQuery("_id", Integer.toString(n))).get(), 1);
|
||||
assertHitCount(client().prepareCount("test").setQuery(QueryBuilders.matchAllQuery()).get(), numDocs);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).setQuery(QueryBuilders.matchQuery("_id", Integer.toString(n))).get(), 1);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get(), numDocs);
|
||||
|
||||
DeleteByQueryRequestBuilder delete = newDeleteByQuery().setIndices("alias").setQuery(QueryBuilders.matchQuery("_id", Integer.toString(n)));
|
||||
assertDBQResponse(delete.get(), 1L, 1L, 0l, 0l);
|
||||
refresh();
|
||||
assertHitCount(client().prepareCount("test").setQuery(QueryBuilders.matchAllQuery()).get(), numDocs - 1);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).setQuery(QueryBuilders.matchAllQuery()).get(), numDocs - 1);
|
||||
assertSearchContextsClosed();
|
||||
}
|
||||
|
||||
|
@ -245,12 +245,12 @@ public class DeleteByQueryTests extends ESIntegTestCase {
|
|||
index("test", "type", "1", "d", "2013-01-01");
|
||||
ensureGreen();
|
||||
refresh();
|
||||
assertHitCount(client().prepareCount("test").get(), 1);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).get(), 1);
|
||||
|
||||
DeleteByQueryRequestBuilder delete = newDeleteByQuery().setIndices("test").setQuery(QueryBuilders.rangeQuery("d").to("now-1h"));
|
||||
assertDBQResponse(delete.get(), 1L, 1L, 0l, 0l);
|
||||
refresh();
|
||||
assertHitCount(client().prepareCount("test").get(), 0);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).get(), 0);
|
||||
assertSearchContextsClosed();
|
||||
}
|
||||
|
||||
|
@ -295,14 +295,14 @@ public class DeleteByQueryTests extends ESIntegTestCase {
|
|||
}
|
||||
}
|
||||
refresh();
|
||||
assertHitCount(client().prepareCount("test").get(), docs * threads.length);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).get(), docs * threads.length);
|
||||
|
||||
final CountDownLatch start = new CountDownLatch(1);
|
||||
final AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
|
||||
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
final int threadNum = i;
|
||||
assertHitCount(client().prepareCount("test").setQuery(QueryBuilders.termQuery("field", threadNum)).get(), docs);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).setQuery(QueryBuilders.termQuery("field", threadNum)).get(), docs);
|
||||
|
||||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
|
@ -337,7 +337,7 @@ public class DeleteByQueryTests extends ESIntegTestCase {
|
|||
refresh();
|
||||
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
assertHitCount(client().prepareCount("test").setQuery(QueryBuilders.termQuery("field", i)).get(), 0);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).setQuery(QueryBuilders.termQuery("field", i)).get(), 0);
|
||||
}
|
||||
assertSearchContextsClosed();
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ public class DeleteByQueryTests extends ESIntegTestCase {
|
|||
index("test", "test", String.valueOf(i), "foo", "bar");
|
||||
}
|
||||
refresh();
|
||||
assertHitCount(client().prepareCount("test").get(), docs);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).get(), docs);
|
||||
|
||||
final Thread[] threads = new Thread[scaledRandomIntBetween(2, 9)];
|
||||
|
||||
|
@ -363,7 +363,7 @@ public class DeleteByQueryTests extends ESIntegTestCase {
|
|||
final AtomicLong deleted = new AtomicLong(0);
|
||||
|
||||
for (int i = 0; i < threads.length; i++) {
|
||||
assertHitCount(client().prepareCount("test").setQuery(query).get(), docs);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).setQuery(query).get(), docs);
|
||||
|
||||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
|
@ -397,7 +397,7 @@ public class DeleteByQueryTests extends ESIntegTestCase {
|
|||
assertionError.printStackTrace();
|
||||
}
|
||||
assertThat(assertionError + " should be null", assertionError, nullValue());
|
||||
assertHitCount(client().prepareCount("test").get(), 0L);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).get(), 0L);
|
||||
assertThat(deleted.get(), equalTo(docs));
|
||||
assertSearchContextsClosed();
|
||||
}
|
||||
|
@ -412,7 +412,7 @@ public class DeleteByQueryTests extends ESIntegTestCase {
|
|||
index("test", "test", String.valueOf(i), "field", 1);
|
||||
}
|
||||
refresh();
|
||||
assertHitCount(client().prepareCount("test").get(), docs);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).get(), docs);
|
||||
|
||||
try {
|
||||
enableIndexBlock("test", IndexMetaData.SETTING_READ_ONLY);
|
||||
|
@ -422,7 +422,7 @@ public class DeleteByQueryTests extends ESIntegTestCase {
|
|||
disableIndexBlock("test", IndexMetaData.SETTING_READ_ONLY);
|
||||
}
|
||||
|
||||
assertHitCount(client().prepareCount("test").get(), docs);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).get(), docs);
|
||||
assertSearchContextsClosed();
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import org.elasticsearch.action.bulk.BulkItemResponse;
|
|||
import org.elasticsearch.action.bulk.BulkRequest;
|
||||
import org.elasticsearch.action.bulk.BulkRequestBuilder;
|
||||
import org.elasticsearch.action.bulk.BulkResponse;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.delete.DeleteRequest;
|
||||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
|
@ -407,7 +407,7 @@ public class BulkTests extends ESIntegTestCase {
|
|||
|
||||
refresh();
|
||||
|
||||
CountResponse countResponse = client().prepareCount().get();
|
||||
SearchResponse countResponse = client().prepareSearch().setSize(0).get();
|
||||
assertHitCount(countResponse, numDocs);
|
||||
}
|
||||
|
||||
|
|
|
@ -2009,8 +2009,8 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
client().prepareIndex("test", "type", "3").setSource("field", -999999999999L));
|
||||
|
||||
|
||||
assertHitCount(client().prepareCount("test").setQuery(rangeQuery("field").lte(-1000000000000L)).get(), 2);
|
||||
assertHitCount(client().prepareCount("test").setQuery(rangeQuery("field").lte(-999999999999L)).get(), 3);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).setQuery(rangeQuery("field").lte(-1000000000000L)).get(), 2);
|
||||
assertHitCount(client().prepareSearch("test").setSize(0).setQuery(rangeQuery("field").lte(-999999999999L)).get(), 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -67,9 +67,9 @@ public class AzureSnapshotRestoreServiceTests extends AbstractAzureRepositorySer
|
|||
index("test-idx-3", "doc", Integer.toString(i), "foo", "baz" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> snapshot");
|
||||
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx-*", "-test-idx-3").get();
|
||||
|
@ -89,9 +89,9 @@ public class AzureSnapshotRestoreServiceTests extends AbstractAzureRepositorySer
|
|||
client.prepareDelete("test-idx-3", "doc", Integer.toString(i)).get();
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
|
||||
logger.info("--> close indices");
|
||||
client.admin().indices().prepareClose("test-idx-1", "test-idx-2").get();
|
||||
|
@ -101,9 +101,9 @@ public class AzureSnapshotRestoreServiceTests extends AbstractAzureRepositorySer
|
|||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
|
||||
ensureGreen();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
|
||||
// Test restore after index deletion
|
||||
logger.info("--> delete indices");
|
||||
|
@ -112,7 +112,7 @@ public class AzureSnapshotRestoreServiceTests extends AbstractAzureRepositorySer
|
|||
restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx-*", "-test-idx-2").execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
ensureGreen();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
ClusterState clusterState = client.admin().cluster().prepareState().get().getState();
|
||||
assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true));
|
||||
assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(false));
|
||||
|
|
|
@ -123,9 +123,9 @@ public class AzureSnapshotRestoreTests extends AbstractAzureWithThirdPartyTestCa
|
|||
index("test-idx-3", "doc", Integer.toString(i), "foo", "baz" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> snapshot");
|
||||
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx-*", "-test-idx-3").get();
|
||||
|
@ -145,9 +145,9 @@ public class AzureSnapshotRestoreTests extends AbstractAzureWithThirdPartyTestCa
|
|||
client.prepareDelete("test-idx-3", "doc", Integer.toString(i)).get();
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
|
||||
logger.info("--> close indices");
|
||||
client.admin().indices().prepareClose("test-idx-1", "test-idx-2").get();
|
||||
|
@ -157,9 +157,9 @@ public class AzureSnapshotRestoreTests extends AbstractAzureWithThirdPartyTestCa
|
|||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
|
||||
ensureGreen();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
|
||||
// Test restore after index deletion
|
||||
logger.info("--> delete indices");
|
||||
|
@ -168,7 +168,7 @@ public class AzureSnapshotRestoreTests extends AbstractAzureWithThirdPartyTestCa
|
|||
restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx-*", "-test-idx-2").execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
ensureGreen();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
ClusterState clusterState = client.admin().cluster().prepareState().get().getState();
|
||||
assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true));
|
||||
assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(false));
|
||||
|
@ -194,7 +194,7 @@ public class AzureSnapshotRestoreTests extends AbstractAzureWithThirdPartyTestCa
|
|||
logger.info("indexing first document");
|
||||
index(indexName, typeName, Integer.toString(1), "foo", "bar " + Integer.toString(1));
|
||||
refresh();
|
||||
assertThat(client.prepareCount(indexName).get().getCount(), equalTo(1L));
|
||||
assertThat(client.prepareSearch(indexName).setSize(0).get().getHits().totalHits(), equalTo(1L));
|
||||
|
||||
logger.info("creating Azure repository with path [{}]", getRepositoryPath());
|
||||
PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository(repositoryName)
|
||||
|
@ -215,7 +215,7 @@ public class AzureSnapshotRestoreTests extends AbstractAzureWithThirdPartyTestCa
|
|||
logger.info("indexing second document");
|
||||
index(indexName, typeName, Integer.toString(2), "foo", "bar " + Integer.toString(2));
|
||||
refresh();
|
||||
assertThat(client.prepareCount(indexName).get().getCount(), equalTo(2L));
|
||||
assertThat(client.prepareSearch(indexName).setSize(0).get().getHits().totalHits(), equalTo(2L));
|
||||
|
||||
logger.info("creating snapshot [{}]", snapshot2Name);
|
||||
CreateSnapshotResponse createSnapshotResponse2 = client.admin().cluster().prepareCreateSnapshot(repositoryName, snapshot2Name).setWaitForCompletion(true).setIndices(indexName).get();
|
||||
|
@ -231,7 +231,7 @@ public class AzureSnapshotRestoreTests extends AbstractAzureWithThirdPartyTestCa
|
|||
RestoreSnapshotResponse restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot(repositoryName, snapshot1Name).setWaitForCompletion(true).execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
ensureGreen();
|
||||
assertThat(client.prepareCount(indexName).get().getCount(), equalTo(1L));
|
||||
assertThat(client.prepareSearch(indexName).setSize(0).get().getHits().totalHits(), equalTo(1L));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -262,8 +262,8 @@ public class AzureSnapshotRestoreTests extends AbstractAzureWithThirdPartyTestCa
|
|||
index("test-idx-2", "doc", Integer.toString(i), "foo", "baz" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> snapshot 1");
|
||||
CreateSnapshotResponse createSnapshotResponse1 = client.admin().cluster().prepareCreateSnapshot("test-repo1", "test-snap").setWaitForCompletion(true).setIndices("test-idx-1").get();
|
||||
|
@ -285,7 +285,7 @@ public class AzureSnapshotRestoreTests extends AbstractAzureWithThirdPartyTestCa
|
|||
RestoreSnapshotResponse restoreSnapshotResponse1 = client.admin().cluster().prepareRestoreSnapshot("test-repo1", "test-snap").setWaitForCompletion(true).setIndices("test-idx-1").execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse1.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
ensureGreen();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
ClusterState clusterState = client.admin().cluster().prepareState().get().getState();
|
||||
assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true));
|
||||
assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(false));
|
||||
|
@ -294,7 +294,7 @@ public class AzureSnapshotRestoreTests extends AbstractAzureWithThirdPartyTestCa
|
|||
RestoreSnapshotResponse restoreSnapshotResponse2 = client.admin().cluster().prepareRestoreSnapshot("test-repo2", "test-snap").setWaitForCompletion(true).setIndices("test-idx-2").execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse2.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
ensureGreen();
|
||||
assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
clusterState = client.admin().cluster().prepareState().get().getState();
|
||||
assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true));
|
||||
assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(true));
|
||||
|
|
|
@ -110,9 +110,9 @@ abstract public class AbstractS3SnapshotRestoreTest extends AbstractAwsTestCase
|
|||
index("test-idx-3", "doc", Integer.toString(i), "foo", "baz" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> snapshot");
|
||||
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx-*", "-test-idx-3").get();
|
||||
|
@ -132,9 +132,9 @@ abstract public class AbstractS3SnapshotRestoreTest extends AbstractAwsTestCase
|
|||
client.prepareDelete("test-idx-3", "doc", Integer.toString(i)).get();
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
|
||||
logger.info("--> close indices");
|
||||
client.admin().indices().prepareClose("test-idx-1", "test-idx-2").get();
|
||||
|
@ -144,9 +144,9 @@ abstract public class AbstractS3SnapshotRestoreTest extends AbstractAwsTestCase
|
|||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
|
||||
ensureGreen();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
|
||||
// Test restore after index deletion
|
||||
logger.info("--> delete indices");
|
||||
|
@ -155,7 +155,7 @@ abstract public class AbstractS3SnapshotRestoreTest extends AbstractAwsTestCase
|
|||
restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx-*", "-test-idx-2").execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
ensureGreen();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
ClusterState clusterState = client.admin().cluster().prepareState().get().getState();
|
||||
assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true));
|
||||
assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(false));
|
||||
|
@ -183,9 +183,9 @@ abstract public class AbstractS3SnapshotRestoreTest extends AbstractAwsTestCase
|
|||
index("test-idx-3", "doc", Integer.toString(i), "foo", "baz" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> snapshot");
|
||||
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx-*", "-test-idx-3").get();
|
||||
|
@ -221,9 +221,9 @@ abstract public class AbstractS3SnapshotRestoreTest extends AbstractAwsTestCase
|
|||
client.prepareDelete("test-idx-3", "doc", Integer.toString(i)).get();
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
|
||||
logger.info("--> close indices");
|
||||
client.admin().indices().prepareClose("test-idx-1", "test-idx-2").get();
|
||||
|
@ -233,9 +233,9 @@ abstract public class AbstractS3SnapshotRestoreTest extends AbstractAwsTestCase
|
|||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
|
||||
ensureGreen();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-2").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareCount("test-idx-3").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-2").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-3").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
|
||||
// Test restore after index deletion
|
||||
logger.info("--> delete indices");
|
||||
|
@ -244,7 +244,7 @@ abstract public class AbstractS3SnapshotRestoreTest extends AbstractAwsTestCase
|
|||
restoreSnapshotResponse = client.admin().cluster().prepareRestoreSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx-*", "-test-idx-2").execute().actionGet();
|
||||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
ensureGreen();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
ClusterState clusterState = client.admin().cluster().prepareState().get().getState();
|
||||
assertThat(clusterState.getMetaData().hasIndex("test-idx-1"), equalTo(true));
|
||||
assertThat(clusterState.getMetaData().hasIndex("test-idx-2"), equalTo(false));
|
||||
|
@ -398,7 +398,7 @@ abstract public class AbstractS3SnapshotRestoreTest extends AbstractAwsTestCase
|
|||
index("test-idx-1", "doc", Integer.toString(i), "foo", "bar" + i);
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
|
||||
logger.info("--> snapshot");
|
||||
CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot(repository, "test-snap").setWaitForCompletion(true).setIndices("test-idx-*").get();
|
||||
|
@ -412,7 +412,7 @@ abstract public class AbstractS3SnapshotRestoreTest extends AbstractAwsTestCase
|
|||
client.prepareDelete("test-idx-1", "doc", Integer.toString(i)).get();
|
||||
}
|
||||
refresh();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(50L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(50L));
|
||||
|
||||
logger.info("--> close indices");
|
||||
client.admin().indices().prepareClose("test-idx-1").get();
|
||||
|
@ -422,7 +422,7 @@ abstract public class AbstractS3SnapshotRestoreTest extends AbstractAwsTestCase
|
|||
assertThat(restoreSnapshotResponse.getRestoreInfo().totalShards(), greaterThan(0));
|
||||
|
||||
ensureGreen();
|
||||
assertThat(client.prepareCount("test-idx-1").get().getCount(), equalTo(100L));
|
||||
assertThat(client.prepareSearch("test-idx-1").setSize(0).get().getHits().totalHits(), equalTo(100L));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue