Remove ParseFieldMatcher usages from a couple of Rest Actions

This commit is contained in:
javanna 2016-12-31 12:19:36 +01:00 committed by Luca Cavanna
parent 0d67891a64
commit 77f4152a18
3 changed files with 12 additions and 16 deletions

View File

@ -21,7 +21,6 @@ package org.elasticsearch.rest.action.admin.indices;
import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
@ -65,7 +64,7 @@ public class RestAnalyzeAction extends BaseRestHandler {
AnalyzeRequest analyzeRequest = new AnalyzeRequest(request.param("index"));
try (XContentParser parser = request.contentOrSourceParamParser()) {
buildFromContent(parser, analyzeRequest, parseFieldMatcher);
buildFromContent(parser, analyzeRequest);
} catch (IOException e) {
throw new IllegalArgumentException("Failed to parse request body", e);
}
@ -73,7 +72,7 @@ public class RestAnalyzeAction extends BaseRestHandler {
return channel -> client.admin().indices().analyze(analyzeRequest, new RestToXContentListener<>(channel));
}
static void buildFromContent(XContentParser parser, AnalyzeRequest analyzeRequest, ParseFieldMatcher parseFieldMatcher)
static void buildFromContent(XContentParser parser, AnalyzeRequest analyzeRequest)
throws IOException {
if (parser.nextToken() != XContentParser.Token.START_OBJECT) {
throw new IllegalArgumentException("Malformed content, must start with an object");

View File

@ -24,7 +24,6 @@ import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRespo
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
@ -61,7 +60,7 @@ public class RestClearIndicesCacheAction extends BaseRestHandler {
ClearIndicesCacheRequest clearIndicesCacheRequest = new ClearIndicesCacheRequest(
Strings.splitStringByCommaToArray(request.param("index")));
clearIndicesCacheRequest.indicesOptions(IndicesOptions.fromRequest(request, clearIndicesCacheRequest.indicesOptions()));
fromRequest(request, clearIndicesCacheRequest, parseFieldMatcher);
fromRequest(request, clearIndicesCacheRequest);
return channel ->
client.admin().indices().clearCache(clearIndicesCacheRequest, new RestBuilderListener<ClearIndicesCacheResponse>(channel) {
@Override
@ -79,8 +78,7 @@ public class RestClearIndicesCacheAction extends BaseRestHandler {
return false;
}
public static ClearIndicesCacheRequest fromRequest(final RestRequest request, ClearIndicesCacheRequest clearIndicesCacheRequest,
ParseFieldMatcher parseFieldMatcher) {
public static ClearIndicesCacheRequest fromRequest(final RestRequest request, ClearIndicesCacheRequest clearIndicesCacheRequest) {
for (Map.Entry<String, String> entry : request.params().entrySet()) {
if (Fields.QUERY.match(entry.getKey())) {

View File

@ -19,7 +19,6 @@
package org.elasticsearch.rest.action.admin.indices;
import org.elasticsearch.action.admin.indices.analyze.AnalyzeRequest;
import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentFactory;
@ -46,7 +45,7 @@ public class RestAnalyzeActionTests extends ESTestCase {
AnalyzeRequest analyzeRequest = new AnalyzeRequest("for test");
RestAnalyzeAction.buildFromContent(content, analyzeRequest, new ParseFieldMatcher(Settings.EMPTY));
RestAnalyzeAction.buildFromContent(content, analyzeRequest);
assertThat(analyzeRequest.text().length, equalTo(1));
assertThat(analyzeRequest.text(), equalTo(new String[]{"THIS IS A TEST"}));
@ -79,7 +78,7 @@ public class RestAnalyzeActionTests extends ESTestCase {
AnalyzeRequest analyzeRequest = new AnalyzeRequest("for test");
RestAnalyzeAction.buildFromContent(content, analyzeRequest, new ParseFieldMatcher(Settings.EMPTY));
RestAnalyzeAction.buildFromContent(content, analyzeRequest);
assertThat(analyzeRequest.text().length, equalTo(1));
assertThat(analyzeRequest.text(), equalTo(new String[]{"THIS IS A TEST"}));
@ -106,7 +105,7 @@ public class RestAnalyzeActionTests extends ESTestCase {
.field("unknown", "keyword")
.endObject());
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> RestAnalyzeAction.buildFromContent(invalidContent, analyzeRequest, new ParseFieldMatcher(Settings.EMPTY)));
() -> RestAnalyzeAction.buildFromContent(invalidContent, analyzeRequest));
assertThat(e.getMessage(), startsWith("Unknown parameter [unknown]"));
}
@ -117,7 +116,7 @@ public class RestAnalyzeActionTests extends ESTestCase {
.field("explain", "fals")
.endObject());
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
() -> RestAnalyzeAction.buildFromContent(invalidExplain, analyzeRequest, new ParseFieldMatcher(Settings.EMPTY)));
() -> RestAnalyzeAction.buildFromContent(invalidExplain, analyzeRequest));
assertThat(e.getMessage(), startsWith("explain must be either 'true' or 'false'"));
}
@ -130,7 +129,7 @@ public class RestAnalyzeActionTests extends ESTestCase {
.array("filters", "lowercase")
.endObject());
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> RestAnalyzeAction.buildFromContent(parser,
new AnalyzeRequest("for test"), new ParseFieldMatcher(Settings.EMPTY)));
new AnalyzeRequest("for test")));
assertThat(e.getMessage(), startsWith("Unknown parameter [filters]"));
}
@ -142,7 +141,7 @@ public class RestAnalyzeActionTests extends ESTestCase {
.array("token_filters", "lowercase")
.endObject());
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> RestAnalyzeAction.buildFromContent(parser,
new AnalyzeRequest("for test"), new ParseFieldMatcher(Settings.EMPTY)));
new AnalyzeRequest("for test")));
assertThat(e.getMessage(), startsWith("Unknown parameter [token_filters]"));
}
@ -154,7 +153,7 @@ public class RestAnalyzeActionTests extends ESTestCase {
.array("char_filters", "lowercase")
.endObject());
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> RestAnalyzeAction.buildFromContent(parser,
new AnalyzeRequest("for test"), new ParseFieldMatcher(Settings.EMPTY)));
new AnalyzeRequest("for test")));
assertThat(e.getMessage(), startsWith("Unknown parameter [char_filters]"));
}
@ -166,7 +165,7 @@ public class RestAnalyzeActionTests extends ESTestCase {
.array("token_filter", "lowercase")
.endObject());
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> RestAnalyzeAction.buildFromContent(parser,
new AnalyzeRequest("for test"), new ParseFieldMatcher(Settings.EMPTY)));
new AnalyzeRequest("for test")));
assertThat(e.getMessage(), startsWith("Unknown parameter [token_filter]"));
}
}