Merge branch 'master' into feature/multi_cluster_search

This commit is contained in:
Simon Willnauer 2017-01-11 17:03:30 +01:00
commit d3124dd62b
21 changed files with 55 additions and 134 deletions

View File

@ -119,7 +119,6 @@ import org.elasticsearch.repositories.RepositoriesModule;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.SearchService;
import org.elasticsearch.search.fetch.FetchPhase;
import org.elasticsearch.snapshots.SnapshotShardsService;
@ -379,8 +378,7 @@ public class Node implements Closeable {
Collection<Object> pluginComponents = pluginsService.filterPlugins(Plugin.class).stream()
.flatMap(p -> p.createComponents(client, clusterService, threadPool, resourceWatcherService,
scriptModule.getScriptService(), searchModule.getSearchRequestParsers(),
xContentRegistry).stream())
scriptModule.getScriptService(), xContentRegistry).stream())
.collect(Collectors.toList());
Collection<UnaryOperator<Map<String, MetaData.Custom>>> customMetaDataUpgraders =
pluginsService.filterPlugins(Plugin.class).stream()
@ -410,7 +408,6 @@ public class Node implements Closeable {
final DiscoveryModule discoveryModule = new DiscoveryModule(this.settings, threadPool, transportService,
namedWriteableRegistry, networkService, clusterService, pluginsService.filterPlugins(DiscoveryPlugin.class));
modules.add(b -> {
b.bind(SearchRequestParsers.class).toInstance(searchModule.getSearchRequestParsers());
b.bind(NamedXContentRegistry.class).toInstance(xContentRegistry);
b.bind(PluginsService.class).toInstance(pluginsService);
b.bind(Client.class).toInstance(client);

View File

@ -42,7 +42,6 @@ import org.elasticsearch.repositories.RepositoriesModule;
import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.threadpool.ExecutorBuilder;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.watcher.ResourceWatcherService;
@ -103,11 +102,10 @@ public abstract class Plugin implements Closeable {
* @param threadPool A service to allow retrieving an executor to run an async action
* @param resourceWatcherService A service to watch for changes to node local files
* @param scriptService A service to allow running scripts on the local node
* @param searchRequestParsers Parsers for search requests which may be used to templatize search requests
*/
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool,
ResourceWatcherService resourceWatcherService, ScriptService scriptService,
SearchRequestParsers searchRequestParsers, NamedXContentRegistry xContentRegistry) {
NamedXContentRegistry xContentRegistry) {
return Collections.emptyList();
}

View File

@ -37,7 +37,6 @@ import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import java.io.IOException;
@ -53,12 +52,10 @@ import static org.elasticsearch.rest.RestRequest.Method.POST;
public class RestMultiSearchAction extends BaseRestHandler {
private final boolean allowExplicitIndex;
private final SearchRequestParsers searchRequestParsers;
@Inject
public RestMultiSearchAction(Settings settings, RestController controller, SearchRequestParsers searchRequestParsers) {
public RestMultiSearchAction(Settings settings, RestController controller) {
super(settings);
this.searchRequestParsers = searchRequestParsers;
controller.registerHandler(GET, "/_msearch", this);
controller.registerHandler(POST, "/_msearch", this);
@ -72,7 +69,7 @@ public class RestMultiSearchAction extends BaseRestHandler {
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
MultiSearchRequest multiSearchRequest = parseRequest(request, allowExplicitIndex, searchRequestParsers, parseFieldMatcher);
MultiSearchRequest multiSearchRequest = parseRequest(request, allowExplicitIndex, parseFieldMatcher);
return channel -> client.multiSearch(multiSearchRequest, new RestToXContentListener<>(channel));
}
@ -80,7 +77,6 @@ public class RestMultiSearchAction extends BaseRestHandler {
* Parses a {@link RestRequest} body and returns a {@link MultiSearchRequest}
*/
public static MultiSearchRequest parseRequest(RestRequest restRequest, boolean allowExplicitIndex,
SearchRequestParsers searchRequestParsers,
ParseFieldMatcher parseFieldMatcher) throws IOException {
MultiSearchRequest multiRequest = new MultiSearchRequest();
if (restRequest.hasParam("max_concurrent_searches")) {

View File

@ -36,7 +36,6 @@ import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestActions;
import org.elasticsearch.rest.action.RestStatusToXContentListener;
import org.elasticsearch.search.Scroll;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.fetch.StoredFieldsContext;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
@ -54,13 +53,9 @@ import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.search.suggest.SuggestBuilders.termSuggestion;
public class RestSearchAction extends BaseRestHandler {
private final SearchRequestParsers searchRequestParsers;
@Inject
public RestSearchAction(Settings settings, RestController controller, SearchRequestParsers searchRequestParsers) {
public RestSearchAction(Settings settings, RestController controller) {
super(settings);
this.searchRequestParsers = searchRequestParsers;
controller.registerHandler(GET, "/_search", this);
controller.registerHandler(POST, "/_search", this);
controller.registerHandler(GET, "/{index}/_search", this);
@ -73,7 +68,7 @@ public class RestSearchAction extends BaseRestHandler {
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
SearchRequest searchRequest = new SearchRequest();
request.withContentOrSourceParamParserOrNull(parser ->
parseSearchRequest(searchRequest, request, searchRequestParsers, parseFieldMatcher, parser));
parseSearchRequest(searchRequest, request, parseFieldMatcher, parser));
return channel -> client.search(searchRequest, new RestStatusToXContentListener<>(channel));
}
@ -84,8 +79,8 @@ public class RestSearchAction extends BaseRestHandler {
* @param requestContentParser body of the request to read. This method does not attempt to read the body from the {@code request}
* parameter
*/
public static void parseSearchRequest(SearchRequest searchRequest, RestRequest request, SearchRequestParsers searchRequestParsers,
ParseFieldMatcher parseFieldMatcher, XContentParser requestContentParser) throws IOException {
public static void parseSearchRequest(SearchRequest searchRequest, RestRequest request, ParseFieldMatcher parseFieldMatcher,
XContentParser requestContentParser) throws IOException {
if (searchRequest.source() == null) {
searchRequest.source(new SearchSourceBuilder());

View File

@ -276,7 +276,6 @@ public class SearchModule {
private final Settings settings;
private final List<NamedWriteableRegistry.Entry> namedWriteables = new ArrayList<>();
private final List<NamedXContentRegistry.Entry> namedXContents = new ArrayList<>();
private final SearchRequestParsers searchRequestParsers;
public SearchModule(Settings settings, boolean transportClient, List<SearchPlugin> plugins) {
this.settings = settings;
@ -295,7 +294,6 @@ public class SearchModule {
registerFetchSubPhases(plugins);
registerSearchExts(plugins);
registerShapes();
searchRequestParsers = new SearchRequestParsers();
}
public List<NamedWriteableRegistry.Entry> getNamedWriteables() {
@ -306,10 +304,6 @@ public class SearchModule {
return namedXContents;
}
public SearchRequestParsers getSearchRequestParsers() {
return searchRequestParsers;
}
/**
* Returns the {@link Highlighter} registry
*/

View File

@ -1,29 +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.search;
/**
* A container for all parsers used to parse
* {@link org.elasticsearch.action.search.SearchRequest} objects from a rest request.
*/
public class SearchRequestParsers {
public SearchRequestParsers() {
}
}

View File

@ -840,7 +840,7 @@ public abstract class TcpTransport<Channel> extends AbstractLifecycleComponent i
}
@Override
protected final void doClose() {
protected void doClose() {
}
@Override

View File

@ -29,7 +29,6 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.fetch.subphase.FetchSourceContext;
import org.elasticsearch.search.internal.AliasFilter;
import org.elasticsearch.test.ESTestCase;
@ -41,9 +40,8 @@ import java.util.Collections;
import java.util.List;
public class ExplainRequestTests extends ESTestCase {
private NamedWriteableRegistry namedWriteableRegistry;
protected NamedWriteableRegistry namedWriteableRegistry;
protected SearchRequestParsers searchRequestParsers;
public void setUp() throws Exception {
super.setUp();
IndicesModule indicesModule = new IndicesModule(Collections.emptyList());
@ -52,10 +50,8 @@ public class ExplainRequestTests extends ESTestCase {
entries.addAll(indicesModule.getNamedWriteables());
entries.addAll(searchModule.getNamedWriteables());
namedWriteableRegistry = new NamedWriteableRegistry(entries);
searchRequestParsers = searchModule.getSearchRequestParsers();
}
public void testSerialize() throws IOException {
try (BytesStreamOutput output = new BytesStreamOutput()) {
ExplainRequest request = new ExplainRequest("index", "type", "id");

View File

@ -31,7 +31,6 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.search.SearchModule;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.internal.AliasFilter;
import org.elasticsearch.test.ESTestCase;
@ -42,9 +41,8 @@ import java.util.Collections;
import java.util.List;
public class ShardValidateQueryRequestTests extends ESTestCase {
protected NamedWriteableRegistry namedWriteableRegistry;
protected SearchRequestParsers searchRequestParsers;
public void setUp() throws Exception {
super.setUp();
IndicesModule indicesModule = new IndicesModule(Collections.emptyList());
@ -53,10 +51,8 @@ public class ShardValidateQueryRequestTests extends ESTestCase {
entries.addAll(indicesModule.getNamedWriteables());
entries.addAll(searchModule.getNamedWriteables());
namedWriteableRegistry = new NamedWriteableRegistry(entries);
searchRequestParsers = searchModule.getSearchRequestParsers();
}
public void testSerialize() throws IOException {
try (BytesStreamOutput output = new BytesStreamOutput()) {
ValidateQueryRequest validateQueryRequest = new ValidateQueryRequest("indices");

View File

@ -30,7 +30,6 @@ import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.search.RestMultiSearchAction;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.StreamsUtils;
import org.elasticsearch.test.rest.FakeRestRequest;
@ -163,7 +162,7 @@ public class MultiSearchRequestTests extends ESTestCase {
private MultiSearchRequest parseMultiSearchRequest(String sample) throws IOException {
byte[] data = StreamsUtils.copyToBytesFromClasspath(sample);
RestRequest restRequest = new FakeRestRequest.Builder(xContentRegistry()).withContent(new BytesArray(data)).build();
return RestMultiSearchAction.parseRequest(restRequest, true, new SearchRequestParsers(), ParseFieldMatcher.EMPTY);
return RestMultiSearchAction.parseRequest(restRequest, true, ParseFieldMatcher.EMPTY);
}
@Override

View File

@ -53,7 +53,6 @@ import java.util.function.Supplier;
public abstract class AbstractSearchTestCase extends ESTestCase {
protected NamedWriteableRegistry namedWriteableRegistry;
protected SearchRequestParsers searchRequestParsers;
private TestSearchExtPlugin searchExtPlugin;
private NamedXContentRegistry xContentRegistry;
@ -67,7 +66,6 @@ public abstract class AbstractSearchTestCase extends ESTestCase {
entries.addAll(searchModule.getNamedWriteables());
namedWriteableRegistry = new NamedWriteableRegistry(entries);
xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
searchRequestParsers = searchModule.getSearchRequestParsers();
}
@Override

View File

@ -36,7 +36,6 @@ import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestStatusToXContentListener;
import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.search.SearchRequestParsers;
import java.io.IOException;
@ -75,12 +74,9 @@ public class RestSearchTemplateAction extends BaseRestHandler {
}, new ParseField("inline", "template"), ObjectParser.ValueType.OBJECT_OR_STRING);
}
private final SearchRequestParsers searchRequestParsers;
@Inject
public RestSearchTemplateAction(Settings settings, RestController controller, SearchRequestParsers searchRequestParsers) {
public RestSearchTemplateAction(Settings settings, RestController controller) {
super(settings);
this.searchRequestParsers = searchRequestParsers;
controller.registerHandler(GET, "/_search/template", this);
controller.registerHandler(POST, "/_search/template", this);
@ -98,7 +94,7 @@ public class RestSearchTemplateAction extends BaseRestHandler {
// Creates the search request with all required params
SearchRequest searchRequest = new SearchRequest();
RestSearchAction.parseSearchRequest(searchRequest, request, searchRequestParsers, parseFieldMatcher, null);
RestSearchAction.parseSearchRequest(searchRequest, request, parseFieldMatcher, null);
// Creates the search template request
SearchTemplateRequest searchTemplateRequest;

View File

@ -36,7 +36,6 @@ import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
@ -51,19 +50,17 @@ public class TransportSearchTemplateAction extends HandledTransportAction<Search
private final ScriptService scriptService;
private final TransportSearchAction searchAction;
private final SearchRequestParsers searchRequestParsers;
private final NamedXContentRegistry xContentRegistry;
@Inject
public TransportSearchTemplateAction(Settings settings, ThreadPool threadPool, TransportService transportService,
ActionFilters actionFilters, IndexNameExpressionResolver resolver,
ScriptService scriptService,
TransportSearchAction searchAction, SearchRequestParsers searchRequestParsers,
TransportSearchAction searchAction,
NamedXContentRegistry xContentRegistry) {
super(settings, SearchTemplateAction.NAME, threadPool, transportService, actionFilters, resolver, SearchTemplateRequest::new);
this.scriptService = scriptService;
this.searchAction = searchAction;
this.searchRequestParsers = searchRequestParsers;
this.xContentRegistry = xContentRegistry;
}

View File

@ -29,7 +29,6 @@ import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.tasks.LoggingTaskListener;
import org.elasticsearch.tasks.Task;
@ -42,12 +41,10 @@ public abstract class AbstractBaseReindexRestHandler<
A extends GenericAction<Request, BulkIndexByScrollResponse>
> extends BaseRestHandler {
protected final SearchRequestParsers searchRequestParsers;
private final A action;
protected AbstractBaseReindexRestHandler(Settings settings, SearchRequestParsers searchRequestParsers, A action) {
protected AbstractBaseReindexRestHandler(Settings settings, A action) {
super(settings);
this.searchRequestParsers = searchRequestParsers;
this.action = action;
}

View File

@ -28,7 +28,6 @@ import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.search.SearchRequestParsers;
import java.io.IOException;
import java.util.Map;
@ -43,8 +42,8 @@ public abstract class AbstractBulkByQueryRestHandler<
Request extends AbstractBulkByScrollRequest<Request>,
A extends GenericAction<Request, BulkIndexByScrollResponse>> extends AbstractBaseReindexRestHandler<Request, A> {
protected AbstractBulkByQueryRestHandler(Settings settings, SearchRequestParsers searchRequestParsers, A action) {
super(settings, searchRequestParsers, action);
protected AbstractBulkByQueryRestHandler(Settings settings, A action) {
super(settings, action);
}
protected void parseInternalRequest(Request internal, RestRequest restRequest,
@ -63,8 +62,7 @@ public abstract class AbstractBulkByQueryRestHandler<
* the generated parser probably is a noop but we should do the accounting just in case. It doesn't hurt to close twice but it
* really hurts not to close if by some miracle we have to. */
try {
RestSearchAction.parseSearchRequest(searchRequest, restRequest, searchRequestParsers, parseFieldMatcher,
searchRequestParser);
RestSearchAction.parseSearchRequest(searchRequest, restRequest, parseFieldMatcher, searchRequestParser);
} finally {
IOUtils.close(searchRequestParser);
}

View File

@ -26,7 +26,6 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.search.SearchRequestParsers;
import java.io.IOException;
import java.util.HashMap;
@ -38,8 +37,8 @@ import static org.elasticsearch.rest.RestRequest.Method.POST;
public class RestDeleteByQueryAction extends AbstractBulkByQueryRestHandler<DeleteByQueryRequest, DeleteByQueryAction> {
@Inject
public RestDeleteByQueryAction(Settings settings, RestController controller, SearchRequestParsers searchRequestParsers) {
super(settings, searchRequestParsers, DeleteByQueryAction.INSTANCE);
public RestDeleteByQueryAction(Settings settings, RestController controller) {
super(settings, DeleteByQueryAction.INSTANCE);
controller.registerHandler(POST, "/{index}/_delete_by_query", this);
controller.registerHandler(POST, "/{index}/{type}/_delete_by_query", this);
}

View File

@ -24,7 +24,6 @@ import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.ParseFieldMatcherSupplier;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.inject.Inject;
@ -43,7 +42,6 @@ import org.elasticsearch.index.reindex.remote.RemoteInfo;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.script.Script;
import org.elasticsearch.search.SearchRequestParsers;
import java.io.IOException;
import java.util.List;
@ -61,11 +59,11 @@ import static org.elasticsearch.rest.RestRequest.Method.POST;
* Expose reindex over rest.
*/
public class RestReindexAction extends AbstractBaseReindexRestHandler<ReindexRequest, ReindexAction> {
static final ObjectParser<ReindexRequest, ReindexParseContext> PARSER = new ObjectParser<>("reindex");
static final ObjectParser<ReindexRequest, Void> PARSER = new ObjectParser<>("reindex");
private static final Pattern HOST_PATTERN = Pattern.compile("(?<scheme>[^:]+)://(?<host>[^:]+):(?<port>\\d+)");
static {
ObjectParser.Parser<ReindexRequest, ReindexParseContext> sourceParser = (parser, request, context) -> {
ObjectParser.Parser<ReindexRequest, Void> sourceParser = (parser, request, context) -> {
// Funky hack to work around Search not having a proper ObjectParser and us wanting to extract query if using remote.
Map<String, Object> source = parser.map();
String[] indices = extractStringArray(source, "index");
@ -80,11 +78,11 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler<ReindexReq
XContentBuilder builder = XContentFactory.contentBuilder(parser.contentType());
builder.map(source);
try (XContentParser innerParser = parser.contentType().xContent().createParser(parser.getXContentRegistry(), builder.bytes())) {
request.getSearchRequest().source().parseXContent(context.queryParseContext(innerParser));
request.getSearchRequest().source().parseXContent(new QueryParseContext(innerParser, ParseFieldMatcher.EMPTY));
}
};
ObjectParser<IndexRequest, ParseFieldMatcherSupplier> destParser = new ObjectParser<>("dest");
ObjectParser<IndexRequest, Void> destParser = new ObjectParser<>("dest");
destParser.declareString(IndexRequest::index, new ParseField("index"));
destParser.declareString(IndexRequest::type, new ParseField("type"));
destParser.declareString(IndexRequest::routing, new ParseField("routing"));
@ -101,8 +99,8 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler<ReindexReq
}
@Inject
public RestReindexAction(Settings settings, RestController controller, SearchRequestParsers searchRequestParsers) {
super(settings, searchRequestParsers, ReindexAction.INSTANCE);
public RestReindexAction(Settings settings, RestController controller) {
super(settings, ReindexAction.INSTANCE);
controller.registerHandler(POST, "/_reindex", this);
}
@ -119,7 +117,7 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler<ReindexReq
}
ReindexRequest internal = new ReindexRequest(new SearchRequest(), new IndexRequest());
try (XContentParser parser = request.contentParser()) {
PARSER.parse(parser, internal, new ReindexParseContext(searchRequestParsers, parseFieldMatcher));
PARSER.parse(parser, internal, null);
}
return internal;
}
@ -218,23 +216,4 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler<ReindexReq
Map<String, Object> map = (Map<String, Object>) query;
return builder.map(map).bytes();
}
static class ReindexParseContext implements ParseFieldMatcherSupplier {
private final SearchRequestParsers searchRequestParsers;
private final ParseFieldMatcher parseFieldMatcher;
ReindexParseContext(SearchRequestParsers searchRequestParsers, ParseFieldMatcher parseFieldMatcher) {
this.searchRequestParsers = searchRequestParsers;
this.parseFieldMatcher = parseFieldMatcher;
}
QueryParseContext queryParseContext(XContentParser parser) {
return new QueryParseContext(parser, parseFieldMatcher);
}
@Override
public ParseFieldMatcher getParseFieldMatcher() {
return this.parseFieldMatcher;
}
}
}

View File

@ -29,7 +29,6 @@ import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.search.SearchRequestParsers;
import java.io.IOException;
import java.util.Collections;
@ -44,8 +43,8 @@ import static org.elasticsearch.script.Script.DEFAULT_SCRIPT_LANG;
public class RestUpdateByQueryAction extends AbstractBulkByQueryRestHandler<UpdateByQueryRequest, UpdateByQueryAction> {
@Inject
public RestUpdateByQueryAction(Settings settings, RestController controller, SearchRequestParsers searchRequestParsers) {
super(settings, searchRequestParsers, UpdateByQueryAction.INSTANCE);
public RestUpdateByQueryAction(Settings settings, RestController controller) {
super(settings, UpdateByQueryAction.INSTANCE);
controller.registerHandler(POST, "/{index}/_update_by_query", this);
controller.registerHandler(POST, "/{index}/{type}/_update_by_query", this);
}

View File

@ -21,16 +21,13 @@ package org.elasticsearch.index.reindex;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.index.reindex.RestReindexAction.ReindexParseContext;
import org.elasticsearch.index.reindex.remote.RemoteInfo;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.test.rest.FakeRestRequest;
@ -124,16 +121,14 @@ public class RestReindexActionTests extends ESTestCase {
}
try (XContentParser p = createParser(JsonXContent.jsonXContent, request)) {
ReindexRequest r = new ReindexRequest(new SearchRequest(), new IndexRequest());
SearchRequestParsers searchParsers = new SearchRequestParsers();
RestReindexAction.PARSER.parse(p, r, new ReindexParseContext(searchParsers, ParseFieldMatcher.STRICT));
RestReindexAction.PARSER.parse(p, r, null);
assertEquals("localhost", r.getRemoteInfo().getHost());
assertArrayEquals(new String[] {"source"}, r.getSearchRequest().indices());
}
}
public void testPipelineQueryParameterIsError() throws IOException {
SearchRequestParsers parsers = new SearchRequestParsers();
RestReindexAction action = new RestReindexAction(Settings.EMPTY, mock(RestController.class), parsers);
RestReindexAction action = new RestReindexAction(Settings.EMPTY, mock(RestController.class));
FakeRestRequest.Builder request = new FakeRestRequest.Builder(xContentRegistry());
try (XContentBuilder body = JsonXContent.contentBuilder().prettyPrint()) {

View File

@ -35,7 +35,6 @@ import org.elasticsearch.env.Environment;
import org.elasticsearch.plugins.DiscoveryPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.search.SearchRequestParsers;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.TransportService;
import org.elasticsearch.watcher.ResourceWatcherService;
@ -73,7 +72,6 @@ public class FileBasedDiscoveryPlugin extends Plugin implements DiscoveryPlugin
ThreadPool threadPool,
ResourceWatcherService resourceWatcherService,
ScriptService scriptService,
SearchRequestParsers searchRequestParsers,
NamedXContentRegistry xContentRegistry) {
final int concurrentConnects = UnicastZenPing.DISCOVERY_ZEN_PING_UNICAST_CONCURRENT_CONNECTS_SETTING.get(settings);
final ThreadFactory threadFactory = EsExecutors.daemonThreadFactory(settings, "[file_based_discovery_resolve]");

View File

@ -49,6 +49,8 @@ import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -74,6 +76,8 @@ public class MockTcpTransport extends TcpTransport<MockTcpTransport.MockChannel>
*/
public static final ConnectionProfile LIGHT_PROFILE;
private final Map<MockChannel, Boolean> openChannels = new IdentityHashMap<>();
static {
ConnectionProfile.Builder builder = new ConnectionProfile.Builder();
builder.addConnections(1,
@ -284,6 +288,9 @@ public class MockTcpTransport extends TcpTransport<MockTcpTransport.MockChannel>
this.serverSocket = null;
this.profile = profile;
this.onClose = () -> onClose.accept(this);
synchronized (openChannels) {
openChannels.put(this, Boolean.TRUE);
}
}
/**
@ -353,12 +360,17 @@ public class MockTcpTransport extends TcpTransport<MockTcpTransport.MockChannel>
@Override
public void close() throws IOException {
if (isOpen.compareAndSet(true, false)) {
final Boolean removedChannel;
synchronized (openChannels) {
removedChannel = openChannels.remove(this);
}
//establish a happens-before edge between closing and accepting a new connection
synchronized (this) {
onChannelClosed(this);
IOUtils.close(serverSocket, activeChannel, () -> IOUtils.close(workerChannels.keySet()),
() -> cancellableThreads.cancel("channel closed"), onClose);
}
assert removedChannel : "Channel was not removed or removed twice?";
}
}
}
@ -395,5 +407,16 @@ public class MockTcpTransport extends TcpTransport<MockTcpTransport.MockChannel>
return mockVersion;
}
@Override
protected void doClose() {
if (Thread.currentThread().isInterrupted() == false) {
// TCPTransport might be interrupted due to a timeout waiting for connections to be closed.
// in this case the thread is interrupted and we can't tell if we really missed something or if we are
// still closing connections. in such a case we don't assert the open channels
synchronized (openChannels) {
assert openChannels.isEmpty() : "there are still open channels: " + openChannels;
}
}
}
}