From ac8c1722acd627a22f9513bf5bf8ef8760059a4e Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Wed, 23 Sep 2015 11:07:20 +0100 Subject: [PATCH] fix compile errors --- .../warmer/put/RestPutWarmerAction.java | 3 +- .../rest/action/search/RestSearchAction.java | 11 ++-- .../search/builder/SearchSourceBuilder.java | 51 +++++++++---------- .../fetch/source/FetchSourceContext.java | 19 ++++--- 4 files changed, 39 insertions(+), 45 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/warmer/put/RestPutWarmerAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/warmer/put/RestPutWarmerAction.java index 198c3204ee4..c50cf18b906 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/warmer/put/RestPutWarmerAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/warmer/put/RestPutWarmerAction.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.Index; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.rest.BaseRestHandler; @@ -77,7 +76,7 @@ public class RestPutWarmerAction extends BaseRestHandler { BytesReference sourceBytes = RestActions.getRestContent(request); XContentParser parser = XContentFactory.xContent(sourceBytes).createParser(sourceBytes); - QueryParseContext queryParseContext = new QueryParseContext(new Index(""), queryRegistry); // NORELEASE remove index + QueryParseContext queryParseContext = new QueryParseContext(queryRegistry); queryParseContext.reset(parser); SearchSourceBuilder source = SearchSourceBuilder.PROTOTYPE.fromXContent(parser, queryParseContext); SearchRequest searchRequest = new SearchRequest(Strings.splitStringByCommaToArray(request.param("index"))) diff --git a/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 3c90d54f5f3..093db18b9fd 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.Index; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.indices.query.IndicesQueriesRegistry; @@ -106,11 +105,11 @@ public class RestSearchAction extends BaseRestHandler { if (isTemplateRequest) { searchRequest.templateSource(RestActions.getRestContent(request)); } else { - BytesReference sourceBytes = RestActions.getRestContent(request); - XContentParser parser = XContentFactory.xContent(sourceBytes).createParser(sourceBytes); - QueryParseContext queryParseContext = new QueryParseContext(new Index(""), queryRegistry); // NORELEASE remove index - queryParseContext.reset(parser); - searchRequest.source(SearchSourceBuilder.PROTOTYPE.fromXContent(parser, queryParseContext)); + BytesReference sourceBytes = RestActions.getRestContent(request); + XContentParser parser = XContentFactory.xContent(sourceBytes).createParser(sourceBytes); + QueryParseContext queryParseContext = new QueryParseContext(queryRegistry); + queryParseContext.reset(parser); + searchRequest.source(SearchSourceBuilder.PROTOTYPE.fromXContent(parser, queryParseContext)); } } diff --git a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java index 9b01564dd27..d2040c2b89e 100644 --- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -687,8 +687,8 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ XContentParser.Token token; String currentFieldName = null; if ((token = parser.nextToken()) != XContentParser.Token.START_OBJECT) { - throw new ParsingException(context, "Expected [" + XContentParser.Token.START_OBJECT + "] but found [" + token + "]", - parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Expected [" + XContentParser.Token.START_OBJECT + "] but found [" + + token + "]"); } while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { @@ -718,8 +718,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ fieldNames.add(parser.text()); builder.fieldNames = fieldNames; } else { - throw new ParsingException(context, "Unknown key for a " + token + " in [" + currentFieldName + "].", - parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_OBJECT) { if (context.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) { @@ -743,24 +742,25 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ scriptFields .add(new ScriptField(scriptFieldName, Script.parse(parser, context.parseFieldMatcher()))); } else { - throw new ParsingException(context, "Unknown key for a " + token + " in [" + currentFieldName - + "].", parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_OBJECT) { if (context.parseFieldMatcher().match(currentFieldName, SCRIPT_FIELD)) { scriptFields .add(new ScriptField(scriptFieldName, Script.parse(parser, context.parseFieldMatcher()))); } else { - throw new ParsingException(context, "Unknown key for a " + token + " in [" + currentFieldName - + "].", parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + + currentFieldName + "]."); } } else { - throw new ParsingException(context, "Unknown key for a " + token + " in [" + currentFieldName - + "].", parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + + currentFieldName + "]."); } } } else { - throw new ParsingException(context, "Expected [" + XContentParser.Token.START_OBJECT + "] in [" + throw new ParsingException(parser.getTokenLocation(), "Expected [" + XContentParser.Token.START_OBJECT + + "] in [" + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); } } @@ -773,8 +773,8 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ } else if (token.isValue()) { indexBoost.put(currentFieldName, parser.floatValue()); } else { - throw new ParsingException(context, "Unknown key for a " + token + " in [" + currentFieldName + "].", - parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + + "]."); } } builder.indexBoost = indexBoost; @@ -791,8 +791,8 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ xContentBuilder.endObject(); aggregations.add(xContentBuilder.bytes()); } else { - throw new ParsingException(context, "Unknown key for a " + token + " in [" + currentFieldName + "].", - parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + + "]."); } } builder.aggregations = aggregations; @@ -806,8 +806,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ XContentBuilder xContentBuilder = XContentFactory.contentBuilder(parser.contentType()).copyCurrentStructure(parser); builder.suggestBuilder = xContentBuilder.bytes(); } else { - throw new ParsingException(context, "Unknown key for a " + token + " in [" + currentFieldName + "].", - parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_ARRAY) { if (context.parseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) { @@ -816,8 +815,8 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ if (token == XContentParser.Token.VALUE_STRING) { fieldNames.add(parser.text()); } else { - throw new ParsingException(context, "Expected [" + XContentParser.Token.VALUE_STRING + "] in [" - + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Expected [" + XContentParser.Token.VALUE_STRING + + "] in [" + currentFieldName + "] but found [" + token + "]"); } } builder.fieldNames = fieldNames; @@ -827,8 +826,8 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ if (token == XContentParser.Token.VALUE_STRING) { fieldDataFields.add(parser.text()); } else { - throw new ParsingException(context, "Expected [" + XContentParser.Token.VALUE_STRING + "] in [" - + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Expected [" + XContentParser.Token.VALUE_STRING + + "] in [" + currentFieldName + "] but found [" + token + "]"); } } builder.fieldDataFields = fieldDataFields; @@ -852,18 +851,16 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ if (token == XContentParser.Token.VALUE_STRING) { stats.add(parser.text()); } else { - throw new ParsingException(context, "Expected [" + XContentParser.Token.VALUE_STRING + "] in [" - + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Expected [" + XContentParser.Token.VALUE_STRING + + "] in [" + currentFieldName + "] but found [" + token + "]"); } } builder.stats = stats.toArray(new String[stats.size()]); } else { - throw new ParsingException(context, "Unknown key for a " + token + " in [" + currentFieldName + "].", - parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "]."); } } else { - throw new ParsingException(context, "Unknown key for a " + token + " in [" + currentFieldName + "].", - parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "]."); } } return builder; diff --git a/core/src/main/java/org/elasticsearch/search/fetch/source/FetchSourceContext.java b/core/src/main/java/org/elasticsearch/search/fetch/source/FetchSourceContext.java index 2f4493aba89..27ec93e7b08 100644 --- a/core/src/main/java/org/elasticsearch/search/fetch/source/FetchSourceContext.java +++ b/core/src/main/java/org/elasticsearch/search/fetch/source/FetchSourceContext.java @@ -206,8 +206,8 @@ public class FetchSourceContext implements Streamable, ToXContent { if (token == XContentParser.Token.VALUE_STRING) { includesList.add(parser.text()); } else { - throw new ParsingException(context, "Unknown key for a " + token + " in [" + currentFieldName + "].", - parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + + currentFieldName + "]."); } } includes = includesList.toArray(new String[includesList.size()]); @@ -217,23 +217,22 @@ public class FetchSourceContext implements Streamable, ToXContent { if (token == XContentParser.Token.VALUE_STRING) { excludesList.add(parser.text()); } else { - throw new ParsingException(context, "Unknown key for a " + token + " in [" + currentFieldName + "].", - parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + + currentFieldName + "]."); } } excludes = excludesList.toArray(new String[excludesList.size()]); } else { - throw new ParsingException(context, "Unknown key for a " + token + " in [" + currentFieldName + "].", - parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + + "]."); } } else { - throw new ParsingException(context, "Unknown key for a " + token + " in [" + currentFieldName + "].", - parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "]."); } } } else { - throw new ParsingException(context, "Expected one of [" + XContentParser.Token.VALUE_BOOLEAN + ", " - + XContentParser.Token.START_OBJECT + "] but found [" + token + "]", parser.getTokenLocation()); + throw new ParsingException(parser.getTokenLocation(), "Expected one of [" + XContentParser.Token.VALUE_BOOLEAN + ", " + + XContentParser.Token.START_OBJECT + "] but found [" + token + "]"); } this.fetchSource = fetchSource; this.includes = includes;