From bd17ee8c56d45c4b54c4ff25d53fa298825d4623 Mon Sep 17 00:00:00 2001 From: Michael Stockerl Date: Sun, 20 Mar 2016 19:12:05 +0100 Subject: [PATCH 001/561] Get TermVectorResponses for like and unlike items in separate requests, so we don't have to validate responses afterwards. Relates to #14944 --- .../index/query/MoreLikeThisQueryBuilder.java | 27 ++++++------------- .../search/morelikethis/MoreLikeThisIT.java | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java index 9f6c8b24c4f..fcda9ae3a8e 100644 --- a/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java @@ -861,14 +861,14 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder 0) { - org.apache.lucene.index.Fields[] unlikeFields = getFieldsFor(responses, unlikeItems); + MultiTermVectorsResponse unlikeItemsResponse = fetchResponse(context.getClient(), unlikeItems); + org.apache.lucene.index.Fields[] unlikeFields = getFieldsFor(unlikeItemsResponse); if (unlikeFields.length > 0) { mltQuery.setUnlikeText(unlikeFields); } @@ -907,30 +907,19 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder likeFields = new ArrayList<>(); - Set selectedItems = new HashSet<>(); - for (Item request : items) { - selectedItems.add(new Item(request.index(), request.type(), request.id())); - } - for (MultiTermVectorsItemResponse response : responses) { - if (!hasResponseFromRequest(response, selectedItems)) { - continue; - } if (response.isFailed()) { continue; } diff --git a/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java b/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java index 651982106c5..9f06f625582 100644 --- a/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java +++ b/core/src/test/java/org/elasticsearch/search/morelikethis/MoreLikeThisIT.java @@ -145,6 +145,32 @@ public class MoreLikeThisIT extends ESIntegTestCase { assertThat(response.getHits().getAt(0).id(), equalTo("3")); } + // Issue #14944 + public void testMoreLikeThisWithAliasesInLikeDocuments() throws Exception { + String indexName = "foo"; + String aliasName = "foo_name"; + String typeName = "bar"; + + String mapping = XContentFactory.jsonBuilder().startObject().startObject("bar") + .startObject("properties") + .endObject() + .endObject().endObject().string(); + client().admin().indices().prepareCreate(indexName).addMapping(typeName, mapping).execute().actionGet(); + client().admin().indices().aliases(indexAliasesRequest().addAlias(aliasName, indexName)).actionGet(); + + assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN)); + + client().index(indexRequest(indexName).type(typeName).id("1").source(jsonBuilder().startObject().field("text", "elasticsearch index").endObject())).actionGet(); + client().index(indexRequest(indexName).type(typeName).id("2").source(jsonBuilder().startObject().field("text", "lucene index").endObject())).actionGet(); + client().index(indexRequest(indexName).type(typeName).id("3").source(jsonBuilder().startObject().field("text", "elasticsearch index").endObject())).actionGet(); + refresh(indexName); + + SearchResponse response = client().prepareSearch().setQuery( + new MoreLikeThisQueryBuilder(null, new Item[] {new Item(aliasName, typeName, "1")}).minTermFreq(1).minDocFreq(1)).get(); + assertHitCount(response, 2L); + assertThat(response.getHits().getAt(0).id(), equalTo("3")); + } + public void testMoreLikeThisIssue2197() throws Exception { Client client = client(); String mapping = XContentFactory.jsonBuilder().startObject().startObject("bar") @@ -564,6 +590,7 @@ public class MoreLikeThisIT extends ESIntegTestCase { .maxQueryTerms(100) .include(true) .minimumShouldMatch("0%"); + response = client().prepareSearch("test").setTypes("type1").setQuery(mltQuery).get(); assertSearchResponse(response); assertHitCount(response, numFields - (i + 1)); From c6b1beb083bf62ce0ebf14e9547382387e64cc87 Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 8 Apr 2016 10:07:21 +0200 Subject: [PATCH 002/561] Add a test for forced values in mapper-attachments plugin This PR just adds a new test where we check that we forcing a value in the JSON document actually works as expected: ```json { "file": { "_content": "BASE64" "_name": "12-240.pdf", "_language": "en", "_content_type": "pdf" } } ``` Note that we don't support forcing all values. So sending: ```json { "file": { "_content": "BASE64" "_name": "12-240.pdf", "_title": "12-240.pdf", "_keywords": "Div42 Src580 LGE Mechtech", "_language": "en", "_content_type": "pdf" } } ``` Will have absolutely no effect on fields `title` and `keywords`. Note that when `_language` is set, it only works if `index.mapping.attachment.detect_language` is set to `true`. Related to https://discuss.elastic.co/t/mapper-attachments/46615/4 --- .../MultifieldAttachmentMapperTests.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MultifieldAttachmentMapperTests.java b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MultifieldAttachmentMapperTests.java index 6b781a6f4a6..5459bc6aef8 100644 --- a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MultifieldAttachmentMapperTests.java +++ b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/MultifieldAttachmentMapperTests.java @@ -153,4 +153,45 @@ public class MultifieldAttachmentMapperTests extends AttachmentUnitTestCase { // In mapping we set store:true for suggest subfield assertThat(doc.rootDoc().getField("file.name.suggest").fieldType().stored(), is(true)); } + + public void testAllExternalValues() throws Exception { + String originalText = "This is an elasticsearch mapper attachment test."; + String forcedName = randomAsciiOfLength(20); + String forcedLanguage = randomAsciiOfLength(20); + String forcedContentType = randomAsciiOfLength(20); + + String bytes = Base64.encodeBytes(originalText.getBytes(StandardCharsets.ISO_8859_1)); + threadPool = new ThreadPool("testing-only"); + + MapperService mapperService = MapperTestUtils.newMapperService(createTempDir(), + Settings.builder().put(AttachmentMapper.INDEX_ATTACHMENT_DETECT_LANGUAGE_SETTING.getKey(), true).build(), + getIndicesModuleWithRegisteredAttachmentMapper()); + + String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/attachment/test/unit/multifield/multifield-mapping.json"); + + DocumentMapper documentMapper = mapperService.documentMapperParser().parse("person", new CompressedXContent(mapping)); + + ParsedDocument doc = documentMapper.parse("person", "person", "1", XContentFactory.jsonBuilder() + .startObject() + .startObject("file") + .field("_content", bytes) + .field("_name", forcedName) + .field("_language", forcedLanguage) + .field("_content_type", forcedContentType) + .endObject() + .endObject() + .bytes()); + + // Note that we don't support forcing values for _title and _keywords + + assertThat(doc.rootDoc().getField("file.content"), notNullValue()); + assertThat(doc.rootDoc().getField("file.content").stringValue(), is(originalText + "\n")); + + assertThat(doc.rootDoc().getField("file.name"), notNullValue()); + assertThat(doc.rootDoc().getField("file.name").stringValue(), is(forcedName)); + assertThat(doc.rootDoc().getField("file.language"), notNullValue()); + assertThat(doc.rootDoc().getField("file.language").stringValue(), is(forcedLanguage)); + assertThat(doc.rootDoc().getField("file.content_type"), notNullValue()); + assertThat(doc.rootDoc().getField("file.content_type").stringValue(), is(forcedContentType)); + } } From f7a63a5e651304e0b2f317110ba18a2e643b4d0a Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Mon, 11 Apr 2016 13:33:06 -0700 Subject: [PATCH 003/561] Plugin cli: Add verbose output with zip url when installing plugin closes #17529 --- .../elasticsearch/plugins/InstallPluginCommand.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java b/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java index 4afe6b57e7e..3db532b84c8 100644 --- a/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java +++ b/core/src/main/java/org/elasticsearch/plugins/InstallPluginCommand.java @@ -197,7 +197,7 @@ class InstallPluginCommand extends Command { version); } terminal.println("-> Downloading " + pluginId + " from elastic"); - return downloadZipAndChecksum(url, tmpDir); + return downloadZipAndChecksum(terminal, url, tmpDir); } // now try as maven coordinates, a valid URL would only have a colon and slash @@ -206,16 +206,17 @@ class InstallPluginCommand extends Command { String mavenUrl = String.format(Locale.ROOT, "https://repo1.maven.org/maven2/%1$s/%2$s/%3$s/%2$s-%3$s.zip", coordinates[0].replace(".", "/") /* groupId */, coordinates[1] /* artifactId */, coordinates[2] /* version */); terminal.println("-> Downloading " + pluginId + " from maven central"); - return downloadZipAndChecksum(mavenUrl, tmpDir); + return downloadZipAndChecksum(terminal, mavenUrl, tmpDir); } // fall back to plain old URL terminal.println("-> Downloading " + URLDecoder.decode(pluginId, "UTF-8")); - return downloadZip(pluginId, tmpDir); + return downloadZip(terminal, pluginId, tmpDir); } /** Downloads a zip from the url, into a temp file under the given temp dir. */ - private Path downloadZip(String urlString, Path tmpDir) throws IOException { + private Path downloadZip(Terminal terminal, String urlString, Path tmpDir) throws IOException { + terminal.println(VERBOSE, "Retrieving zip from " + urlString); URL url = new URL(urlString); Path zip = Files.createTempFile(tmpDir, null, ".zip"); try (InputStream in = url.openStream()) { @@ -226,8 +227,8 @@ class InstallPluginCommand extends Command { } /** Downloads a zip from the url, as well as a SHA1 checksum, and checks the checksum. */ - private Path downloadZipAndChecksum(String urlString, Path tmpDir) throws Exception { - Path zip = downloadZip(urlString, tmpDir); + private Path downloadZipAndChecksum(Terminal terminal, String urlString, Path tmpDir) throws Exception { + Path zip = downloadZip(terminal, urlString, tmpDir); URL checksumUrl = new URL(urlString + ".sha1"); final String expectedChecksum; From 125473dc9f492d07e24968f089b5e8ea6e836da6 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 14 Apr 2016 11:31:45 -0700 Subject: [PATCH 004/561] Mappings: Support dots in field names when mapping exists In 2.0 we began restricting fields to not contains dots in their names. This change adds back part of dots in fieldnames support. Specifically, it allows indexing documents that contain dots in the field names, when the correct corresponding mappers exist. For example, if mappings contain an object field `foo`, and a subfield `bar`, then indexing a document with `foo.bar` will work. see #15951 --- .../index/mapper/DocumentParser.java | 69 +++++++++---------- .../index/mapper/DocumentParserTests.java | 27 ++++++++ 2 files changed, 58 insertions(+), 38 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java b/core/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java index 70219516147..b00ff957744 100644 --- a/core/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java +++ b/core/src/main/java/org/elasticsearch/index/mapper/DocumentParser.java @@ -54,7 +54,6 @@ import org.elasticsearch.index.mapper.internal.TypeFieldMapper; import org.elasticsearch.index.mapper.internal.UidFieldMapper; import org.elasticsearch.index.mapper.object.ArrayValueMapperParser; import org.elasticsearch.index.mapper.object.ObjectMapper; -import org.elasticsearch.index.mapper.object.RootObjectMapper; /** A parser for documents, given mappings from a DocumentMapper */ final class DocumentParser implements Closeable { @@ -474,7 +473,7 @@ final class DocumentParser implements Closeable { context.addDynamicMapper(update); } if (fieldMapper.copyTo() != null) { - parseCopyFields(context, fieldMapper, fieldMapper.copyTo().copyToFields()); + parseCopyFields(context, fieldMapper.copyTo().copyToFields()); } } } @@ -484,14 +483,11 @@ final class DocumentParser implements Closeable { context.path().add(currentFieldName); ObjectMapper update = null; - Mapper objectMapper = mapper.getMapper(currentFieldName); + Mapper objectMapper = getMapper(mapper, currentFieldName); if (objectMapper != null) { parseObjectOrField(context, objectMapper); } else { - ObjectMapper.Dynamic dynamic = mapper.dynamic(); - if (dynamic == null) { - dynamic = dynamicOrDefault(context.root().dynamic()); - } + ObjectMapper.Dynamic dynamic = dynamicOrDefault(mapper, context.root().dynamic()); if (dynamic == ObjectMapper.Dynamic.STRICT) { throw new StrictDynamicMappingException(mapper.fullPath(), currentFieldName); } else if (dynamic == ObjectMapper.Dynamic.TRUE) { @@ -500,10 +496,6 @@ final class DocumentParser implements Closeable { Mapper.Builder builder = context.root().findTemplateBuilder(context, currentFieldName, "object"); if (builder == null) { builder = new ObjectMapper.Builder(currentFieldName).enabled(true); - // if this is a non root object, then explicitly set the dynamic behavior if set - if (!(mapper instanceof RootObjectMapper) && mapper.dynamic() != ObjectMapper.Defaults.DYNAMIC) { - ((ObjectMapper.Builder) builder).dynamic(mapper.dynamic()); - } } Mapper.BuilderContext builderContext = new Mapper.BuilderContext(context.indexSettings(), context.path()); objectMapper = builder.build(builderContext); @@ -522,7 +514,7 @@ final class DocumentParser implements Closeable { private static void parseArray(ParseContext context, ObjectMapper parentMapper, String lastFieldName) throws IOException { String arrayFieldName = lastFieldName; - Mapper mapper = parentMapper.getMapper(lastFieldName); + Mapper mapper = getMapper(parentMapper, lastFieldName); if (mapper != null) { // There is a concrete mapper for this field already. Need to check if the mapper // expects an array, if so we pass the context straight to the mapper and if not @@ -534,10 +526,7 @@ final class DocumentParser implements Closeable { } } else { - ObjectMapper.Dynamic dynamic = parentMapper.dynamic(); - if (dynamic == null) { - dynamic = dynamicOrDefault(context.root().dynamic()); - } + ObjectMapper.Dynamic dynamic = dynamicOrDefault(parentMapper, context.root().dynamic()); if (dynamic == ObjectMapper.Dynamic.STRICT) { throw new StrictDynamicMappingException(parentMapper.fullPath(), arrayFieldName); } else if (dynamic == ObjectMapper.Dynamic.TRUE) { @@ -587,7 +576,7 @@ final class DocumentParser implements Closeable { if (currentFieldName == null) { throw new MapperParsingException("object mapping [" + parentMapper.name() + "] trying to serialize a value with no field associated with it, current value [" + context.parser().textOrNull() + "]"); } - Mapper mapper = parentMapper.getMapper(currentFieldName); + Mapper mapper = getMapper(parentMapper, currentFieldName); if (mapper != null) { parseObjectOrField(context, mapper); } else { @@ -597,7 +586,7 @@ final class DocumentParser implements Closeable { private static void parseNullValue(ParseContext context, ObjectMapper parentMapper, String lastFieldName) throws IOException { // we can only handle null values if we have mappings for them - Mapper mapper = parentMapper.getMapper(lastFieldName); + Mapper mapper = getMapper(parentMapper, lastFieldName); if (mapper != null) { // TODO: passing null to an object seems bogus? parseObjectOrField(context, mapper); @@ -811,10 +800,7 @@ final class DocumentParser implements Closeable { } private static void parseDynamicValue(final ParseContext context, ObjectMapper parentMapper, String currentFieldName, XContentParser.Token token) throws IOException { - ObjectMapper.Dynamic dynamic = parentMapper.dynamic(); - if (dynamic == null) { - dynamic = dynamicOrDefault(context.root().dynamic()); - } + ObjectMapper.Dynamic dynamic = dynamicOrDefault(parentMapper, context.root().dynamic()); if (dynamic == ObjectMapper.Dynamic.STRICT) { throw new StrictDynamicMappingException(parentMapper.fullPath(), currentFieldName); } @@ -824,12 +810,11 @@ final class DocumentParser implements Closeable { final String path = context.path().pathAsText(currentFieldName); final Mapper.BuilderContext builderContext = new Mapper.BuilderContext(context.indexSettings(), context.path()); final MappedFieldType existingFieldType = context.mapperService().fullName(path); - Mapper.Builder builder = null; + final Mapper.Builder builder; if (existingFieldType != null) { // create a builder of the same type builder = createBuilderFromFieldType(context, existingFieldType, currentFieldName); - } - if (builder == null) { + } else { builder = createBuilderFromDynamicValue(context, token, currentFieldName); } Mapper mapper = builder.build(builderContext); @@ -843,7 +828,7 @@ final class DocumentParser implements Closeable { } /** Creates instances of the fields that the current field should be copied to */ - private static void parseCopyFields(ParseContext context, FieldMapper fieldMapper, List copyToFields) throws IOException { + private static void parseCopyFields(ParseContext context, List copyToFields) throws IOException { if (!context.isWithinCopyTo() && copyToFields.isEmpty() == false) { context = context.createCopyToContext(); for (String field : copyToFields) { @@ -888,10 +873,7 @@ final class DocumentParser implements Closeable { mapper = context.docMapper().objectMappers().get(context.path().pathAsText(paths[i])); if (mapper == null) { // One mapping is missing, check if we are allowed to create a dynamic one. - ObjectMapper.Dynamic dynamic = parent.dynamic(); - if (dynamic == null) { - dynamic = dynamicOrDefault(context.root().dynamic()); - } + ObjectMapper.Dynamic dynamic = dynamicOrDefault(parent, context.root().dynamic()); switch (dynamic) { case STRICT: @@ -899,10 +881,6 @@ final class DocumentParser implements Closeable { case TRUE: Mapper.Builder builder = context.root().findTemplateBuilder(context, paths[i], "object"); if (builder == null) { - // if this is a non root object, then explicitly set the dynamic behavior if set - if (!(parent instanceof RootObjectMapper) && parent.dynamic() != ObjectMapper.Defaults.DYNAMIC) { - ((ObjectMapper.Builder) builder).dynamic(parent.dynamic()); - } builder = new ObjectMapper.Builder(paths[i]).enabled(true); } Mapper.BuilderContext builderContext = new Mapper.BuilderContext(context.indexSettings(), context.path()); @@ -915,8 +893,6 @@ final class DocumentParser implements Closeable { case FALSE: // Maybe we should log something to tell the user that the copy_to is ignored in this case. break; - default: - throw new AssertionError("Unexpected dynamic type " + dynamic); } } @@ -929,8 +905,25 @@ final class DocumentParser implements Closeable { } } - private static ObjectMapper.Dynamic dynamicOrDefault(ObjectMapper.Dynamic dynamic) { - return dynamic == null ? ObjectMapper.Dynamic.TRUE : dynamic; + private static ObjectMapper.Dynamic dynamicOrDefault(ObjectMapper parentMapper, ObjectMapper.Dynamic dynamicDefault) { + ObjectMapper.Dynamic dynamic = parentMapper.dynamic(); + if (dynamic == null) { + return dynamicDefault == null ? ObjectMapper.Dynamic.TRUE : dynamicDefault; + } + return dynamic; + } + + // looks up a child mapper, but takes into account field names that expand to objects + static Mapper getMapper(ObjectMapper objectMapper, String fieldName) { + String[] subfields = fieldName.split("\\."); + for (int i = 0; i < subfields.length - 1; ++i) { + Mapper mapper = objectMapper.getMapper(subfields[i]); + if (mapper == null || (mapper instanceof ObjectMapper) == false) { + return null; + } + objectMapper = (ObjectMapper)mapper; + } + return objectMapper.getMapper(subfields[subfields.length - 1]); } @Override diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java index e4d1e306af3..a3b56ec9fc5 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java @@ -70,6 +70,33 @@ public class DocumentParserTests extends ESSingleNodeTestCase { assertNotNull(doc.rootDoc().getField(UidFieldMapper.NAME)); } + public void testDotsWithExistingMapper() throws Exception { + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") + .startObject("foo").startObject("properties") + .startObject("bar").startObject("properties") + .startObject("baz").field("type", "integer") + .endObject().endObject().endObject().endObject().endObject().endObject().endObject().endObject().string(); + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); + + BytesReference bytes = XContentFactory.jsonBuilder() + .startObject() + .field("foo.bar.baz", 123) + .startObject("foo") + .field("bar.baz", 456) + .endObject() + .startObject("foo.bar") + .field("baz", 789) + .endObject() + .endObject().bytes(); + ParsedDocument doc = mapper.parse("test", "type", "1", bytes); + String[] values = doc.rootDoc().getValues("foo.bar.baz"); + assertEquals(3, values.length); + assertEquals("123", values[0]); + assertEquals("456", values[1]); + assertEquals("789", values[2]); + } + DocumentMapper createDummyMapping(MapperService mapperService) throws Exception { String mapping = jsonBuilder().startObject().startObject("type").startObject("properties") .startObject("y").field("type", "object").endObject() From 88dd6ba430e729d473432076a6eba1f6cb85c136 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Thu, 14 Apr 2016 22:59:22 -0700 Subject: [PATCH 005/561] Rest: Remove 'case' parameter from rest apis The current api allows for choosing which "case" response json keys are written in. This has the options of camelCase or underscore. camelCase is going to be deprecated from the query apis. However, with the case api, it is not necessary to deprecate, as users who were using it in 2.x can transition completely on 2.x before upgrading by simply using the underscore option. This change removes the 'case' option from rest apis. see #8988 --- .../cluster/health/ClusterHealthResponse.java | 2 +- .../cluster/node/info/NodesInfoResponse.java | 14 +-- .../admin/cluster/node/stats/NodeStats.java | 10 +- .../node/stats/NodesStatsResponse.java | 4 +- .../node/tasks/list/ListTasksResponse.java | 8 +- .../verify/VerifyRepositoryResponse.java | 4 +- .../snapshots/status/SnapshotIndexStatus.java | 2 +- .../mapping/get/GetFieldMappingsResponse.java | 4 +- .../segments/IndicesSegmentResponse.java | 6 +- .../indices/stats/IndicesStatsResponse.java | 2 +- .../upgrade/get/UpgradeStatusResponse.java | 2 +- .../elasticsearch/cluster/ClusterState.java | 8 +- .../cluster/metadata/AliasMetaData.java | 2 +- .../cluster/metadata/IndexMetaData.java | 4 +- .../metadata/IndexTemplateMetaData.java | 4 +- .../metadata/RepositoriesMetaData.java | 2 +- .../cluster/node/DiscoveryNode.java | 2 +- .../common/settings/Settings.java | 2 +- .../elasticsearch/common/unit/Fuzziness.java | 2 +- .../common/xcontent/XContentBuilder.java | 98 +------------------ .../xcontent/XContentBuilderString.java | 19 +--- .../index/fielddata/FieldDataStats.java | 4 +- .../index/search/stats/SearchStats.java | 2 +- .../index/shard/IndexingStats.java | 2 +- .../BlobStoreIndexShardSnapshots.java | 2 +- .../org/elasticsearch/monitor/fs/FsInfo.java | 6 +- .../elasticsearch/monitor/jvm/JvmStats.java | 6 +- .../rest/AbstractRestChannel.java | 9 -- .../alias/get/RestGetAliasesAction.java | 2 +- .../mapping/get/RestGetMappingAction.java | 2 +- .../settings/RestGetSettingsAction.java | 2 +- .../indices/upgrade/RestUpgradeAction.java | 2 +- .../query/RestValidateQueryAction.java | 2 +- .../suggest/completion/CompletionStats.java | 6 +- .../elasticsearch/threadpool/ThreadPool.java | 2 +- .../threadpool/ThreadPoolStats.java | 2 +- .../builder/XContentBuilderTests.java | 12 --- 37 files changed, 70 insertions(+), 194 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java index 946897a2c97..7c0bd350289 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java @@ -305,7 +305,7 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo if (outputIndices) { builder.startObject(Fields.INDICES); for (ClusterIndexHealth indexHealth : clusterStateHealth.getIndices().values()) { - builder.startObject(indexHealth.getIndex(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(indexHealth.getIndex()); indexHealth.toXContent(builder, params); builder.endObject(); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoResponse.java index 79eab0f61a0..fdb15db8ffc 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/info/NodesInfoResponse.java @@ -64,23 +64,23 @@ public class NodesInfoResponse extends BaseNodesResponse implements To @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.field("cluster_name", getClusterName().value(), XContentBuilder.FieldCaseConversion.NONE); + builder.field("cluster_name", getClusterName().value()); builder.startObject("nodes"); for (NodeInfo nodeInfo : this) { - builder.startObject(nodeInfo.getNode().getId(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(nodeInfo.getNode().getId()); - builder.field("name", nodeInfo.getNode().getName(), XContentBuilder.FieldCaseConversion.NONE); + builder.field("name", nodeInfo.getNode().getName()); builder.field("transport_address", nodeInfo.getNode().getAddress().toString()); - builder.field("host", nodeInfo.getNode().getHostName(), XContentBuilder.FieldCaseConversion.NONE); - builder.field("ip", nodeInfo.getNode().getHostAddress(), XContentBuilder.FieldCaseConversion.NONE); + builder.field("host", nodeInfo.getNode().getHostName()); + builder.field("ip", nodeInfo.getNode().getHostAddress()); builder.field("version", nodeInfo.getVersion()); builder.field("build_hash", nodeInfo.getBuild().shortHash()); if (nodeInfo.getServiceAttributes() != null) { for (Map.Entry nodeAttribute : nodeInfo.getServiceAttributes().entrySet()) { - builder.field(nodeAttribute.getKey(), nodeAttribute.getValue(), XContentBuilder.FieldCaseConversion.NONE); + builder.field(nodeAttribute.getKey(), nodeAttribute.getValue()); } } @@ -93,7 +93,7 @@ public class NodesInfoResponse extends BaseNodesResponse implements To if (!nodeInfo.getNode().getAttributes().isEmpty()) { builder.startObject("attributes"); for (Map.Entry entry : nodeInfo.getNode().getAttributes().entrySet()) { - builder.field(entry.getKey(), entry.getValue(), XContentBuilder.FieldCaseConversion.NONE); + builder.field(entry.getKey(), entry.getValue()); } builder.endObject(); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java index ce16a848fc6..22e12d2baab 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodeStats.java @@ -299,10 +299,10 @@ public class NodeStats extends BaseNodeResponse implements ToXContent { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { if (!params.param("node_info_format", "default").equals("none")) { - builder.field("name", getNode().getName(), XContentBuilder.FieldCaseConversion.NONE); - builder.field("transport_address", getNode().getAddress().toString(), XContentBuilder.FieldCaseConversion.NONE); - builder.field("host", getNode().getHostName(), XContentBuilder.FieldCaseConversion.NONE); - builder.field("ip", getNode().getAddress(), XContentBuilder.FieldCaseConversion.NONE); + builder.field("name", getNode().getName()); + builder.field("transport_address", getNode().getAddress().toString()); + builder.field("host", getNode().getHostName()); + builder.field("ip", getNode().getAddress()); builder.startArray("roles"); for (DiscoveryNode.Role role : getNode().getRoles()) { @@ -313,7 +313,7 @@ public class NodeStats extends BaseNodeResponse implements ToXContent { if (!getNode().getAttributes().isEmpty()) { builder.startObject("attributes"); for (Map.Entry attrEntry : getNode().getAttributes().entrySet()) { - builder.field(attrEntry.getKey(), attrEntry.getValue(), XContentBuilder.FieldCaseConversion.NONE); + builder.field(attrEntry.getKey(), attrEntry.getValue()); } builder.endObject(); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsResponse.java index ffd28f90251..af28c1fb5d5 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/stats/NodesStatsResponse.java @@ -65,7 +65,7 @@ public class NodesStatsResponse extends BaseNodesResponse implements builder.startObject("nodes"); for (NodeStats nodeStats : this) { - builder.startObject(nodeStats.getNode().getId(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(nodeStats.getNode().getId()); builder.field("timestamp", nodeStats.getTimestamp()); nodeStats.toXContent(builder, params); @@ -88,4 +88,4 @@ public class NodesStatsResponse extends BaseNodesResponse implements return "{ \"error\" : \"" + e.getMessage() + "\"}"; } } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/ListTasksResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/ListTasksResponse.java index 7b308affcc9..f8ecd7a506f 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/ListTasksResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/node/tasks/list/ListTasksResponse.java @@ -163,7 +163,7 @@ public class ListTasksResponse extends BaseTasksResponse implements ToXContent { builder.startObject("nodes"); for (Map.Entry> entry : getPerNodeTasks().entrySet()) { DiscoveryNode node = entry.getKey(); - builder.startObject(node.getId(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(node.getId()); builder.field("name", node.getName()); builder.field("transport_address", node.getAddress().toString()); builder.field("host", node.getHostName()); @@ -178,13 +178,13 @@ public class ListTasksResponse extends BaseTasksResponse implements ToXContent { if (!node.getAttributes().isEmpty()) { builder.startObject("attributes"); for (Map.Entry attrEntry : node.getAttributes().entrySet()) { - builder.field(attrEntry.getKey(), attrEntry.getValue(), XContentBuilder.FieldCaseConversion.NONE); + builder.field(attrEntry.getKey(), attrEntry.getValue()); } builder.endObject(); } builder.startObject("tasks"); for(TaskInfo task : entry.getValue()) { - builder.startObject(task.getTaskId().toString(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(task.getTaskId().toString()); task.toXContent(builder, params); builder.endObject(); } @@ -194,7 +194,7 @@ public class ListTasksResponse extends BaseTasksResponse implements ToXContent { } else if ("parents".equals(groupBy)) { builder.startObject("tasks"); for (TaskGroup group : getTaskGroups()) { - builder.startObject(group.getTaskInfo().getTaskId().toString(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(group.getTaskInfo().getTaskId().toString()); group.toXContent(builder, params); builder.endObject(); } diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java index ddc2f7035d7..11020beac4a 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java @@ -86,8 +86,8 @@ public class VerifyRepositoryResponse extends ActionResponse implements ToXConte public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(Fields.NODES); for (DiscoveryNode node : nodes) { - builder.startObject(node.getId(), XContentBuilder.FieldCaseConversion.NONE); - builder.field(Fields.NAME, node.getName(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(node.getId()); + builder.field(Fields.NAME, node.getName()); builder.endObject(); } builder.endObject(); diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotIndexStatus.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotIndexStatus.java index 5999fc3eb4f..87d153a83fd 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotIndexStatus.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotIndexStatus.java @@ -96,7 +96,7 @@ public class SnapshotIndexStatus implements Iterable, @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(getIndex(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(getIndex()); shardsStats.toXContent(builder, params); stats.toXContent(builder, params); builder.startObject(Fields.SHARDS); diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java index 12ef72bfc8e..e0cedcf841e 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/mapping/get/GetFieldMappingsResponse.java @@ -74,10 +74,10 @@ public class GetFieldMappingsResponse extends ActionResponse implements ToXConte @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { for (Map.Entry>> indexEntry : mappings.entrySet()) { - builder.startObject(indexEntry.getKey(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(indexEntry.getKey()); builder.startObject("mappings"); for (Map.Entry> typeEntry : indexEntry.getValue().entrySet()) { - builder.startObject(typeEntry.getKey(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(typeEntry.getKey()); for (Map.Entry fieldEntry : typeEntry.getValue().entrySet()) { builder.startObject(fieldEntry.getKey()); fieldEntry.getValue().toXContent(builder, params); diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentResponse.java index 6bcf7d71c34..05729f4f0f9 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/segments/IndicesSegmentResponse.java @@ -102,7 +102,7 @@ public class IndicesSegmentResponse extends BroadcastResponse implements ToXCont builder.startObject(Fields.INDICES); for (IndexSegments indexSegments : getIndices().values()) { - builder.startObject(indexSegments.getIndex(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(indexSegments.getIndex()); builder.startObject(Fields.SHARDS); for (IndexShardSegments indexSegment : indexSegments) { @@ -164,7 +164,7 @@ public class IndicesSegmentResponse extends BroadcastResponse implements ToXCont builder.endObject(); return builder; } - + static void toXContent(XContentBuilder builder, Accountable tree) throws IOException { builder.startObject(); builder.field(Fields.DESCRIPTION, tree.toString()); @@ -208,4 +208,4 @@ public class IndicesSegmentResponse extends BroadcastResponse implements ToXCont static final XContentBuilderString DESCRIPTION = new XContentBuilderString("description"); static final XContentBuilderString CHILDREN = new XContentBuilderString("children"); } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsResponse.java index 11f91397c52..a99a8883ddc 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsResponse.java @@ -176,7 +176,7 @@ public class IndicesStatsResponse extends BroadcastResponse implements ToXConten if ("indices".equalsIgnoreCase(level) || "shards".equalsIgnoreCase(level)) { builder.startObject(Fields.INDICES); for (IndexStats indexStats : getIndices().values()) { - builder.startObject(indexStats.getIndex(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(indexStats.getIndex()); builder.startObject("primaries"); indexStats.getPrimaries().toXContent(builder, params); diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/upgrade/get/UpgradeStatusResponse.java b/core/src/main/java/org/elasticsearch/action/admin/indices/upgrade/get/UpgradeStatusResponse.java index 6c3a64e04fc..b20f8554500 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/indices/upgrade/get/UpgradeStatusResponse.java +++ b/core/src/main/java/org/elasticsearch/action/admin/indices/upgrade/get/UpgradeStatusResponse.java @@ -126,7 +126,7 @@ public class UpgradeStatusResponse extends BroadcastResponse implements ToXConte if (outputIndices) { builder.startObject(Fields.INDICES); for (IndexUpgradeStatus indexUpgradeStatus : getIndices().values()) { - builder.startObject(indexUpgradeStatus.getIndex(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(indexUpgradeStatus.getIndex()); builder.byteSizeField(Fields.SIZE_IN_BYTES, Fields.SIZE, indexUpgradeStatus.getTotalBytes()); builder.byteSizeField(Fields.SIZE_TO_UPGRADE_IN_BYTES, Fields.SIZE_TO_UPGRADE, indexUpgradeStatus.getToUpgradeBytes()); diff --git a/core/src/main/java/org/elasticsearch/cluster/ClusterState.java b/core/src/main/java/org/elasticsearch/cluster/ClusterState.java index 3f9ef6a82b8..4c69bfa500e 100644 --- a/core/src/main/java/org/elasticsearch/cluster/ClusterState.java +++ b/core/src/main/java/org/elasticsearch/cluster/ClusterState.java @@ -427,7 +427,7 @@ public class ClusterState implements ToXContent, Diffable { builder.startObject("templates"); for (ObjectCursor cursor : metaData().templates().values()) { IndexTemplateMetaData templateMetaData = cursor.value; - builder.startObject(templateMetaData.name(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(templateMetaData.name()); builder.field("template", templateMetaData.template()); builder.field("order", templateMetaData.order()); @@ -458,7 +458,7 @@ public class ClusterState implements ToXContent, Diffable { builder.startObject("indices"); for (IndexMetaData indexMetaData : metaData()) { - builder.startObject(indexMetaData.getIndex().getName(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(indexMetaData.getIndex().getName()); builder.field("state", indexMetaData.getState().toString().toLowerCase(Locale.ENGLISH)); @@ -522,7 +522,7 @@ public class ClusterState implements ToXContent, Diffable { builder.startObject("routing_table"); builder.startObject("indices"); for (IndexRoutingTable indexRoutingTable : routingTable()) { - builder.startObject(indexRoutingTable.getIndex().getName(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(indexRoutingTable.getIndex().getName()); builder.startObject("shards"); for (IndexShardRoutingTable indexShardRoutingTable : indexRoutingTable) { builder.startArray(Integer.toString(indexShardRoutingTable.shardId().id())); @@ -549,7 +549,7 @@ public class ClusterState implements ToXContent, Diffable { builder.startObject("nodes"); for (RoutingNode routingNode : getRoutingNodes()) { - builder.startArray(routingNode.nodeId() == null ? "null" : routingNode.nodeId(), XContentBuilder.FieldCaseConversion.NONE); + builder.startArray(routingNode.nodeId() == null ? "null" : routingNode.nodeId()); for (ShardRouting shardRouting : routingNode) { shardRouting.toXContent(builder, params); } diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java index c083396482e..f194af9a16f 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java @@ -281,7 +281,7 @@ public class AliasMetaData extends AbstractDiffable { } public static void toXContent(AliasMetaData aliasMetaData, XContentBuilder builder, ToXContent.Params params) throws IOException { - builder.startObject(aliasMetaData.alias(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(aliasMetaData.alias()); boolean binary = params.paramAsBoolean("binary", false); diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java index d493e3f9031..165a4265fd7 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java @@ -908,7 +908,7 @@ public class IndexMetaData implements Diffable, FromXContentBuild } public static void toXContent(IndexMetaData indexMetaData, XContentBuilder builder, ToXContent.Params params) throws IOException { - builder.startObject(indexMetaData.getIndex().getName(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(indexMetaData.getIndex().getName()); builder.field(KEY_VERSION, indexMetaData.getVersion()); builder.field(KEY_STATE, indexMetaData.getState().toString().toLowerCase(Locale.ENGLISH)); @@ -936,7 +936,7 @@ public class IndexMetaData implements Diffable, FromXContentBuild builder.endArray(); for (ObjectObjectCursor cursor : indexMetaData.getCustoms()) { - builder.startObject(cursor.key, XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(cursor.key); cursor.value.toXContent(builder, params); builder.endObject(); } diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java index 6ae9a6746e5..edb5825d469 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java @@ -316,7 +316,7 @@ public class IndexTemplateMetaData extends AbstractDiffable cursor : indexTemplateMetaData.customs()) { - builder.startObject(cursor.key, XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(cursor.key); cursor.value.toXContent(builder, params); builder.endObject(); } diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/RepositoriesMetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/RepositoriesMetaData.java index aa8f204953a..2dc842ceaae 100644 --- a/core/src/main/java/org/elasticsearch/cluster/metadata/RepositoriesMetaData.java +++ b/core/src/main/java/org/elasticsearch/cluster/metadata/RepositoriesMetaData.java @@ -197,7 +197,7 @@ public class RepositoriesMetaData extends AbstractDiffable implements Me * @param params serialization parameters */ public static void toXContent(RepositoryMetaData repository, XContentBuilder builder, ToXContent.Params params) throws IOException { - builder.startObject(repository.name(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(repository.name()); builder.field("type", repository.type()); builder.startObject("settings"); repository.settings().toXContent(builder, params); diff --git a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java index ea1973c4057..0de737792fc 100644 --- a/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java +++ b/core/src/main/java/org/elasticsearch/cluster/node/DiscoveryNode.java @@ -335,7 +335,7 @@ public class DiscoveryNode implements Writeable, ToXContent { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(getId(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(getId()); builder.field("name", getName()); builder.field("transport_address", getAddress().toString()); diff --git a/core/src/main/java/org/elasticsearch/common/settings/Settings.java b/core/src/main/java/org/elasticsearch/common/settings/Settings.java index 5608eca394a..ac1a3662c8e 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/Settings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/Settings.java @@ -751,7 +751,7 @@ public final class Settings implements ToXContent { } } else { for (Map.Entry entry : settings.getAsMap().entrySet()) { - builder.field(entry.getKey(), entry.getValue(), XContentBuilder.FieldCaseConversion.NONE); + builder.field(entry.getKey(), entry.getValue()); } } return builder; diff --git a/core/src/main/java/org/elasticsearch/common/unit/Fuzziness.java b/core/src/main/java/org/elasticsearch/common/unit/Fuzziness.java index 9068c5ffa50..139dfd75494 100644 --- a/core/src/main/java/org/elasticsearch/common/unit/Fuzziness.java +++ b/core/src/main/java/org/elasticsearch/common/unit/Fuzziness.java @@ -43,7 +43,7 @@ public final class Fuzziness implements ToXContent, Writeable { public static final Fuzziness ONE = new Fuzziness(1); public static final Fuzziness TWO = new Fuzziness(2); public static final Fuzziness AUTO = new Fuzziness("AUTO"); - public static final ParseField FIELD = new ParseField(X_FIELD_NAME.camelCase().getValue()); + public static final ParseField FIELD = new ParseField(X_FIELD_NAME.value()); private final String fuzziness; diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java b/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java index 2229d45840b..83122646df6 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java @@ -51,33 +51,12 @@ import java.util.Map; import java.util.concurrent.TimeUnit; /** - * + * A utility to build XContent (ie json). */ public final class XContentBuilder implements BytesStream, Releasable { - public enum FieldCaseConversion { - /** - * No conversion will occur. - */ - NONE, - /** - * Camel Case will be converted to Underscore casing. - */ - UNDERSCORE, - /** - * Underscore will be converted to Camel case. - */ - CAMELCASE - } - public final static DateTimeFormatter defaultDatePrinter = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC); - protected static FieldCaseConversion globalFieldCaseConversion = FieldCaseConversion.NONE; - - public static void globalFieldCaseConversion(FieldCaseConversion globalFieldCaseConversion) { - XContentBuilder.globalFieldCaseConversion = globalFieldCaseConversion; - } - public static XContentBuilder builder(XContent xContent) throws IOException { return new XContentBuilder(xContent, new BytesStreamOutput()); } @@ -94,10 +73,6 @@ public final class XContentBuilder implements BytesStream, Releasable { private final OutputStream bos; - private FieldCaseConversion fieldCaseConversion = globalFieldCaseConversion; - - private StringBuilder cachedStringBuilder; - private boolean humanReadable = false; /** @@ -130,11 +105,6 @@ public final class XContentBuilder implements BytesStream, Releasable { this.generator = xContent.createGenerator(bos, filters, inclusive); } - public XContentBuilder fieldCaseConversion(FieldCaseConversion fieldCaseConversion) { - this.fieldCaseConversion = fieldCaseConversion; - return this; - } - public XContentType contentType() { return generator.contentType(); } @@ -176,24 +146,12 @@ public final class XContentBuilder implements BytesStream, Releasable { return this; } - public XContentBuilder startObject(String name, FieldCaseConversion conversion) throws IOException { - field(name, conversion); - startObject(); - return this; - } - public XContentBuilder startObject(XContentBuilderString name) throws IOException { field(name); startObject(); return this; } - public XContentBuilder startObject(XContentBuilderString name, FieldCaseConversion conversion) throws IOException { - field(name, conversion); - startObject(); - return this; - } - public XContentBuilder startObject() throws IOException { generator.writeStartObject(); return this; @@ -240,12 +198,6 @@ public final class XContentBuilder implements BytesStream, Releasable { return this; } - public XContentBuilder startArray(String name, FieldCaseConversion conversion) throws IOException { - field(name, conversion); - startArray(); - return this; - } - public XContentBuilder startArray(String name) throws IOException { field(name); startArray(); @@ -269,39 +221,13 @@ public final class XContentBuilder implements BytesStream, Releasable { } public XContentBuilder field(XContentBuilderString name) throws IOException { - return field(name, fieldCaseConversion); - } - - public XContentBuilder field(XContentBuilderString name, FieldCaseConversion conversion) throws IOException { - if (conversion == FieldCaseConversion.UNDERSCORE) { - generator.writeFieldName(name.underscore()); - } else if (conversion == FieldCaseConversion.CAMELCASE) { - generator.writeFieldName(name.camelCase()); - } else { - generator.writeFieldName(name.underscore()); - } - return this; + return field(name.value()); } public XContentBuilder field(String name) throws IOException { - return field(name, fieldCaseConversion); - } - - public XContentBuilder field(String name, FieldCaseConversion conversion) throws IOException { if (name == null) { throw new IllegalArgumentException("field name cannot be null"); } - if (conversion == FieldCaseConversion.UNDERSCORE) { - if (cachedStringBuilder == null) { - cachedStringBuilder = new StringBuilder(); - } - name = Strings.toUnderscoreCase(name, cachedStringBuilder); - } else if (conversion == FieldCaseConversion.CAMELCASE) { - if (cachedStringBuilder == null) { - cachedStringBuilder = new StringBuilder(); - } - name = Strings.toCamelCase(name, cachedStringBuilder); - } generator.writeFieldName(name); return this; } @@ -336,16 +262,6 @@ public final class XContentBuilder implements BytesStream, Releasable { return this; } - public XContentBuilder field(String name, String value, FieldCaseConversion conversion) throws IOException { - field(name, conversion); - if (value == null) { - generator.writeNull(); - } else { - generator.writeString(value); - } - return this; - } - public XContentBuilder field(XContentBuilderString name, String value) throws IOException { field(name); if (value == null) { @@ -356,16 +272,6 @@ public final class XContentBuilder implements BytesStream, Releasable { return this; } - public XContentBuilder field(XContentBuilderString name, String value, FieldCaseConversion conversion) throws IOException { - field(name, conversion); - if (value == null) { - generator.writeNull(); - } else { - generator.writeString(value); - } - return this; - } - public XContentBuilder field(String name, Integer value) throws IOException { field(name); if (value == null) { diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilderString.java b/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilderString.java index ea1f6f1dd8a..b056131f585 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilderString.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilderString.java @@ -19,27 +19,18 @@ package org.elasticsearch.common.xcontent; -import org.elasticsearch.common.Strings; - /** - * + * TODO: remove this, it is just a wrapper that is no longer needed */ public class XContentBuilderString { - private final XContentString underscore; - - private final XContentString camelCase; + private final String value; public XContentBuilderString(String value) { - underscore = new XContentString(Strings.toUnderscoreCase(value)); - camelCase = new XContentString(Strings.toCamelCase(value)); + this.value = value; } - public XContentString underscore() { - return underscore; - } - - public XContentString camelCase() { - return camelCase; + public String value() { + return value; } } diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/FieldDataStats.java b/core/src/main/java/org/elasticsearch/index/fielddata/FieldDataStats.java index ec55ae9d59f..3f3f1b550c3 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/FieldDataStats.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/FieldDataStats.java @@ -54,7 +54,7 @@ public class FieldDataStats implements Streamable, ToXContent { this.memorySize += stats.memorySize; this.evictions += stats.evictions; if (stats.fields != null) { - if (fields == null) { + if (fields == null) { fields = stats.fields.clone(); } else { assert !stats.fields.containsKey(null); @@ -138,7 +138,7 @@ public class FieldDataStats implements Streamable, ToXContent { final long[] values = fields.values; for (int i = 0; i < keys.length; i++) { if (keys[i] != null) { - builder.startObject((String) keys[i], XContentBuilder.FieldCaseConversion.NONE); + builder.startObject((String) keys[i]); builder.byteSizeField(Fields.MEMORY_SIZE_IN_BYTES, Fields.MEMORY_SIZE, values[i]); builder.endObject(); } diff --git a/core/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java b/core/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java index bcabd7c5e12..83252103c40 100644 --- a/core/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java +++ b/core/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java @@ -309,7 +309,7 @@ public class SearchStats implements Streamable, ToXContent { if (groupStats != null && !groupStats.isEmpty()) { builder.startObject(Fields.GROUPS); for (Map.Entry entry : groupStats.entrySet()) { - builder.startObject(entry.getKey(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(entry.getKey()); entry.getValue().toXContent(builder, params); builder.endObject(); } diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexingStats.java b/core/src/main/java/org/elasticsearch/index/shard/IndexingStats.java index 27cda2ca1c8..beafbefddcd 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexingStats.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexingStats.java @@ -258,7 +258,7 @@ public class IndexingStats implements Streamable, ToXContent { if (typeStats != null && !typeStats.isEmpty()) { builder.startObject(Fields.TYPES); for (Map.Entry entry : typeStats.entrySet()) { - builder.startObject(entry.getKey(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(entry.getKey()); entry.getValue().toXContent(builder, params); builder.endObject(); } diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java index 1e0d55f2f65..7b7a8dd9829 100644 --- a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java +++ b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java @@ -221,7 +221,7 @@ public class BlobStoreIndexShardSnapshots implements Iterable, To // Then we list all snapshots with list of all blobs that are used by the snapshot builder.startObject(Fields.SNAPSHOTS); for (SnapshotFiles snapshot : shardSnapshots) { - builder.startObject(snapshot.snapshot(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(snapshot.snapshot()); builder.startArray(Fields.FILES); for (FileInfo fileInfo : snapshot.indexFiles()) { builder.value(fileInfo.name()); diff --git a/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java b/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java index b97457af706..55ce159f397 100644 --- a/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java +++ b/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java @@ -166,13 +166,13 @@ public class FsInfo implements Iterable, Streamable, ToXContent { public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); if (path != null) { - builder.field(Fields.PATH, path, XContentBuilder.FieldCaseConversion.NONE); + builder.field(Fields.PATH, path); } if (mount != null) { - builder.field(Fields.MOUNT, mount, XContentBuilder.FieldCaseConversion.NONE); + builder.field(Fields.MOUNT, mount); } if (type != null) { - builder.field(Fields.TYPE, type, XContentBuilder.FieldCaseConversion.NONE); + builder.field(Fields.TYPE, type); } if (total != -1) { diff --git a/core/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java b/core/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java index 276ef537bc8..c78ed608068 100644 --- a/core/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java +++ b/core/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java @@ -195,7 +195,7 @@ public class JvmStats implements Streamable, ToXContent { builder.startObject(Fields.POOLS); for (MemoryPool pool : mem) { - builder.startObject(pool.getName(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(pool.getName()); builder.byteSizeField(Fields.USED_IN_BYTES, Fields.USED, pool.used); builder.byteSizeField(Fields.MAX_IN_BYTES, Fields.MAX, pool.max); @@ -219,7 +219,7 @@ public class JvmStats implements Streamable, ToXContent { builder.startObject(Fields.COLLECTORS); for (GarbageCollector collector : gc) { - builder.startObject(collector.getName(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(collector.getName()); builder.field(Fields.COLLECTION_COUNT, collector.getCollectionCount()); builder.timeValueField(Fields.COLLECTION_TIME_IN_MILLIS, Fields.COLLECTION_TIME, collector.collectionTime); builder.endObject(); @@ -232,7 +232,7 @@ public class JvmStats implements Streamable, ToXContent { if (bufferPools != null) { builder.startObject(Fields.BUFFER_POOLS); for (BufferPool bufferPool : bufferPools) { - builder.startObject(bufferPool.getName(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(bufferPool.getName()); builder.field(Fields.COUNT, bufferPool.getCount()); builder.byteSizeField(Fields.USED_IN_BYTES, Fields.USED, bufferPool.used); builder.byteSizeField(Fields.TOTAL_CAPACITY_IN_BYTES, Fields.TOTAL_CAPACITY, bufferPool.totalCapacity); diff --git a/core/src/main/java/org/elasticsearch/rest/AbstractRestChannel.java b/core/src/main/java/org/elasticsearch/rest/AbstractRestChannel.java index 89434b1ce47..aa00943ed08 100644 --- a/core/src/main/java/org/elasticsearch/rest/AbstractRestChannel.java +++ b/core/src/main/java/org/elasticsearch/rest/AbstractRestChannel.java @@ -71,15 +71,6 @@ public abstract class AbstractRestChannel implements RestChannel { } builder.humanReadable(request.paramAsBoolean("human", builder.humanReadable())); - - String casing = request.param("case"); - if (casing != null && "camelCase".equals(casing)) { - builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.CAMELCASE); - } else { - // we expect all REST interfaces to write results in underscore casing, so - // no need for double casing - builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.NONE); - } return builder; } diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/get/RestGetAliasesAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/get/RestGetAliasesAction.java index da439c63d5e..d18b013efb2 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/get/RestGetAliasesAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/get/RestGetAliasesAction.java @@ -83,7 +83,7 @@ public class RestGetAliasesAction extends BaseRestHandler { builder.startObject(); for (ObjectObjectCursor> entry : response.getAliases()) { - builder.startObject(entry.key, XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(entry.key); builder.startObject(Fields.ALIASES); for (AliasMetaData alias : entry.value) { AliasMetaData.Builder.toXContent(alias, builder, ToXContent.EMPTY_PARAMS); diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java index 12c29bb781e..29012ba86fe 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java @@ -88,7 +88,7 @@ public class RestGetMappingAction extends BaseRestHandler { if (indexEntry.value.isEmpty()) { continue; } - builder.startObject(indexEntry.key, XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(indexEntry.key); builder.startObject(Fields.MAPPINGS); for (ObjectObjectCursor typeEntry : indexEntry.value) { builder.field(typeEntry.key); diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestGetSettingsAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestGetSettingsAction.java index 300423a6ed5..8c24e2c68e3 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestGetSettingsAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/settings/RestGetSettingsAction.java @@ -77,7 +77,7 @@ public class RestGetSettingsAction extends BaseRestHandler { if (cursor.value.getAsMap().isEmpty()) { continue; } - builder.startObject(cursor.key, XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(cursor.key); builder.startObject("settings"); cursor.value.toXContent(builder, request); builder.endObject(); diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/upgrade/RestUpgradeAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/upgrade/RestUpgradeAction.java index 60a781f90bb..7c4c0f51b8e 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/upgrade/RestUpgradeAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/upgrade/RestUpgradeAction.java @@ -89,7 +89,7 @@ public class RestUpgradeAction extends BaseRestHandler { buildBroadcastShardsHeader(builder, request, response); builder.startObject("upgraded_indices"); for (Map.Entry> entry : response.versions().entrySet()) { - builder.startObject(entry.getKey(), XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(entry.getKey()); builder.field("upgrade_version", entry.getValue().v1()); builder.field("oldest_lucene_segment_version", entry.getValue().v2()); builder.endObject(); diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/query/RestValidateQueryAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/query/RestValidateQueryAction.java index 86d6e9d6089..c0a209375b0 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/query/RestValidateQueryAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/query/RestValidateQueryAction.java @@ -102,7 +102,7 @@ public class RestValidateQueryAction extends BaseRestHandler { for (QueryExplanation explanation : response.getQueryExplanation()) { builder.startObject(); if (explanation.getIndex() != null) { - builder.field(INDEX_FIELD, explanation.getIndex(), XContentBuilder.FieldCaseConversion.NONE); + builder.field(INDEX_FIELD, explanation.getIndex()); } builder.field(VALID_FIELD, explanation.isValid()); if (explanation.getError() != null) { diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionStats.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionStats.java index 5ec517dd8d0..7bb96aeedca 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionStats.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionStats.java @@ -80,7 +80,7 @@ public class CompletionStats implements Streamable, ToXContent { } else { out.writeBoolean(true); out.writeVInt(fields.size()); - + assert !fields.containsKey(null); final Object[] keys = fields.keys; final long[] values = fields.values; @@ -105,7 +105,7 @@ public class CompletionStats implements Streamable, ToXContent { final long[] values = fields.values; for (int i = 0; i < keys.length; i++) { if (keys[i] != null) { - builder.startObject((String) keys[i], XContentBuilder.FieldCaseConversion.NONE); + builder.startObject((String) keys[i]); builder.byteSizeField(Fields.SIZE_IN_BYTES, Fields.SIZE, values[i]); builder.endObject(); } @@ -137,7 +137,7 @@ public class CompletionStats implements Streamable, ToXContent { sizeInBytes += completion.getSizeInBytes(); if (completion.fields != null) { - if (fields == null) { + if (fields == null) { fields = completion.fields.clone(); } else { assert !completion.fields.containsKey(null); diff --git a/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java b/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java index 30881073397..f612a770b86 100644 --- a/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java +++ b/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java @@ -889,7 +889,7 @@ public class ThreadPool extends AbstractComponent implements Closeable { @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(name, XContentBuilder.FieldCaseConversion.NONE); + builder.startObject(name); builder.field(Fields.TYPE, type.getType()); if (min != -1) { builder.field(Fields.MIN, min); diff --git a/core/src/main/java/org/elasticsearch/threadpool/ThreadPoolStats.java b/core/src/main/java/org/elasticsearch/threadpool/ThreadPoolStats.java index af53482c629..f16d6a886d8 100644 --- a/core/src/main/java/org/elasticsearch/threadpool/ThreadPoolStats.java +++ b/core/src/main/java/org/elasticsearch/threadpool/ThreadPoolStats.java @@ -112,7 +112,7 @@ public class ThreadPoolStats implements Streamable, ToXContent, Iterable Date: Fri, 15 Apr 2016 06:10:30 -0400 Subject: [PATCH 006/561] switch to registered Settings for all IndexingMemoryController settings --- .../common/settings/ClusterSettings.java | 8 ++- .../elasticsearch/index/shard/IndexShard.java | 2 +- .../indices/IndexingMemoryController.java | 51 ++++++++++++------- .../IndexingMemoryControllerTests.java | 20 ++++---- 4 files changed, 52 insertions(+), 29 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java index 83f9afc3f38..5622461c0ee 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -65,6 +65,7 @@ import org.elasticsearch.http.HttpTransportSettings; import org.elasticsearch.http.netty.NettyHttpServerTransport; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.store.IndexStoreConfig; +import org.elasticsearch.indices.IndexingMemoryController; import org.elasticsearch.indices.IndicesQueryCache; import org.elasticsearch.indices.IndicesRequestCache; import org.elasticsearch.indices.IndicesService; @@ -404,6 +405,11 @@ public final class ClusterSettings extends AbstractScopedSettings { BootstrapSettings.SECURITY_FILTER_BAD_DEFAULTS_SETTING, BootstrapSettings.MLOCKALL_SETTING, BootstrapSettings.SECCOMP_SETTING, - BootstrapSettings.CTRLHANDLER_SETTING + BootstrapSettings.CTRLHANDLER_SETTING, + IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING, + IndexingMemoryController.MIN_INDEX_BUFFER_SIZE_SETTING, + IndexingMemoryController.MAX_INDEX_BUFFER_SIZE_SETTING, + IndexingMemoryController.SHARD_INACTIVE_TIME_SETTING, + IndexingMemoryController.SHARD_MEMORY_INTERVAL_TIME_SETTING ))); } diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java index 11f04ae2731..979dfd18152 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -1404,7 +1404,7 @@ public class IndexShard extends AbstractIndexShardComponent { return new EngineConfig(openMode, shardId, threadPool, indexSettings, warmer, store, deletionPolicy, indexSettings.getMergePolicy(), mapperService.indexAnalyzer(), similarityService.similarity(mapperService), codecService, shardEventListener, translogRecoveryPerformer, indexCache.query(), cachingPolicy, translogConfig, - indexSettings.getSettings().getAsTime(IndexingMemoryController.SHARD_INACTIVE_TIME_SETTING, IndexingMemoryController.SHARD_DEFAULT_INACTIVE_TIME)); + IndexingMemoryController.SHARD_INACTIVE_TIME_SETTING.get(indexSettings.getSettings())); } public Releasable acquirePrimaryOperationLock() { diff --git a/core/src/main/java/org/elasticsearch/indices/IndexingMemoryController.java b/core/src/main/java/org/elasticsearch/indices/IndexingMemoryController.java index d51288255ca..4536cf304c6 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndexingMemoryController.java +++ b/core/src/main/java/org/elasticsearch/indices/IndexingMemoryController.java @@ -20,6 +20,8 @@ package org.elasticsearch.indices; import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.settings.Setting.Property; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.ByteSizeUnit; import org.elasticsearch.common.unit.ByteSizeValue; @@ -50,22 +52,37 @@ import java.util.concurrent.locks.ReentrantLock; public class IndexingMemoryController extends AbstractComponent implements IndexingOperationListener, Closeable { /** How much heap (% or bytes) we will share across all actively indexing shards on this node (default: 10%). */ - public static final String INDEX_BUFFER_SIZE_SETTING = "indices.memory.index_buffer_size"; + public static final Setting INDEX_BUFFER_SIZE_SETTING = new Setting("indices.memory.index_buffer_size", (s) -> "10%", + (s) -> { + if (s.endsWith("%")) { + try { + Double.parseDouble(s.substring(0, s.length() - 1)); + } catch (NumberFormatException nfe) { + throw new IllegalArgumentException("unknown value for [indices.memory.index_buffer_size]: must be X% or a size value (e.g. XMB) but was: " + s); + } + } else { + try { + ByteSizeValue.parseBytesSizeValue(s, "indices.memory.index_buffer_size"); + } catch (Throwable t) { + throw new IllegalArgumentException("unknown value for [indices.memory.index_buffer_size]: must be X% or a size value (e.g. XMB) but " + t.getMessage()); + } + } + + return s; + }, + Property.NodeScope); /** Only applies when indices.memory.index_buffer_size is a %, to set a floor on the actual size in bytes (default: 48 MB). */ - public static final String MIN_INDEX_BUFFER_SIZE_SETTING = "indices.memory.min_index_buffer_size"; + public static final Setting MIN_INDEX_BUFFER_SIZE_SETTING = Setting.byteSizeSetting("indices.memory.min_index_buffer_size", new ByteSizeValue(48, ByteSizeUnit.MB), Property.NodeScope); /** Only applies when indices.memory.index_buffer_size is a %, to set a ceiling on the actual size in bytes (default: not set). */ - public static final String MAX_INDEX_BUFFER_SIZE_SETTING = "indices.memory.max_index_buffer_size"; + public static final Setting MAX_INDEX_BUFFER_SIZE_SETTING = Setting.byteSizeSetting("indices.memory.max_index_buffer_size", new ByteSizeValue(-1), Property.NodeScope); /** If we see no indexing operations after this much time for a given shard, we consider that shard inactive (default: 5 minutes). */ - public static final String SHARD_INACTIVE_TIME_SETTING = "indices.memory.shard_inactive_time"; - - /** Default value (5 minutes) for indices.memory.shard_inactive_time */ - public static final TimeValue SHARD_DEFAULT_INACTIVE_TIME = TimeValue.timeValueMinutes(5); + public static final Setting SHARD_INACTIVE_TIME_SETTING = Setting.timeSetting("indices.memory.shard_inactive_time", TimeValue.timeValueMinutes(5), Property.NodeScope); /** How frequently we check indexing memory usage (default: 5 seconds). */ - public static final String SHARD_MEMORY_INTERVAL_TIME_SETTING = "indices.memory.interval"; + public static final Setting SHARD_MEMORY_INTERVAL_TIME_SETTING = Setting.timeSetting("indices.memory.interval", TimeValue.timeValueSeconds(5), Property.NodeScope); private final ThreadPool threadPool; @@ -95,34 +112,34 @@ public class IndexingMemoryController extends AbstractComponent implements Index this.indexShards = indexServices; ByteSizeValue indexingBuffer; - String indexingBufferSetting = this.settings.get(INDEX_BUFFER_SIZE_SETTING, "10%"); + String indexingBufferSetting = INDEX_BUFFER_SIZE_SETTING.get(settings); if (indexingBufferSetting.endsWith("%")) { double percent = Double.parseDouble(indexingBufferSetting.substring(0, indexingBufferSetting.length() - 1)); indexingBuffer = new ByteSizeValue((long) (((double) jvmMemoryInBytes) * (percent / 100))); - ByteSizeValue minIndexingBuffer = this.settings.getAsBytesSize(MIN_INDEX_BUFFER_SIZE_SETTING, new ByteSizeValue(48, ByteSizeUnit.MB)); - ByteSizeValue maxIndexingBuffer = this.settings.getAsBytesSize(MAX_INDEX_BUFFER_SIZE_SETTING, null); + ByteSizeValue minIndexingBuffer = MIN_INDEX_BUFFER_SIZE_SETTING.get(this.settings); + ByteSizeValue maxIndexingBuffer = MAX_INDEX_BUFFER_SIZE_SETTING.get(this.settings); if (indexingBuffer.bytes() < minIndexingBuffer.bytes()) { indexingBuffer = minIndexingBuffer; } - if (maxIndexingBuffer != null && indexingBuffer.bytes() > maxIndexingBuffer.bytes()) { + if (maxIndexingBuffer.bytes() != -1 && indexingBuffer.bytes() > maxIndexingBuffer.bytes()) { indexingBuffer = maxIndexingBuffer; } } else { - indexingBuffer = ByteSizeValue.parseBytesSizeValue(indexingBufferSetting, INDEX_BUFFER_SIZE_SETTING); + indexingBuffer = ByteSizeValue.parseBytesSizeValue(indexingBufferSetting, INDEX_BUFFER_SIZE_SETTING.getKey()); } this.indexingBuffer = indexingBuffer; - this.inactiveTime = this.settings.getAsTime(SHARD_INACTIVE_TIME_SETTING, SHARD_DEFAULT_INACTIVE_TIME); + this.inactiveTime = SHARD_INACTIVE_TIME_SETTING.get(this.settings); // we need to have this relatively small to free up heap quickly enough - this.interval = this.settings.getAsTime(SHARD_MEMORY_INTERVAL_TIME_SETTING, TimeValue.timeValueSeconds(5)); + this.interval = SHARD_MEMORY_INTERVAL_TIME_SETTING.get(this.settings); this.statusChecker = new ShardsIndicesStatusChecker(); logger.debug("using indexing buffer size [{}] with {} [{}], {} [{}]", this.indexingBuffer, - SHARD_INACTIVE_TIME_SETTING, this.inactiveTime, - SHARD_MEMORY_INTERVAL_TIME_SETTING, this.interval); + SHARD_INACTIVE_TIME_SETTING.getKey(), this.inactiveTime, + SHARD_MEMORY_INTERVAL_TIME_SETTING.getKey(), this.interval); this.scheduler = scheduleTask(threadPool); // Need to save this so we can later launch async "write indexing buffer to disk" on shards: diff --git a/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java b/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java index 066a9b701d9..4ffcb503a2f 100644 --- a/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java +++ b/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java @@ -181,7 +181,7 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase { IndexService test = indicesService.indexService(resolveIndex("test")); MockController controller = new MockController(Settings.builder() - .put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING, "4mb").build()); + .put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING.getKey(), "4mb").build()); IndexShard shard0 = test.getShard(0); controller.simulateIndexing(shard0); controller.assertBuffer(shard0, 1); @@ -214,8 +214,8 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase { IndexService test = indicesService.indexService(resolveIndex("test")); MockController controller = new MockController(Settings.builder() - .put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING, "5mb") - .build()); + .put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING.getKey(), "5mb") + .build()); IndexShard shard0 = test.getShard(0); controller.simulateIndexing(shard0); @@ -248,16 +248,16 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase { public void testMinBufferSizes() { MockController controller = new MockController(Settings.builder() - .put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING, "0.001%") - .put(IndexingMemoryController.MIN_INDEX_BUFFER_SIZE_SETTING, "6mb").build()); + .put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING.getKey(), "0.001%") + .put(IndexingMemoryController.MIN_INDEX_BUFFER_SIZE_SETTING.getKey(), "6mb").build()); assertThat(controller.indexingBufferSize(), equalTo(new ByteSizeValue(6, ByteSizeUnit.MB))); } public void testMaxBufferSizes() { MockController controller = new MockController(Settings.builder() - .put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING, "90%") - .put(IndexingMemoryController.MAX_INDEX_BUFFER_SIZE_SETTING, "6mb").build()); + .put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING.getKey(), "90%") + .put(IndexingMemoryController.MAX_INDEX_BUFFER_SIZE_SETTING.getKey(), "6mb").build()); assertThat(controller.indexingBufferSize(), equalTo(new ByteSizeValue(6, ByteSizeUnit.MB))); } @@ -268,7 +268,7 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase { IndexService test = indicesService.indexService(resolveIndex("test")); MockController controller = new MockController(Settings.builder() - .put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING, "4mb").build()); + .put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING.getKey(), "4mb").build()); IndexShard shard0 = test.getShard(0); IndexShard shard1 = test.getShard(1); IndexShard shard2 = test.getShard(2); @@ -347,7 +347,7 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase { assertNoFailures(r); // Make a shell of an IMC to check up on indexing buffer usage: - Settings settings = Settings.builder().put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING, "1kb").build(); + Settings settings = Settings.builder().put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING.getKey(), "1kb").build(); // TODO: would be cleaner if I could pass this 1kb setting to the single node this test created.... IndexingMemoryController imc = new IndexingMemoryController(settings, null, null) { @@ -408,7 +408,7 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase { IndexSearcherWrapper wrapper = new IndexSearcherWrapper() {}; shard.close("simon says", false); AtomicReference shardRef = new AtomicReference<>(); - Settings settings = Settings.builder().put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING, "50kb").build(); + Settings settings = Settings.builder().put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING.getKey(), "50kb").build(); Iterable iterable = () -> (shardRef.get() == null) ? Collections.emptyList().iterator() : Collections.singleton(shardRef.get()).iterator(); AtomicInteger flushes = new AtomicInteger(); From beafae8ea5a29ceb1c134ea13984dfc65bbf0b32 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 14 Apr 2016 13:39:50 -0400 Subject: [PATCH 007/561] Cut range aggregations to registerAggregation and remove their PROTOTYPES. Does not remove the PROTOTYPEs from their Range implementations which will have to wait for another commit. --- .../elasticsearch/search/SearchModule.java | 9 ++-- .../bucket/range/AbstractRangeBuilder.java | 48 +++++++++++-------- .../bucket/range/RangeAggregatorBuilder.java | 25 +++++----- .../bucket/range/RangeParser.java | 13 ++--- .../date/DateRangeAggregatorBuilder.java | 29 +++++------ .../bucket/range/date/DateRangeParser.java | 10 ---- .../ipv4/IPv4RangeAggregatorBuilder.java | 23 ++++----- .../bucket/range/ipv4/IpRangeParser.java | 13 +---- 8 files changed, 74 insertions(+), 96 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index 5196ee00583..18eba2f9cbf 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -123,11 +123,14 @@ import org.elasticsearch.search.aggregations.bucket.nested.InternalReverseNested import org.elasticsearch.search.aggregations.bucket.nested.NestedParser; import org.elasticsearch.search.aggregations.bucket.nested.ReverseNestedParser; import org.elasticsearch.search.aggregations.bucket.range.InternalRange; +import org.elasticsearch.search.aggregations.bucket.range.RangeAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.range.RangeParser; +import org.elasticsearch.search.aggregations.bucket.range.date.DateRangeAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.range.date.DateRangeParser; import org.elasticsearch.search.aggregations.bucket.range.date.InternalDateRange; import org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceParser; import org.elasticsearch.search.aggregations.bucket.range.geodistance.InternalGeoDistance; +import org.elasticsearch.search.aggregations.bucket.range.ipv4.IPv4RangeAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.range.ipv4.InternalIPv4Range; import org.elasticsearch.search.aggregations.bucket.range.ipv4.IpRangeParser; import org.elasticsearch.search.aggregations.bucket.sampler.DiversifiedSamplerParser; @@ -457,9 +460,9 @@ public class SearchModule extends AbstractModule { registerAggregatorParser(new DiversifiedSamplerParser()); registerAggregatorParser(new TermsParser()); registerAggregatorParser(new SignificantTermsParser(significanceHeuristicParserMapper, queryParserRegistry)); - registerAggregatorParser(new RangeParser()); - registerAggregatorParser(new DateRangeParser()); - registerAggregatorParser(new IpRangeParser()); + registerAggregation(RangeAggregatorBuilder::new, new RangeParser(), RangeAggregatorBuilder.AGGREGATION_NAME_FIELD); + registerAggregation(DateRangeAggregatorBuilder::new, new DateRangeParser(), DateRangeAggregatorBuilder.AGGREGATION_NAME_FIELD); + registerAggregation(IPv4RangeAggregatorBuilder::new, new IpRangeParser(), IPv4RangeAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(HistogramAggregatorBuilder::new, new HistogramParser(), HistogramAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(DateHistogramAggregatorBuilder::new, new DateHistogramParser(), DateHistogramAggregatorBuilder.AGGREGATION_NAME_FIELD); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeBuilder.java index 7fe87b0774e..1e2e3f52daa 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/AbstractRangeBuilder.java @@ -20,13 +20,13 @@ package org.elasticsearch.search.aggregations.bucket.range; import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamInputReader; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.Range; -import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; -import org.elasticsearch.search.aggregations.support.ValuesSourceType; + import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -44,6 +44,31 @@ public abstract class AbstractRangeBuilder rangeFactory, StreamInputReader rangeReader) + throws IOException { + super(in, rangeFactory.type(), rangeFactory.getValueSourceType(), rangeFactory.getValueType()); + this.rangeFactory = rangeFactory; + ranges = in.readList(rangeReader); + keyed = in.readBoolean(); + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + out.writeVInt(ranges.size()); + for (Range range : ranges) { + range.writeTo(out); + } + out.writeBoolean(keyed); + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; + } + public AB addRange(R range) { if (range == null) { throw new IllegalArgumentException("[range] must not be null: [" + name + "]"); @@ -72,25 +97,6 @@ public abstract class AbstractRangeBuilder factory = createFactoryFromStream(name, in); - factory.keyed = in.readBoolean(); - return (AB) factory; - } - - protected abstract AbstractRangeBuilder createFactoryFromStream(String name, StreamInput in) throws IOException; - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - out.writeVInt(ranges.size()); - for (Range range : ranges) { - range.writeTo(out); - } - out.writeBoolean(keyed); - } - @Override protected int innerHashCode() { return Objects.hash(ranges, keyed); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregatorBuilder.java index 60de6a473c2..5241243e3af 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/RangeAggregatorBuilder.java @@ -19,24 +19,32 @@ package org.elasticsearch.search.aggregations.bucket.range; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.Range; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import java.io.IOException; public class RangeAggregatorBuilder extends AbstractRangeBuilder { - - static final RangeAggregatorBuilder PROTOTYPE = new RangeAggregatorBuilder(""); + public static final String NAME = InternalRange.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); public RangeAggregatorBuilder(String name) { super(name, InternalRange.FACTORY); } + /** + * Read from a stream. + */ + public RangeAggregatorBuilder(StreamInput in) throws IOException { + super(in, InternalRange.FACTORY, Range.PROTOTYPE::readFrom); + } + /** * Add a new range to this aggregation. * @@ -111,12 +119,7 @@ public class RangeAggregatorBuilder extends AbstractRangeBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) { @@ -92,9 +90,4 @@ public class RangeParser extends NumericValuesSourceParser { protected Range parseRange(XContentParser parser, ParseFieldMatcher parseFieldMatcher) throws IOException { return Range.PROTOTYPE.fromXContent(parser, parseFieldMatcher); } - - @Override - public AbstractRangeBuilder getFactoryPrototypes() { - return RangeAggregatorBuilder.PROTOTYPE; - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/date/DateRangeAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/date/DateRangeAggregatorBuilder.java index abd3ad6372e..94fdeb7bf4e 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/date/DateRangeAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/date/DateRangeAggregatorBuilder.java @@ -19,30 +19,38 @@ package org.elasticsearch.search.aggregations.bucket.range.date; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.bucket.range.AbstractRangeBuilder; import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator; import org.elasticsearch.search.aggregations.bucket.range.RangeAggregator.Range; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; +import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.joda.time.DateTime; import java.io.IOException; public class DateRangeAggregatorBuilder extends AbstractRangeBuilder { - - static final DateRangeAggregatorBuilder PROTOTYPE = new DateRangeAggregatorBuilder(""); + public static final String NAME = InternalDateRange.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); public DateRangeAggregatorBuilder(String name) { super(name, InternalDateRange.FACTORY); } + /** + * Read from a stream. + */ + public DateRangeAggregatorBuilder(StreamInput in) throws IOException { + super(in, InternalDateRange.FACTORY, Range.PROTOTYPE::readFrom); + } + @Override public String getWriteableName() { - return InternalDateRange.TYPE.name(); + return NAME; } /** @@ -254,15 +262,4 @@ public class DateRangeAggregatorBuilder extends AbstractRangeBuilder otherOptions) { @@ -57,9 +52,4 @@ public class DateRangeParser extends RangeParser { } return factory; } - - @Override - public DateRangeAggregatorBuilder getFactoryPrototypes() { - return DateRangeAggregatorBuilder.PROTOTYPE; - } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ipv4/IPv4RangeAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ipv4/IPv4RangeAggregatorBuilder.java index 7c867d56fa1..80989d5930c 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ipv4/IPv4RangeAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/ipv4/IPv4RangeAggregatorBuilder.java @@ -40,16 +40,23 @@ import java.io.IOException; import java.util.Objects; public class IPv4RangeAggregatorBuilder extends AbstractRangeBuilder { - - static final IPv4RangeAggregatorBuilder PROTOTYPE = new IPv4RangeAggregatorBuilder(""); + public static final String NAME = InternalIPv4Range.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); public IPv4RangeAggregatorBuilder(String name) { super(name, InternalIPv4Range.FACTORY); } + /** + * Read from a stream. + */ + public IPv4RangeAggregatorBuilder(StreamInput in) throws IOException { + super(in, InternalIPv4Range.FACTORY, Range.PROTOTYPE::readFrom); + } + @Override public String getWriteableName() { - return InternalIPv4Range.TYPE.name(); + return NAME; } /** @@ -132,16 +139,6 @@ public class IPv4RangeAggregatorBuilder extends AbstractRangeBuilder Date: Thu, 14 Apr 2016 14:18:21 -0400 Subject: [PATCH 008/561] Cut derivative aggregation to registerPipelineAggregation and remove its PROTOTYPE. --- .../elasticsearch/search/SearchModule.java | 5 +- .../aggregations/pipeline/BucketHelpers.java | 5 +- .../pipeline/PipelineAggregator.java | 14 +- .../pipeline/PipelineAggregatorBuilder.java | 74 ++++++---- .../pipeline/derivative/DerivativeParser.java | 112 --------------- .../DerivativePipelineAggregatorBuilder.java | 131 ++++++++++++++---- 6 files changed, 167 insertions(+), 174 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativeParser.java diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index 18eba2f9cbf..44b504d777f 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -202,8 +202,8 @@ import org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelec import org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumParser; import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregator; -import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativeParser; import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregator; +import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.derivative.InternalDerivative; import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgParser; import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregator; @@ -478,7 +478,8 @@ public class SearchModule extends AbstractModule { registerAggregation(ChildrenAggregatorBuilder::new, ChildrenAggregatorBuilder::parse, ChildrenAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerPipelineParser(new DerivativeParser()); + registerPipelineAggregation(DerivativePipelineAggregatorBuilder::new, DerivativePipelineAggregatorBuilder::parse, + DerivativePipelineAggregatorBuilder.AGGREGATION_NAME_FIELD); registerPipelineParser(new MaxBucketParser()); registerPipelineParser(new MinBucketParser()); registerPipelineParser(new AvgBucketParser()); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketHelpers.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketHelpers.java index 24d2913bfc0..98d364bcd07 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketHelpers.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketHelpers.java @@ -29,7 +29,6 @@ import org.elasticsearch.search.aggregations.AggregationExecutionException; import org.elasticsearch.search.aggregations.InternalMultiBucketAggregation; import org.elasticsearch.search.aggregations.InvalidAggregationPathException; import org.elasticsearch.search.aggregations.metrics.InternalNumericMetricsAggregation; -import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativeParser; import org.elasticsearch.search.aggregations.support.AggregationPath; import java.io.IOException; @@ -157,7 +156,7 @@ public class BucketHelpers { try { Object propertyValue = bucket.getProperty(agg.getName(), aggPathAsList); if (propertyValue == null) { - throw new AggregationExecutionException(DerivativeParser.BUCKETS_PATH.getPreferredName() + throw new AggregationExecutionException(PipelineAggregatorBuilder.BUCKETS_PATH_FIELD.getPreferredName() + " must reference either a number value or a single value numeric metric aggregation"); } else { double value; @@ -166,7 +165,7 @@ public class BucketHelpers { } else if (propertyValue instanceof InternalNumericMetricsAggregation.SingleValue) { value = ((InternalNumericMetricsAggregation.SingleValue) propertyValue).value(); } else { - throw new AggregationExecutionException(DerivativeParser.BUCKETS_PATH.getPreferredName() + throw new AggregationExecutionException(PipelineAggregatorBuilder.BUCKETS_PATH_FIELD.getPreferredName() + " must reference either a number value or a single value numeric metric aggregation, got: " + propertyValue.getClass().getCanonicalName()); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregator.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregator.java index e9a102438a3..b010b6d28ea 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregator.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregator.java @@ -35,11 +35,9 @@ import java.util.Map; public abstract class PipelineAggregator implements Streamable { /** - * Parses the pipeline aggregation request and creates the appropriate - * pipeline aggregator factory for it. - * - * @see PipelineAggregatorBuilder + * Parse the {@link PipelineAggregatorBuilder} from a {@link QueryParseContext}. */ + @FunctionalInterface public static interface Parser { public static final ParseField BUCKETS_PATH = new ParseField("buckets_path"); @@ -50,7 +48,9 @@ public abstract class PipelineAggregator implements Streamable { /** * @return The aggregation type this parser is associated with. */ - String type(); + default String type() { + throw new UnsupportedOperationException(); // NORELEASE remove before 5.0.0GA + } /** * Returns the pipeline aggregator factory with which this parser is @@ -71,7 +71,9 @@ public abstract class PipelineAggregator implements Streamable { * @return an empty {@link PipelineAggregatorBuilder} instance for this * parser that can be used for deserialization */ - PipelineAggregatorBuilder getFactoryPrototype(); + default PipelineAggregatorBuilder getFactoryPrototype() { + throw new UnsupportedOperationException(); // NORELEASE remove before 5.0.0GA + } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregatorBuilder.java index 73adf489f97..9e943412232 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregatorBuilder.java @@ -19,10 +19,10 @@ package org.elasticsearch.search.aggregations.pipeline; import org.elasticsearch.action.support.ToXContentToBytes; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.NamedWriteable; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.search.aggregations.AggregatorFactory; @@ -37,7 +37,12 @@ import java.util.Objects; * specific type. */ public abstract class PipelineAggregatorBuilder> extends ToXContentToBytes - implements NamedWriteable>, ToXContent { + implements NamedWriteable> { + + /** + * Field shared by many parsers. + */ + public static final ParseField BUCKETS_PATH_FIELD = new ParseField("buckets_path"); protected final String name; protected final String type; @@ -52,7 +57,7 @@ public abstract class PipelineAggregatorBuilder readFrom(StreamInput in) throws IOException { + String name = in.readString(); + String[] bucketsPaths = in.readStringArray(); + PipelineAggregatorBuilder factory = doReadFrom(name, bucketsPaths, in); + factory.metaData = in.readMap(); + return factory; + } + + protected PipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException { + throw new UnsupportedOperationException(); // NORELEASE remove this before 5.0.0GA, when all the aggregations have been migrated + } + public String name() { return name; } @@ -114,32 +161,11 @@ public abstract class PipelineAggregatorBuilder readFrom(StreamInput in) throws IOException { - String name = in.readString(); - String[] bucketsPaths = in.readStringArray(); - PipelineAggregatorBuilder factory = doReadFrom(name, bucketsPaths, in); - factory.metaData = in.readMap(); - return factory; - } - - protected abstract PipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException; - @Override public final XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(getName()); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativeParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativeParser.java deleted file mode 100644 index e08efc4a23f..00000000000 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativeParser.java +++ /dev/null @@ -1,112 +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.aggregations.pipeline.derivative; - -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParsingException; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.query.QueryParseContext; -import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; -import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -public class DerivativeParser implements PipelineAggregator.Parser { - - public static final ParseField FORMAT = new ParseField("format"); - public static final ParseField GAP_POLICY = new ParseField("gap_policy"); - public static final ParseField UNIT = new ParseField("unit"); - - @Override - public String type() { - return DerivativePipelineAggregator.TYPE.name(); - } - - @Override - public DerivativePipelineAggregatorBuilder parse(String pipelineAggregatorName, QueryParseContext context) throws IOException { - XContentParser parser = context.parser(); - XContentParser.Token token; - String currentFieldName = null; - String[] bucketsPaths = null; - String format = null; - String units = null; - GapPolicy gapPolicy = null; - - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - currentFieldName = parser.currentName(); - } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, FORMAT)) { - format = parser.text(); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { - bucketsPaths = new String[] { parser.text() }; - } else if (context.parseFieldMatcher().match(currentFieldName, GAP_POLICY)) { - gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation()); - } else if (context.parseFieldMatcher().match(currentFieldName, UNIT)) { - units = parser.text(); - } else { - throw new ParsingException(parser.getTokenLocation(), - "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "]."); - } - } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { - List paths = new ArrayList<>(); - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - String path = parser.text(); - paths.add(path); - } - bucketsPaths = paths.toArray(new String[paths.size()]); - } else { - throw new ParsingException(parser.getTokenLocation(), - "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "]."); - } - } else { - throw new ParsingException(parser.getTokenLocation(), - "Unexpected token " + token + " in [" + pipelineAggregatorName + "]."); - } - } - - if (bucketsPaths == null) { - throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + BUCKETS_PATH.getPreferredName() - + "] for derivative aggregation [" + pipelineAggregatorName + "]"); - } - - DerivativePipelineAggregatorBuilder factory = - new DerivativePipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]); - if (format != null) { - factory.format(format); - } - if (gapPolicy != null) { - factory.gapPolicy(gapPolicy); - } - if (units != null) { - factory.unit(units); - } - return factory; - } - - @Override - public DerivativePipelineAggregatorBuilder getFactoryPrototype() { - return DerivativePipelineAggregatorBuilder.PROTOTYPE; - } - -} diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java index ffcc91c51dc..847261d5c48 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java @@ -19,11 +19,15 @@ package org.elasticsearch.search.aggregations.pipeline.derivative; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.rounding.DateTimeUnit; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.bucket.histogram.AbstractHistogramAggregatorFactory; @@ -34,13 +38,18 @@ import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; public class DerivativePipelineAggregatorBuilder extends PipelineAggregatorBuilder { - - static final DerivativePipelineAggregatorBuilder PROTOTYPE = new DerivativePipelineAggregatorBuilder("", ""); + public static final String NAME = DerivativePipelineAggregator.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); + + private static final ParseField FORMAT_FIELD = new ParseField("format"); + private static final ParseField GAP_POLICY_FIELD = new ParseField("gap_policy"); + private static final ParseField UNIT_FIELD = new ParseField("unit"); private String format; private GapPolicy gapPolicy = GapPolicy.SKIP; @@ -54,6 +63,34 @@ public class DerivativePipelineAggregatorBuilder extends PipelineAggregatorBuild super(name, DerivativePipelineAggregator.TYPE.name(), bucketsPaths); } + /** + * Read from a stream. + */ + public DerivativePipelineAggregatorBuilder(StreamInput in) throws IOException { + super(in, DerivativePipelineAggregator.TYPE.name()); + format = in.readOptionalString(); + if (in.readBoolean()) { + gapPolicy = GapPolicy.readFrom(in); + } + units = in.readOptionalString(); + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + out.writeOptionalString(format); + boolean hasGapPolicy = gapPolicy != null; + out.writeBoolean(hasGapPolicy); + if (hasGapPolicy) { + gapPolicy.writeTo(out); + } + out.writeOptionalString(units); + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; + } + public DerivativePipelineAggregatorBuilder format(String format) { if (format == null) { throw new IllegalArgumentException("[format] must not be null: [" + name + "]"); @@ -140,42 +177,82 @@ public class DerivativePipelineAggregatorBuilder extends PipelineAggregatorBuild } } - @Override - protected DerivativePipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException { - DerivativePipelineAggregatorBuilder factory = new DerivativePipelineAggregatorBuilder(name, bucketsPaths); - factory.format = in.readOptionalString(); - if (in.readBoolean()) { - factory.gapPolicy = GapPolicy.readFrom(in); - } - factory.units = in.readOptionalString(); - return factory; - } - - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeOptionalString(format); - boolean hasGapPolicy = gapPolicy != null; - out.writeBoolean(hasGapPolicy); - if (hasGapPolicy) { - gapPolicy.writeTo(out); - } - out.writeOptionalString(units); - } - @Override protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException { if (format != null) { - builder.field(DerivativeParser.FORMAT.getPreferredName(), format); + builder.field(FORMAT_FIELD.getPreferredName(), format); } if (gapPolicy != null) { - builder.field(DerivativeParser.GAP_POLICY.getPreferredName(), gapPolicy.getName()); + builder.field(GAP_POLICY_FIELD.getPreferredName(), gapPolicy.getName()); } if (units != null) { - builder.field(DerivativeParser.UNIT.getPreferredName(), units); + builder.field(FORMAT_FIELD.getPreferredName(), units); } return builder; } + public static DerivativePipelineAggregatorBuilder parse(String pipelineAggregatorName, QueryParseContext context) throws IOException { + XContentParser parser = context.parser(); + XContentParser.Token token; + String currentFieldName = null; + String[] bucketsPaths = null; + String format = null; + String units = null; + GapPolicy gapPolicy = null; + + while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { + if (token == XContentParser.Token.FIELD_NAME) { + currentFieldName = parser.currentName(); + } else if (token == XContentParser.Token.VALUE_STRING) { + if (context.parseFieldMatcher().match(currentFieldName, FORMAT_FIELD)) { + format = parser.text(); + } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH_FIELD)) { + bucketsPaths = new String[] { parser.text() }; + } else if (context.parseFieldMatcher().match(currentFieldName, GAP_POLICY_FIELD)) { + gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation()); + } else if (context.parseFieldMatcher().match(currentFieldName, UNIT_FIELD)) { + units = parser.text(); + } else { + throw new ParsingException(parser.getTokenLocation(), + "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "]."); + } + } else if (token == XContentParser.Token.START_ARRAY) { + if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH_FIELD)) { + List paths = new ArrayList<>(); + while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { + String path = parser.text(); + paths.add(path); + } + bucketsPaths = paths.toArray(new String[paths.size()]); + } else { + throw new ParsingException(parser.getTokenLocation(), + "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "]."); + } + } else { + throw new ParsingException(parser.getTokenLocation(), + "Unexpected token " + token + " in [" + pipelineAggregatorName + "]."); + } + } + + if (bucketsPaths == null) { + throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + BUCKETS_PATH_FIELD.getPreferredName() + + "] for derivative aggregation [" + pipelineAggregatorName + "]"); + } + + DerivativePipelineAggregatorBuilder factory = + new DerivativePipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]); + if (format != null) { + factory.format(format); + } + if (gapPolicy != null) { + factory.gapPolicy(gapPolicy); + } + if (units != null) { + factory.unit(units); + } + return factory; + } + @Override protected boolean doEquals(Object obj) { DerivativePipelineAggregatorBuilder other = (DerivativePipelineAggregatorBuilder) obj; From a36b6138d7045096df243f8affdf200d0dbe473e Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 14 Apr 2016 14:41:55 -0400 Subject: [PATCH 009/561] Cut avg aggregation to registerAggregation and remove its PROTOTYPE Relates to #17085 --- .../elasticsearch/search/SearchModule.java | 3 +- .../aggregations/AggregatorBuilder.java | 1 + .../metrics/avg/AvgAggregatorBuilder.java | 43 ++++++++++++------- .../aggregations/metrics/avg/AvgParser.java | 11 ----- .../ValuesSourceAggregatorBuilder.java | 13 +++++- 5 files changed, 41 insertions(+), 30 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index 44b504d777f..5aa8764d9f9 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -148,6 +148,7 @@ import org.elasticsearch.search.aggregations.bucket.terms.LongTerms; import org.elasticsearch.search.aggregations.bucket.terms.StringTerms; import org.elasticsearch.search.aggregations.bucket.terms.TermsParser; import org.elasticsearch.search.aggregations.bucket.terms.UnmappedTerms; +import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.avg.AvgParser; import org.elasticsearch.search.aggregations.metrics.avg.InternalAvg; import org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityParser; @@ -442,7 +443,7 @@ public class SearchModule extends AbstractModule { SignificanceHeuristicParserMapper significanceHeuristicParserMapper = new SignificanceHeuristicParserMapper(heuristicParsers); - registerAggregatorParser(new AvgParser()); + registerAggregation(AvgAggregatorBuilder::new, new AvgParser(), AvgAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregatorParser(new SumParser()); registerAggregatorParser(new MinParser()); registerAggregatorParser(new MaxParser()); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/AggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/AggregatorBuilder.java index 04fa29989db..165f047d252 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/AggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/AggregatorBuilder.java @@ -191,6 +191,7 @@ public abstract class AggregatorBuilder> extend @Override public String getWriteableName() { // NORELEASE remove this before 5.0.0GA - all builders will implement this method on their own. + assert usesNewStyleSerialization() == false: "migrated aggregations should just return their NAME"; return type.stream().toUtf8(); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregatorBuilder.java index 351069f79d9..fea1ddd8328 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgAggregatorBuilder.java @@ -19,47 +19,53 @@ package org.elasticsearch.search.aggregations.metrics.avg; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.ToXContent.Params; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; +import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric; import java.io.IOException; public class AvgAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { - - static final AvgAggregatorBuilder PROTOTYPE = new AvgAggregatorBuilder(""); + public static final String NAME = InternalAvg.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); public AvgAggregatorBuilder(String name) { super(name, InternalAvg.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); } + /** + * Read from a stream. + */ + public AvgAggregatorBuilder(StreamInput in) throws IOException { + super(in, InternalAvg.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC); + } + + @Override + protected void innerWriteTo(StreamOutput out) { + // Do nothing, no extra state to write to stream + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; + } + @Override protected AvgAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { return new AvgAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); } - @Override - protected AvgAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) { - return new AvgAggregatorBuilder(name); - } - - @Override - protected void innerWriteTo(StreamOutput out) { - // Do nothing, no extra state to write to stream - } - @Override public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { return builder; @@ -74,4 +80,9 @@ public class AvgAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly protected boolean innerEquals(Object obj) { return true; } + + @Override + public String getWriteableName() { + return NAME; + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgParser.java index f51e4070fd7..edb3d8f6620 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/avg/AvgParser.java @@ -37,11 +37,6 @@ public class AvgParser extends NumericValuesSourceParser { super(true, true, false); } - @Override - public String type() { - return InternalAvg.TYPE.name(); - } - @Override protected boolean token(String aggregationName, String currentFieldName, XContentParser.Token token, XContentParser parser, ParseFieldMatcher parseFieldMatcher, Map otherOptions) throws IOException { @@ -53,10 +48,4 @@ public class AvgParser extends NumericValuesSourceParser { ValueType targetValueType, Map otherOptions) { return new AvgAggregatorBuilder(aggregationName); } - - @Override - public AvgAggregatorBuilder getFactoryPrototypes() { - return AvgAggregatorBuilder.PROTOTYPE; - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorBuilder.java index 486fae0d52a..cfec5a8962b 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorBuilder.java @@ -21,7 +21,6 @@ package org.elasticsearch.search.aggregations.support; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.joda.FormatDateTimeFormatter; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.index.fielddata.IndexFieldData; import org.elasticsearch.index.fielddata.IndexGeoPointFieldData; @@ -32,9 +31,9 @@ import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.SearchScript; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AggregationInitializationException; -import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.AggregatorBuilder; import org.elasticsearch.search.aggregations.AggregatorFactories; +import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.internal.SearchContext; @@ -57,6 +56,13 @@ public abstract class ValuesSourceAggregatorBuilder Date: Fri, 15 Apr 2016 08:51:22 -0400 Subject: [PATCH 010/561] Fix bad toXContent for derivative aggregation I busted it in the last commit. --- .../derivative/DerivativePipelineAggregatorBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java index 847261d5c48..f897bc6eafd 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java @@ -186,7 +186,7 @@ public class DerivativePipelineAggregatorBuilder extends PipelineAggregatorBuild builder.field(GAP_POLICY_FIELD.getPreferredName(), gapPolicy.getName()); } if (units != null) { - builder.field(FORMAT_FIELD.getPreferredName(), units); + builder.field(UNIT_FIELD.getPreferredName(), units); } return builder; } From cf80b00507d94b61ce1eeb25866cf4277aac00db Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 14 Apr 2016 14:53:43 -0400 Subject: [PATCH 011/561] Cut filters aggregation to registerAggregation and remove its PROTOTYPE. --- .../elasticsearch/search/SearchModule.java | 5 +- .../filters/FiltersAggregatorBuilder.java | 184 ++++++++++++++---- .../bucket/filters/FiltersParser.java | 150 -------------- 3 files changed, 148 insertions(+), 191 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersParser.java diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index 5aa8764d9f9..d6970e1b84b 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -105,7 +105,7 @@ import org.elasticsearch.search.aggregations.bucket.children.ChildrenAggregatorB import org.elasticsearch.search.aggregations.bucket.children.InternalChildren; import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter; -import org.elasticsearch.search.aggregations.bucket.filters.FiltersParser; +import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.filters.InternalFilters; import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGridParser; import org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGrid; @@ -456,7 +456,8 @@ public class SearchModule extends AbstractModule { registerAggregatorParser(new GlobalParser()); registerAggregatorParser(new MissingParser()); registerAggregation(FilterAggregatorBuilder::new, FilterAggregatorBuilder::parse, FilterAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerAggregatorParser(new FiltersParser(queryParserRegistry)); + registerAggregation(FiltersAggregatorBuilder::new, (n, c) -> FiltersAggregatorBuilder.parse(queryParserRegistry, n, c), + FiltersAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregatorParser(new SamplerParser()); registerAggregatorParser(new DiversifiedSamplerParser()); registerAggregatorParser(new TermsParser()); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregatorBuilder.java index 41e99db44be..d802bd685ad 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregatorBuilder.java @@ -19,11 +19,16 @@ package org.elasticsearch.search.aggregations.bucket.filters; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.query.MatchAllQueryBuilder; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryBuilder; +import org.elasticsearch.index.query.QueryBuilders; +import org.elasticsearch.index.query.QueryParseContext; +import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.search.aggregations.AggregatorBuilder; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; import org.elasticsearch.search.aggregations.AggregatorFactory; @@ -37,9 +42,15 @@ import java.util.Collections; import java.util.List; import java.util.Objects; -public class FiltersAggregatorBuilder extends AggregatorBuilder { +import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; - static final FiltersAggregatorBuilder PROTOTYPE = new FiltersAggregatorBuilder("", new MatchAllQueryBuilder()); +public class FiltersAggregatorBuilder extends AggregatorBuilder { + public static final String NAME = InternalFilters.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); + + private static final ParseField FILTERS_FIELD = new ParseField("filters"); + private static final ParseField OTHER_BUCKET_FIELD = new ParseField("other_bucket"); + private static final ParseField OTHER_BUCKET_KEY_FIELD = new ParseField("other_bucket_key"); private final List filters; private final boolean keyed; @@ -80,6 +91,49 @@ public class FiltersAggregatorBuilder extends AggregatorBuilder(filtersSize); + if (keyed) { + for (int i = 0; i < filtersSize; i++) { + filters.add(KeyedFilter.PROTOTYPE.readFrom(in)); + } + } else { + for (int i = 0; i < filtersSize; i++) { + filters.add(new KeyedFilter(String.valueOf(i), in.readQuery())); + } + } + otherBucket = in.readBoolean(); + otherBucketKey = in.readString(); + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + out.writeBoolean(keyed); + out.writeVInt(filters.size()); + if (keyed) { + for (KeyedFilter keyedFilter : filters) { + keyedFilter.writeTo(out); + } + } else { + for (KeyedFilter keyedFilter : filters) { + out.writeQuery(keyedFilter.filter()); + } + } + out.writeBoolean(otherBucket); + out.writeString(otherBucketKey); + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; + } + /** * Set whether to include a bucket for documents not matching any filter */ @@ -151,45 +205,92 @@ public class FiltersAggregatorBuilder extends AggregatorBuilder filters = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - filters.add(KeyedFilter.PROTOTYPE.readFrom(in)); - } - factory = new FiltersAggregatorBuilder(name, filters); - } else { - int size = in.readVInt(); - QueryBuilder[] filters = new QueryBuilder[size]; - for (int i = 0; i < size; i++) { - filters[i] = in.readQuery(); - } - factory = new FiltersAggregatorBuilder(name, filters); - } - factory.otherBucket = in.readBoolean(); - factory.otherBucketKey = in.readString(); - return factory; - } + public static FiltersAggregatorBuilder parse(IndicesQueriesRegistry queriesRegistry, String aggregationName, QueryParseContext context) + throws IOException { + XContentParser parser = context.parser(); - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeBoolean(keyed); - if (keyed) { - out.writeVInt(filters.size()); - for (KeyedFilter keyedFilter : filters) { - keyedFilter.writeTo(out); - } - } else { - out.writeVInt(filters.size()); - for (KeyedFilter keyedFilter : filters) { - out.writeQuery(keyedFilter.filter()); + List keyedFilters = null; + List> nonKeyedFilters = null; + + XContentParser.Token token = null; + String currentFieldName = null; + String otherBucketKey = null; + Boolean otherBucket = false; + while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { + if (token == XContentParser.Token.FIELD_NAME) { + currentFieldName = parser.currentName(); + } else if (token == XContentParser.Token.VALUE_BOOLEAN) { + if (context.parseFieldMatcher().match(currentFieldName, OTHER_BUCKET_FIELD)) { + otherBucket = parser.booleanValue(); + } else { + throw new ParsingException(parser.getTokenLocation(), + "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); + } + } else if (token == XContentParser.Token.VALUE_STRING) { + if (context.parseFieldMatcher().match(currentFieldName, OTHER_BUCKET_KEY_FIELD)) { + otherBucketKey = parser.text(); + } else { + throw new ParsingException(parser.getTokenLocation(), + "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); + } + } else if (token == XContentParser.Token.START_OBJECT) { + if (context.parseFieldMatcher().match(currentFieldName, FILTERS_FIELD)) { + keyedFilters = new ArrayList<>(); + String key = null; + while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { + if (token == XContentParser.Token.FIELD_NAME) { + key = parser.currentName(); + } else { + QueryParseContext queryParseContext = new QueryParseContext(queriesRegistry); + queryParseContext.reset(parser); + queryParseContext.parseFieldMatcher(context.parseFieldMatcher()); + QueryBuilder filter = queryParseContext.parseInnerQueryBuilder(); + keyedFilters.add(new FiltersAggregator.KeyedFilter(key, filter == null ? matchAllQuery() : filter)); + } + } + } else { + throw new ParsingException(parser.getTokenLocation(), + "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); + } + } else if (token == XContentParser.Token.START_ARRAY) { + if (context.parseFieldMatcher().match(currentFieldName, FILTERS_FIELD)) { + nonKeyedFilters = new ArrayList<>(); + while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { + QueryParseContext queryParseContext = new QueryParseContext(queriesRegistry); + queryParseContext.reset(parser); + queryParseContext.parseFieldMatcher(context.parseFieldMatcher()); + QueryBuilder filter = queryParseContext.parseInnerQueryBuilder(); + nonKeyedFilters.add(filter == null ? QueryBuilders.matchAllQuery() : filter); + } + } else { + throw new ParsingException(parser.getTokenLocation(), + "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); + } + } else { + throw new ParsingException(parser.getTokenLocation(), + "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); } } - out.writeBoolean(otherBucket); - out.writeString(otherBucketKey); + + if (otherBucket && otherBucketKey == null) { + otherBucketKey = "_other_"; + } + + FiltersAggregatorBuilder factory; + if (keyedFilters != null) { + factory = new FiltersAggregatorBuilder(aggregationName, + keyedFilters.toArray(new FiltersAggregator.KeyedFilter[keyedFilters.size()])); + } else { + factory = new FiltersAggregatorBuilder(aggregationName, + nonKeyedFilters.toArray(new QueryBuilder[nonKeyedFilters.size()])); + } + if (otherBucket != null) { + factory.otherBucket(otherBucket); + } + if (otherBucketKey != null) { + factory.otherBucketKey(otherBucketKey); + } + return factory; } @Override @@ -205,4 +306,9 @@ public class FiltersAggregatorBuilder extends AggregatorBuilder keyedFilters = null; - List> nonKeyedFilters = null; - - XContentParser.Token token = null; - String currentFieldName = null; - String otherBucketKey = null; - Boolean otherBucket = false; - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - currentFieldName = parser.currentName(); - } else if (token == XContentParser.Token.VALUE_BOOLEAN) { - if (context.parseFieldMatcher().match(currentFieldName, OTHER_BUCKET_FIELD)) { - otherBucket = parser.booleanValue(); - } else { - throw new ParsingException(parser.getTokenLocation(), - "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); - } - } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, OTHER_BUCKET_KEY_FIELD)) { - otherBucketKey = parser.text(); - } else { - throw new ParsingException(parser.getTokenLocation(), - "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); - } - } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, FILTERS_FIELD)) { - keyedFilters = new ArrayList<>(); - String key = null; - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - key = parser.currentName(); - } else { - QueryParseContext queryParseContext = new QueryParseContext(queriesRegistry); - queryParseContext.reset(parser); - queryParseContext.parseFieldMatcher(context.parseFieldMatcher()); - QueryBuilder filter = queryParseContext.parseInnerQueryBuilder(); - keyedFilters - .add(new FiltersAggregator.KeyedFilter(key, filter == null ? QueryBuilders.matchAllQuery() : filter)); - } - } - } else { - throw new ParsingException(parser.getTokenLocation(), - "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); - } - } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, FILTERS_FIELD)) { - nonKeyedFilters = new ArrayList<>(); - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - QueryParseContext queryParseContext = new QueryParseContext(queriesRegistry); - queryParseContext.reset(parser); - queryParseContext.parseFieldMatcher(context.parseFieldMatcher()); - QueryBuilder filter = queryParseContext.parseInnerQueryBuilder(); - nonKeyedFilters.add(filter == null ? QueryBuilders.matchAllQuery() : filter); - } - } else { - throw new ParsingException(parser.getTokenLocation(), - "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); - } - } else { - throw new ParsingException(parser.getTokenLocation(), - "Unknown key for a " + token + " in [" + aggregationName + "]: [" + currentFieldName + "]."); - } - } - - if (otherBucket && otherBucketKey == null) { - otherBucketKey = "_other_"; - } - - FiltersAggregatorBuilder factory; - if (keyedFilters != null) { - factory = new FiltersAggregatorBuilder(aggregationName, - keyedFilters.toArray(new FiltersAggregator.KeyedFilter[keyedFilters.size()])); - } else { - factory = new FiltersAggregatorBuilder(aggregationName, - nonKeyedFilters.toArray(new QueryBuilder[nonKeyedFilters.size()])); - } - if (otherBucket != null) { - factory.otherBucket(otherBucket); - } - if (otherBucketKey != null) { - factory.otherBucketKey(otherBucketKey); - } - return factory; - } - - @Override - public FiltersAggregatorBuilder getFactoryPrototypes() { - return FiltersAggregatorBuilder.PROTOTYPE; - } - -} From e3c65408eca609625f2730ded807034838269f8c Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 14 Apr 2016 15:34:11 -0400 Subject: [PATCH 012/561] Cut terms aggregation to registerAggregation and remove its PROTOTYPE. This is the first aggregation builder that serializes its targetValueType so ValuesSourceAggregatorBuilder had to grow support for that. Relates to #17085 --- .../elasticsearch/search/SearchModule.java | 3 +- .../significant/SignificantTermsParser.java | 2 - .../bucket/terms/TermsAggregatorBuilder.java | 82 ++++++++++--------- .../bucket/terms/TermsParser.java | 13 --- .../aggregations/support/ValueType.java | 3 +- .../ValuesSourceAggregatorBuilder.java | 42 ++++++++-- 6 files changed, 85 insertions(+), 60 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index d6970e1b84b..c06fd014787 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -146,6 +146,7 @@ import org.elasticsearch.search.aggregations.bucket.significant.heuristics.Signi import org.elasticsearch.search.aggregations.bucket.terms.DoubleTerms; import org.elasticsearch.search.aggregations.bucket.terms.LongTerms; import org.elasticsearch.search.aggregations.bucket.terms.StringTerms; +import org.elasticsearch.search.aggregations.bucket.terms.TermsAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.terms.TermsParser; import org.elasticsearch.search.aggregations.bucket.terms.UnmappedTerms; import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregatorBuilder; @@ -460,7 +461,7 @@ public class SearchModule extends AbstractModule { FiltersAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregatorParser(new SamplerParser()); registerAggregatorParser(new DiversifiedSamplerParser()); - registerAggregatorParser(new TermsParser()); + registerAggregation(TermsAggregatorBuilder::new, new TermsParser(), TermsAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregatorParser(new SignificantTermsParser(significanceHeuristicParserMapper, queryParserRegistry)); registerAggregation(RangeAggregatorBuilder::new, new RangeParser(), RangeAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(DateRangeAggregatorBuilder::new, new DateRangeParser(), DateRangeAggregatorBuilder.AGGREGATION_NAME_FIELD); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsParser.java index f5f19115924..6f761ab752a 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsParser.java @@ -20,7 +20,6 @@ package org.elasticsearch.search.aggregations.bucket.significant; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentParser.Token; import org.elasticsearch.index.query.QueryBuilder; @@ -47,7 +46,6 @@ public class SignificantTermsParser extends AbstractTermsParser { private final SignificanceHeuristicParserMapper significanceHeuristicParserMapper; private final IndicesQueriesRegistry queriesRegistry; - @Inject public SignificantTermsParser(SignificanceHeuristicParserMapper significanceHeuristicParserMapper, IndicesQueriesRegistry queriesRegistry) { this.significanceHeuristicParserMapper = significanceHeuristicParserMapper; diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorBuilder.java index d0389601a87..3e86efbe19c 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/terms/TermsAggregatorBuilder.java @@ -38,13 +38,9 @@ import java.io.IOException; import java.util.List; import java.util.Objects; -/** - * - */ -/** - * - */ public class TermsAggregatorBuilder extends ValuesSourceAggregatorBuilder { + public static final String NAME = StringTerms.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); public static final ParseField EXECUTION_HINT_FIELD_NAME = new ParseField("execution_hint"); public static final ParseField SHARD_SIZE_FIELD_NAME = new ParseField("shard_size"); @@ -57,8 +53,6 @@ public class TermsAggregatorBuilder extends ValuesSourceAggregatorBuilder { return description; } - @Override - public ValueType readFrom(StreamInput in) throws IOException { + public static ValueType readFromStream(StreamInput in) throws IOException { byte id = in.readByte(); for (ValueType valueType : values()) { if (id == valueType.id) { diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorBuilder.java index cfec5a8962b..840befe1b23 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorBuilder.java @@ -89,19 +89,39 @@ public abstract class ValuesSourceAggregatorBuilder factory = innerReadFrom(name, valuesSourceType, targetValueType, in); factory.field = in.readOptionalString(); @@ -163,7 +187,7 @@ public abstract class ValuesSourceAggregatorBuilder Date: Thu, 14 Apr 2016 15:47:03 +0200 Subject: [PATCH 013/561] Remove ParseFieldMatcher from AbstractXContentParser Currently we are able to set a ParseFieldMatcher on XContentParsers, mainly to conveniently carry it around to be available where the actual parsing happens. This was just recently introduced together with ObjectParser so that ObjectParser can make use of deprecation logging and throwing errors while parsing. This however is trappy because we create parsers in so many places in the code and it is easy to forget setting the right ParseFieldMatcher. Instead we should hold the ParseFieldMatcher only in the parse contexts (e.g. QueryParseContext). This PR removes the ParseFieldMatcher from XContentParser. ObjectParser can still make use of it because we can make the otherwise unbounded `context` type to extend an interface that makes sure contexts used in ObjectParser can supply a ParseFieldMatcher. Contexts in ObjectParser are now no longer optional, but it is sufficient to pass in a small lambda expression in places where no other context is available. Relates to #17417 --- .../ClusterAllocationExplainRequest.java | 9 +- .../reroute/ClusterRerouteRequest.java | 6 +- .../cluster/routing/AllocationId.java | 7 +- .../AbstractAllocateAllocationCommand.java | 5 +- ...AllocateEmptyPrimaryAllocationCommand.java | 7 +- .../AllocateReplicaAllocationCommand.java | 7 +- ...AllocateStalePrimaryAllocationCommand.java | 7 +- .../command/AllocationCommands.java | 6 +- .../command/BasePrimaryAllocationCommand.java | 5 +- .../common/ParseFieldMatcherSupplier.java | 36 +++++++ .../common/xcontent/ObjectParser.java | 23 ++--- .../common/xcontent/ParseFieldRegistry.java | 14 +-- .../common/xcontent/XContentParser.java | 16 +-- .../support/AbstractXContentParser.java | 11 --- .../index/query/QueryParseContext.java | 12 +-- .../index/query/QueryShardContext.java | 5 +- .../FunctionScoreQueryBuilder.java | 6 +- .../elasticsearch/ingest/IngestMetadata.java | 7 +- .../ingest/PipelineConfiguration.java | 6 +- .../aggregations/AggregatorParsers.java | 18 ++-- .../CompletionSuggestionBuilder.java | 10 +- .../suggest/completion/FuzzyOptions.java | 8 +- .../suggest/completion/RegexOptions.java | 8 +- .../context/CategoryQueryContext.java | 6 +- .../completion/context/GeoQueryContext.java | 6 +- .../DirectCandidateGeneratorBuilder.java | 4 +- .../allocation/AllocationCommandsTests.java | 3 +- .../common/xcontent/ObjectParserTests.java | 99 ++++++++++--------- .../search/SearchModuleTests.java | 8 +- .../aggregations/BaseAggregationTestCase.java | 2 +- .../BasePipelineAggregationTestCase.java | 2 +- .../pipeline/moving/avg/MovAvgTests.java | 5 +- .../search/sort/SortParserTests.java | 40 ++++++-- .../index/reindex/RestReindexAction.java | 13 ++- 34 files changed, 245 insertions(+), 182 deletions(-) create mode 100644 core/src/main/java/org/elasticsearch/common/ParseFieldMatcherSupplier.java diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java index 11722821efb..4d143c437c3 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/allocation/ClusterAllocationExplainRequest.java @@ -24,14 +24,14 @@ import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.master.MasterNodeRequest; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.Strings; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; -import java.util.Objects; import static org.elasticsearch.action.ValidateActions.addValidationError; @@ -40,7 +40,8 @@ import static org.elasticsearch.action.ValidateActions.addValidationError; */ public class ClusterAllocationExplainRequest extends MasterNodeRequest { - private static ObjectParser PARSER = new ObjectParser("cluster/allocation/explain"); + private static ObjectParser PARSER = new ObjectParser( + "cluster/allocation/explain"); static { PARSER.declareString(ClusterAllocationExplainRequest::setIndex, new ParseField("index")); PARSER.declareInt(ClusterAllocationExplainRequest::setShard, new ParseField("shard")); @@ -148,7 +149,7 @@ public class ClusterAllocationExplainRequest extends MasterNodeRequest ParseFieldMatcher.STRICT); Exception e = req.validate(); if (e != null) { throw new ElasticsearchParseException("'index', 'shard', and 'primary' must be specified in allocation explain request", e); diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequest.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequest.java index fc371b9c1f0..a241f01ea28 100644 --- a/core/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequest.java +++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequest.java @@ -25,17 +25,14 @@ import org.elasticsearch.action.support.master.AcknowledgedRequest; import org.elasticsearch.cluster.routing.allocation.command.AllocationCommand; import org.elasticsearch.cluster.routing.allocation.command.AllocationCommandRegistry; import org.elasticsearch.cluster.routing.allocation.command.AllocationCommands; -import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; -import java.util.List; /** * Request to submit cluster reroute allocation commands @@ -105,7 +102,6 @@ public class ClusterRerouteRequest extends AcknowledgedRequest ALLOCATION_ID_PARSER = new ObjectParser<>("allocationId"); + private static final ObjectParser ALLOCATION_ID_PARSER = new ObjectParser<>( + "allocationId"); static { ALLOCATION_ID_PARSER.declareString(AllocationId.Builder::setId, new ParseField(ID_KEY)); @@ -198,6 +201,6 @@ public class AllocationId implements ToXContent { } public static AllocationId fromXContent(XContentParser parser) throws IOException { - return ALLOCATION_ID_PARSER.parse(parser, new AllocationId.Builder()).build(); + return ALLOCATION_ID_PARSER.parse(parser, new AllocationId.Builder(), () -> ParseFieldMatcher.STRICT).build(); } } diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AbstractAllocateAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AbstractAllocateAllocationCommand.java index 28a829b5af9..50e71c5094a 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AbstractAllocateAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AbstractAllocateAllocationCommand.java @@ -28,6 +28,7 @@ import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ObjectParser; @@ -47,8 +48,8 @@ public abstract class AbstractAllocateAllocationCommand implements AllocationCom private static final String SHARD_FIELD = "shard"; private static final String NODE_FIELD = "node"; - protected static > ObjectParser createAllocateParser(String command) { - ObjectParser parser = new ObjectParser<>(command); + protected static > ObjectParser createAllocateParser(String command) { + ObjectParser parser = new ObjectParser<>(command); parser.declareString(Builder::setIndex, new ParseField(INDEX_FIELD)); parser.declareInt(Builder::setShard, new ParseField(SHARD_FIELD)); parser.declareString(Builder::setNode, new ParseField(NODE_FIELD)); diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateEmptyPrimaryAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateEmptyPrimaryAllocationCommand.java index 4ee0294faaf..74e3a18efbc 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateEmptyPrimaryAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateEmptyPrimaryAllocationCommand.java @@ -28,6 +28,8 @@ import org.elasticsearch.cluster.routing.allocation.RerouteExplanation; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentParser; @@ -45,7 +47,8 @@ public class AllocateEmptyPrimaryAllocationCommand extends BasePrimaryAllocation public static final String NAME = "allocate_empty_primary"; public static final ParseField COMMAND_NAME_FIELD = new ParseField(NAME); - private static final ObjectParser EMPTY_PRIMARY_PARSER = BasePrimaryAllocationCommand.createAllocatePrimaryParser(NAME); + private static final ObjectParser EMPTY_PRIMARY_PARSER = BasePrimaryAllocationCommand + .createAllocatePrimaryParser(NAME); /** * Creates a new {@link AllocateEmptyPrimaryAllocationCommand} @@ -78,7 +81,7 @@ public class AllocateEmptyPrimaryAllocationCommand extends BasePrimaryAllocation @Override public Builder parse(XContentParser parser) throws IOException { - return EMPTY_PRIMARY_PARSER.parse(parser, this); + return EMPTY_PRIMARY_PARSER.parse(parser, this, () -> ParseFieldMatcher.STRICT); } @Override diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateReplicaAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateReplicaAllocationCommand.java index a62928fded4..b651580ea74 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateReplicaAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateReplicaAllocationCommand.java @@ -28,6 +28,8 @@ import org.elasticsearch.cluster.routing.allocation.RerouteExplanation; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentParser; @@ -44,7 +46,8 @@ public class AllocateReplicaAllocationCommand extends AbstractAllocateAllocation public static final String NAME = "allocate_replica"; public static final ParseField COMMAND_NAME_FIELD = new ParseField(NAME); - private static final ObjectParser REPLICA_PARSER = createAllocateParser(NAME); + private static final ObjectParser REPLICA_PARSER = + createAllocateParser(NAME); /** * Creates a new {@link AllocateReplicaAllocationCommand} @@ -77,7 +80,7 @@ public class AllocateReplicaAllocationCommand extends AbstractAllocateAllocation @Override public Builder parse(XContentParser parser) throws IOException { - return REPLICA_PARSER.parse(parser, this); + return REPLICA_PARSER.parse(parser, this, () -> ParseFieldMatcher.STRICT); } @Override diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateStalePrimaryAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateStalePrimaryAllocationCommand.java index 438827d004e..5fad78d0360 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateStalePrimaryAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocateStalePrimaryAllocationCommand.java @@ -28,6 +28,8 @@ import org.elasticsearch.cluster.routing.allocation.RerouteExplanation; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.decider.Decision; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentParser; @@ -44,7 +46,8 @@ public class AllocateStalePrimaryAllocationCommand extends BasePrimaryAllocation public static final String NAME = "allocate_stale_primary"; public static final ParseField COMMAND_NAME_FIELD = new ParseField(NAME); - private static final ObjectParser STALE_PRIMARY_PARSER = BasePrimaryAllocationCommand.createAllocatePrimaryParser(NAME); + private static final ObjectParser STALE_PRIMARY_PARSER = BasePrimaryAllocationCommand + .createAllocatePrimaryParser(NAME); /** * Creates a new {@link AllocateStalePrimaryAllocationCommand} @@ -78,7 +81,7 @@ public class AllocateStalePrimaryAllocationCommand extends BasePrimaryAllocation @Override public Builder parse(XContentParser parser) throws IOException { - return STALE_PRIMARY_PARSER.parse(parser, this); + return STALE_PRIMARY_PARSER.parse(parser, this, () -> ParseFieldMatcher.STRICT); } @Override diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocationCommands.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocationCommands.java index f5a06fe78a9..10c43fac7d7 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocationCommands.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/AllocationCommands.java @@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation.command; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.cluster.routing.allocation.RoutingAllocation; import org.elasticsearch.cluster.routing.allocation.RoutingExplanations; +import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ToXContent; @@ -128,7 +129,8 @@ public class AllocationCommands { * @return {@link AllocationCommands} read * @throws IOException if something bad happens while reading the stream */ - public static AllocationCommands fromXContent(XContentParser parser, AllocationCommandRegistry registry) throws IOException { + public static AllocationCommands fromXContent(XContentParser parser, ParseFieldMatcher parseFieldMatcher, + AllocationCommandRegistry registry) throws IOException { AllocationCommands commands = new AllocationCommands(); XContentParser.Token token = parser.currentToken(); @@ -157,7 +159,7 @@ public class AllocationCommands { token = parser.nextToken(); String commandName = parser.currentName(); token = parser.nextToken(); - commands.add(registry.lookup(commandName, parser).fromXContent(parser)); + commands.add(registry.lookup(commandName, parser, parseFieldMatcher).fromXContent(parser)); // move to the end object one if (parser.nextToken() != XContentParser.Token.END_OBJECT) { throw new ElasticsearchParseException("allocation command is malformed, done parsing a command, but didn't get END_OBJECT, got [{}] instead", token); diff --git a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/BasePrimaryAllocationCommand.java b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/BasePrimaryAllocationCommand.java index bbb911c6f01..0013061e8ea 100644 --- a/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/BasePrimaryAllocationCommand.java +++ b/core/src/main/java/org/elasticsearch/cluster/routing/allocation/command/BasePrimaryAllocationCommand.java @@ -20,6 +20,7 @@ package org.elasticsearch.cluster.routing.allocation.command; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ObjectParser; @@ -34,8 +35,8 @@ public abstract class BasePrimaryAllocationCommand extends AbstractAllocateAlloc private static final String ACCEPT_DATA_LOSS_FIELD = "accept_data_loss"; - protected static > ObjectParser createAllocatePrimaryParser(String command) { - ObjectParser parser = AbstractAllocateAllocationCommand.createAllocateParser(command); + protected static > ObjectParser createAllocatePrimaryParser(String command) { + ObjectParser parser = AbstractAllocateAllocationCommand.createAllocateParser(command); parser.declareBoolean(Builder::setAcceptDataLoss, new ParseField(ACCEPT_DATA_LOSS_FIELD)); return parser; } diff --git a/core/src/main/java/org/elasticsearch/common/ParseFieldMatcherSupplier.java b/core/src/main/java/org/elasticsearch/common/ParseFieldMatcherSupplier.java new file mode 100644 index 00000000000..b2b7b51ffcb --- /dev/null +++ b/core/src/main/java/org/elasticsearch/common/ParseFieldMatcherSupplier.java @@ -0,0 +1,36 @@ +/* + * 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.common; + +import org.elasticsearch.index.query.QueryParseContext; +import org.elasticsearch.index.query.QueryShardContext; + +/** + * This interface should be implemented by classes like {@link QueryParseContext} or {@link QueryShardContext} that + * are able to carry a {@link ParseFieldMatcher}. + */ +@FunctionalInterface +public interface ParseFieldMatcherSupplier { + + /** + * @return the parseFieldMatcher + */ + ParseFieldMatcher parseFieldMatcher(); +} diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java index 311b93744ed..a9f6518211c 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java @@ -20,6 +20,7 @@ package org.elasticsearch.common.xcontent; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import java.io.IOException; @@ -51,7 +52,7 @@ import static org.elasticsearch.common.xcontent.XContentParser.Token.VALUE_STRIN * use the high level declare methods like {@link #declareString(BiConsumer, ParseField)} instead of {@link #declareField} which can be used * to implement exceptional parsing operations not covered by the high level methods. */ -public final class ObjectParser implements BiFunction { +public final class ObjectParser implements BiFunction { /** * Adapts an array (or varags) setter into a list setter. */ @@ -87,32 +88,22 @@ public final class ObjectParser implements BiFunction implements BiFunction { * Lookup a value from the registry by name while checking that the name matches the ParseField. * * @param name The name of the thing to look up. - * @param parser The parser from which the name was looked up. This is used to resolve the {@link ParseFieldMatcher} and to build nice - * error messages. + * @param parser The parser from which the name was looked up. + * @param parseFieldMatcher to build nice error messages. * @return The value being looked up. Never null. * @throws ParsingException if the named thing isn't in the registry or the name was deprecated and deprecated names aren't supported. */ - public T lookup(String name, XContentParser parser) { - T value = lookupReturningNullIfNotFound(name, parser); + public T lookup(String name, XContentParser parser, ParseFieldMatcher parseFieldMatcher) { + T value = lookupReturningNullIfNotFound(name, parseFieldMatcher); if (value == null) { throw new ParsingException(parser.getTokenLocation(), "no [" + registryName + "] registered for [" + name + "]"); } @@ -85,19 +85,19 @@ public class ParseFieldRegistry { * Lookup a value from the registry by name while checking that the name matches the ParseField. * * @param name The name of the thing to look up. - * @param parser The parser from which the name was looked up. This is used to resolve the {@link ParseFieldMatcher} and to build nice + * @param parseFieldMatcher The parseFieldMatcher. This is used to resolve the {@link ParseFieldMatcher} and to build nice * error messages. * @return The value being looked up or null if it wasn't found. * @throws ParsingException if the named thing isn't in the registry or the name was deprecated and deprecated names aren't supported. */ - public T lookupReturningNullIfNotFound(String name, XContentParser parser) { + public T lookupReturningNullIfNotFound(String name, ParseFieldMatcher parseFieldMatcher) { Tuple parseFieldAndValue = registry.get(name); if (parseFieldAndValue == null) { return null; } ParseField parseField = parseFieldAndValue.v1(); T value = parseFieldAndValue.v2(); - boolean match = parser.getParseFieldMatcher().match(name, parseField); + boolean match = parseFieldMatcher.match(name, parseField); //this is always expected to match, ParseField is useful for deprecation warnings etc. here assert match : "ParseField did not match registered name [" + name + "][" + registryName + "]"; return value; diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java index d647c5f0134..54de31c3150 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java @@ -20,7 +20,6 @@ package org.elasticsearch.common.xcontent; import org.apache.lucene.util.BytesRef; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.lease.Releasable; import java.io.IOException; @@ -187,7 +186,7 @@ public interface XContentParser extends Releasable { float floatValue(boolean coerce) throws IOException; double doubleValue(boolean coerce) throws IOException; - + short shortValue() throws IOException; int intValue() throws IOException; @@ -241,21 +240,10 @@ public interface XContentParser extends Releasable { /** * Used for error reporting to highlight where syntax errors occur in * content being parsed. - * + * * @return last token's location or null if cannot be determined */ XContentLocation getTokenLocation(); boolean isClosed(); - - /** - * Returns this parsers {@link ParseFieldMatcher} - */ - ParseFieldMatcher getParseFieldMatcher(); - - - /** - * Sets this parsers {@link ParseFieldMatcher} - */ - void setParseFieldMatcher(ParseFieldMatcher matcher) ; } diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java index e994b81832f..39a6fca1095 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/support/AbstractXContentParser.java @@ -22,7 +22,6 @@ package org.elasticsearch.common.xcontent.support; import org.apache.lucene.util.BytesRef; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.Booleans; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.xcontent.XContentParser; import java.io.IOException; @@ -37,8 +36,6 @@ import java.util.Map; */ public abstract class AbstractXContentParser implements XContentParser { - private ParseFieldMatcher matcher = ParseFieldMatcher.STRICT; - // Currently this is not a setting that can be changed and is a policy // that relates to how parsing of things like "boost" are done across // the whole of Elasticsearch (eg if String "1.0" is a valid float). @@ -337,12 +334,4 @@ public abstract class AbstractXContentParser implements XContentParser { @Override public abstract boolean isClosed(); - - public ParseFieldMatcher getParseFieldMatcher() { - return matcher; - } - - public void setParseFieldMatcher(ParseFieldMatcher matcher) { - this.matcher = matcher; - } } diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java index 3fe7cfd6da5..ee6c49234fd 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java @@ -21,13 +21,14 @@ package org.elasticsearch.index.query; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.indices.query.IndicesQueriesRegistry; import java.io.IOException; -public class QueryParseContext { +public class QueryParseContext implements ParseFieldMatcherSupplier { private static final ParseField CACHE = new ParseField("_cache").withAllDeprecated("Elasticsearch makes its own caching decisions"); private static final ParseField CACHE_KEY = new ParseField("_cache_key").withAllDeprecated("Filters are always used as cache keys"); @@ -44,9 +45,6 @@ public class QueryParseContext { public void reset(XContentParser jp) { this.parseFieldMatcher = ParseFieldMatcher.EMPTY; this.parser = jp; - if (parser != null) { - this.parser.setParseFieldMatcher(parseFieldMatcher); - } } public XContentParser parser() { @@ -57,9 +55,6 @@ public class QueryParseContext { if (parseFieldMatcher == null) { throw new IllegalArgumentException("parseFieldMatcher must not be null"); } - if (parser != null) { - parser.setParseFieldMatcher(parseFieldMatcher); - } this.parseFieldMatcher = parseFieldMatcher; } @@ -120,7 +115,7 @@ public class QueryParseContext { if (token != XContentParser.Token.START_OBJECT && token != XContentParser.Token.START_ARRAY) { throw new ParsingException(parser.getTokenLocation(), "[_na] query malformed, no field after start_object"); } - QueryBuilder result = indicesQueriesRegistry.lookup(queryName, parser).fromXContent(this); + QueryBuilder result = indicesQueriesRegistry.lookup(queryName, parser, parseFieldMatcher).fromXContent(this); if (parser.currentToken() == XContentParser.Token.END_OBJECT || parser.currentToken() == XContentParser.Token.END_ARRAY) { // if we are at END_OBJECT, move to the next one... parser.nextToken(); @@ -128,6 +123,7 @@ public class QueryParseContext { return result; } + @Override public ParseFieldMatcher parseFieldMatcher() { return parseFieldMatcher; } diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java index b516e44ea28..6420c235c2e 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java @@ -29,6 +29,7 @@ import org.apache.lucene.search.similarities.Similarity; import org.elasticsearch.Version; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; @@ -49,7 +50,6 @@ import org.elasticsearch.index.mapper.core.TextFieldMapper; import org.elasticsearch.index.mapper.object.ObjectMapper; import org.elasticsearch.index.percolator.PercolatorQueryCache; import org.elasticsearch.index.query.support.InnerHitBuilder; -import org.elasticsearch.index.query.support.InnerHitsBuilder; import org.elasticsearch.index.query.support.NestedScope; import org.elasticsearch.index.similarity.SimilarityService; import org.elasticsearch.indices.query.IndicesQueriesRegistry; @@ -69,7 +69,7 @@ import static java.util.Collections.unmodifiableMap; /** * Context object used to create lucene queries on the shard level. */ -public class QueryShardContext extends QueryRewriteContext { +public class QueryShardContext extends QueryRewriteContext implements ParseFieldMatcherSupplier { private final MapperService mapperService; private final SimilarityService similarityService; @@ -118,6 +118,7 @@ public class QueryShardContext extends QueryRewriteContext { this.parseContext.parseFieldMatcher(parseFieldMatcher); } + @Override public ParseFieldMatcher parseFieldMatcher() { return parseContext.parseFieldMatcher(); } diff --git a/core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java index c3d8dc976ef..a4b5fdd806c 100644 --- a/core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java @@ -476,7 +476,8 @@ public class FunctionScoreQueryBuilder extends AbstractQueryBuilder scoreFunction = scoreFunctionsRegistry.lookup(currentFieldName, parseContext.parser()) + ScoreFunctionBuilder scoreFunction = scoreFunctionsRegistry + .lookup(currentFieldName, parseContext.parser(), parseContext.parseFieldMatcher()) .fromXContent(parseContext); filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(scoreFunction)); } @@ -581,7 +582,8 @@ public class FunctionScoreQueryBuilder extends AbstractQueryBuilder, Void> INGEST_METADATA_PARSER = new ObjectParser<>("ingest_metadata", ArrayList::new); + private static final ObjectParser, ParseFieldMatcherSupplier> INGEST_METADATA_PARSER = new ObjectParser<>( + "ingest_metadata", ArrayList::new); static { INGEST_METADATA_PARSER.declareObjectArray(List::addAll , PipelineConfiguration.getParser(), PIPELINES_FIELD); @@ -94,7 +97,7 @@ public final class IngestMetadata implements MetaData.Custom { @Override public IngestMetadata fromXContent(XContentParser parser) throws IOException { Map pipelines = new HashMap<>(); - List configs = INGEST_METADATA_PARSER.parse(parser); + List configs = INGEST_METADATA_PARSER.parse(parser, () -> ParseFieldMatcher.STRICT); for (PipelineConfiguration pipeline : configs) { pipelines.put(pipeline.getId(), pipeline); } diff --git a/core/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java b/core/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java index d99d0e18c5c..6272eee1cbf 100644 --- a/core/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java +++ b/core/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java @@ -21,6 +21,7 @@ package org.elasticsearch.ingest; import org.elasticsearch.cluster.AbstractDiffable; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -46,7 +47,7 @@ public final class PipelineConfiguration extends AbstractDiffable PARSER = new ObjectParser<>("pipeline_config", Builder::new); + private final static ObjectParser PARSER = new ObjectParser<>("pipeline_config", Builder::new); static { PARSER.declareString(Builder::setId, new ParseField("id")); PARSER.declareField((parser, builder, aVoid) -> { @@ -56,7 +57,7 @@ public final class PipelineConfiguration extends AbstractDiffable getParser() { + public static BiFunction getParser() { return (p, c) -> PARSER.apply(p ,c).build(); } private static class Builder { @@ -110,6 +111,7 @@ public final class PipelineConfiguration extends AbstractDiffable TLP_PARSER = + private static ObjectParser TLP_PARSER = new ObjectParser<>(SUGGESTION_NAME, null); static { TLP_PARSER.declareStringArray(CompletionSuggestionBuilder.InnerBuilder::payload, PAYLOAD_FIELD); @@ -80,12 +82,12 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder - completionSuggestionContext.regexOptions = RegexOptions.parse(parser), + completionSuggestionContext.regexOptions = RegexOptions.parse(parser, context), RegexOptions.REGEX_OPTIONS, ObjectParser.ValueType.OBJECT); TLP_PARSER.declareString(CompletionSuggestionBuilder.InnerBuilder::field, SuggestUtils.Fields.FIELD); TLP_PARSER.declareString(CompletionSuggestionBuilder.InnerBuilder::analyzer, SuggestUtils.Fields.ANALYZER); @@ -263,7 +265,7 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder ParseFieldMatcher.STRICT); String field = builder.field; // now we should have field name, check and copy fields over to the suggestion builder we return if (field == null) { diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/FuzzyOptions.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/FuzzyOptions.java index ed2efdf4562..2977e8ad9a2 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/FuzzyOptions.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/FuzzyOptions.java @@ -23,6 +23,7 @@ import org.apache.lucene.search.suggest.document.FuzzyCompletionQuery; import org.apache.lucene.util.automaton.Operations; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -56,7 +57,8 @@ public class FuzzyOptions implements ToXContent, Writeable { * "max_determinized_states" : INT * } */ - private static ObjectParser PARSER = new ObjectParser<>(FUZZY_OPTIONS.getPreferredName(), Builder::new); + private static ObjectParser PARSER = new ObjectParser<>(FUZZY_OPTIONS.getPreferredName(), + Builder::new); static { PARSER.declareInt(Builder::setFuzzyMinLength, MIN_LENGTH_FIELD); PARSER.declareInt(Builder::setMaxDeterminizedStates, MAX_DETERMINIZED_STATES_FIELD); @@ -111,8 +113,8 @@ public class FuzzyOptions implements ToXContent, Writeable { out.writeVInt(maxDeterminizedStates); } - static FuzzyOptions parse(XContentParser parser) throws IOException { - return PARSER.parse(parser).build(); + static FuzzyOptions parse(XContentParser parser, ParseFieldMatcherSupplier context) throws IOException { + return PARSER.parse(parser, context).build(); } public static Builder builder() { diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/RegexOptions.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/RegexOptions.java index 58464cddee2..59ca2a6da14 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/RegexOptions.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/RegexOptions.java @@ -23,6 +23,7 @@ import org.apache.lucene.util.automaton.Operations; import org.apache.lucene.util.automaton.RegExp; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Writeable; @@ -48,7 +49,8 @@ public class RegexOptions implements ToXContent, Writeable { * "max_determinized_states" : INT * } */ - private static ObjectParser PARSER = new ObjectParser<>(REGEX_OPTIONS.getPreferredName(), Builder::new); + private static ObjectParser PARSER = new ObjectParser<>(REGEX_OPTIONS.getPreferredName(), + Builder::new); static { PARSER.declareInt(Builder::setMaxDeterminizedStates, MAX_DETERMINIZED_STATES); PARSER.declareField((parser, builder, aVoid) -> { @@ -105,8 +107,8 @@ public class RegexOptions implements ToXContent, Writeable { return new Builder(); } - static RegexOptions parse(XContentParser parser) throws IOException { - return PARSER.parse(parser).build(); + static RegexOptions parse(XContentParser parser, ParseFieldMatcherSupplier context) throws IOException { + return PARSER.parse(parser, context).build(); } @Override diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java index 62892216c68..1384868f0dc 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java @@ -21,6 +21,8 @@ package org.elasticsearch.search.suggest.completion.context; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -95,7 +97,7 @@ public final class CategoryQueryContext implements ToXContent { return result; } - private static ObjectParser CATEGORY_PARSER = new ObjectParser<>(NAME, null); + private static ObjectParser CATEGORY_PARSER = new ObjectParser<>(NAME, null); static { CATEGORY_PARSER.declareString(Builder::setCategory, new ParseField(CONTEXT_VALUE)); CATEGORY_PARSER.declareInt(Builder::setBoost, new ParseField(CONTEXT_BOOST)); @@ -106,7 +108,7 @@ public final class CategoryQueryContext implements ToXContent { XContentParser.Token token = parser.currentToken(); Builder builder = builder(); if (token == XContentParser.Token.START_OBJECT) { - CATEGORY_PARSER.parse(parser, builder); + CATEGORY_PARSER.parse(parser, builder, () -> ParseFieldMatcher.STRICT); } else if (token == XContentParser.Token.VALUE_STRING) { builder.setCategory(parser.text()); } else { diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java index 1d27f171594..dd625f252de 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java @@ -21,6 +21,8 @@ package org.elasticsearch.search.suggest.completion.context; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoUtils; import org.elasticsearch.common.xcontent.ObjectParser; @@ -111,7 +113,7 @@ public final class GeoQueryContext implements ToXContent { return new Builder(); } - private static ObjectParser GEO_CONTEXT_PARSER = new ObjectParser<>(NAME, null); + private static ObjectParser GEO_CONTEXT_PARSER = new ObjectParser<>(NAME, null); static { GEO_CONTEXT_PARSER.declareField((parser, geoQueryContext, geoContextMapping) -> geoQueryContext.setGeoPoint(GeoUtils.parseGeoPoint(parser)), new ParseField(CONTEXT_VALUE), ObjectParser.ValueType.OBJECT); GEO_CONTEXT_PARSER.declareInt(GeoQueryContext.Builder::setBoost, new ParseField(CONTEXT_BOOST)); @@ -127,7 +129,7 @@ public final class GeoQueryContext implements ToXContent { XContentParser.Token token = parser.currentToken(); GeoQueryContext.Builder builder = new Builder(); if (token == XContentParser.Token.START_OBJECT) { - GEO_CONTEXT_PARSER.parse(parser, builder); + GEO_CONTEXT_PARSER.parse(parser, builder, () -> ParseFieldMatcher.STRICT); } else if (token == XContentParser.Token.VALUE_STRING) { builder.setGeoPoint(GeoPoint.fromGeohash(parser.text())); } else { diff --git a/core/src/main/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGeneratorBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGeneratorBuilder.java index d2fee7ccb30..0d4e269a5c4 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGeneratorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGeneratorBuilder.java @@ -375,13 +375,15 @@ public final class DirectCandidateGeneratorBuilder DirectCandidateGeneratorBuilder tempGenerator = new DirectCandidateGeneratorBuilder("_na_"); // bucket for the field name, needed as constructor arg later Set tmpFieldName = new HashSet<>(1); - PARSER.parse(parseContext.parser(), new Tuple, DirectCandidateGeneratorBuilder>(tmpFieldName, tempGenerator)); + PARSER.parse(parseContext.parser(), new Tuple, DirectCandidateGeneratorBuilder>(tmpFieldName, tempGenerator), + parseContext); if (tmpFieldName.size() != 1) { throw new IllegalArgumentException("[" + TYPE + "] expects exactly one field parameter, but found " + tmpFieldName); } return replaceField(tmpFieldName.iterator().next(), tempGenerator); } + @Override public PhraseSuggestionContext.DirectCandidateGenerator build(MapperService mapperService) throws IOException { PhraseSuggestionContext.DirectCandidateGenerator generator = new PhraseSuggestionContext.DirectCandidateGenerator(); generator.setField(this.field); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java index e1b55b735c0..2cd688a661c 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java @@ -36,6 +36,7 @@ import org.elasticsearch.cluster.routing.allocation.command.AllocationCommands; import org.elasticsearch.cluster.routing.allocation.command.CancelAllocationCommand; import org.elasticsearch.cluster.routing.allocation.command.MoveAllocationCommand; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; +import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -452,7 +453,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase { parser.nextToken(); AllocationCommandRegistry registry = new NetworkModule(null, Settings.EMPTY, true, new NamedWriteableRegistry()) .getAllocationCommandRegistry(); - AllocationCommands sCommands = AllocationCommands.fromXContent(parser, registry); + AllocationCommands sCommands = AllocationCommands.fromXContent(parser, ParseFieldMatcher.STRICT, registry); assertThat(sCommands.commands().size(), equalTo(5)); assertThat(((AllocateEmptyPrimaryAllocationCommand) (sCommands.commands().get(0))).shardId(), equalTo(1)); diff --git a/core/src/test/java/org/elasticsearch/common/xcontent/ObjectParserTests.java b/core/src/test/java/org/elasticsearch/common/xcontent/ObjectParserTests.java index ec4da62c2dd..abafd7e4cf3 100644 --- a/core/src/test/java/org/elasticsearch/common/xcontent/ObjectParserTests.java +++ b/core/src/test/java/org/elasticsearch/common/xcontent/ObjectParserTests.java @@ -18,22 +18,25 @@ */ package org.elasticsearch.common.xcontent; -import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParsingException; -import org.elasticsearch.common.xcontent.ObjectParser.NamedObjectParser; -import org.elasticsearch.common.xcontent.ObjectParser.ValueType; -import org.elasticsearch.test.ESTestCase; +import static org.hamcrest.Matchers.hasSize; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import static org.hamcrest.Matchers.hasSize; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; +import org.elasticsearch.common.ParsingException; +import org.elasticsearch.common.xcontent.ObjectParser.NamedObjectParser; +import org.elasticsearch.common.xcontent.ObjectParser.ValueType; +import org.elasticsearch.test.ESTestCase; public class ObjectParserTests extends ESTestCase { + private final static ParseFieldMatcherSupplier STRICT_PARSING = () -> ParseFieldMatcher.STRICT; + public void testBasics() throws IOException { XContentParser parser = XContentType.JSON.xContent().createParser( "{\n" @@ -53,14 +56,13 @@ public class ObjectParserTests extends ESTestCase { this.ints = ints; } } - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); TestStruct s = new TestStruct(); objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("test"), ObjectParser.ValueType.STRING); objectParser.declareInt(TestStruct::setTestNumber, new ParseField("test_number")); objectParser.declareIntArray(TestStruct::setInts, new ParseField("test_array")); - parser.setParseFieldMatcher(ParseFieldMatcher.STRICT); - objectParser.parse(parser, s); + objectParser.parse(parser, s, STRICT_PARSING); assertEquals(s.test, "foo"); assertEquals(s.testNumber, 2); assertEquals(s.ints, Arrays.asList(1, 2, 3, 4)); @@ -74,17 +76,17 @@ public class ObjectParserTests extends ESTestCase { public void testObjectOrDefault() throws IOException { XContentParser parser = XContentType.JSON.xContent().createParser("{\"object\" : { \"test\": 2}}"); - ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); + ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); objectParser.declareInt(StaticTestStruct::setTest, new ParseField("test")); objectParser.declareObjectOrDefault(StaticTestStruct::setObject, objectParser, StaticTestStruct::new, new ParseField("object")); - StaticTestStruct s = objectParser.parse(parser); + StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING); assertEquals(s.object.test, 2); parser = XContentType.JSON.xContent().createParser("{\"object\" : false }"); - s = objectParser.parse(parser); + s = objectParser.parse(parser, STRICT_PARSING); assertNull(s.object); parser = XContentType.JSON.xContent().createParser("{\"object\" : true }"); - s = objectParser.parse(parser); + s = objectParser.parse(parser, STRICT_PARSING); assertNotNull(s.object); assertEquals(s.object.test, 0); @@ -96,12 +98,12 @@ public class ObjectParserTests extends ESTestCase { public void setTest(int test) { } } - ObjectParser objectParser = new ObjectParser<>("the_parser"); + ObjectParser objectParser = new ObjectParser<>("the_parser"); TestStruct s = new TestStruct(); objectParser.declareInt(TestStruct::setTest, new ParseField("test")); try { - objectParser.parse(parser, s); + objectParser.parse(parser, s, STRICT_PARSING); fail("numeric value expected"); } catch (ParsingException ex) { assertEquals(ex.getMessage(), "[the_parser] failed to parse field [test]"); @@ -110,7 +112,7 @@ public class ObjectParserTests extends ESTestCase { parser = XContentType.JSON.xContent().createParser("{\"not_supported_field\" : \"foo\"}"); try { - objectParser.parse(parser, s); + objectParser.parse(parser, s, STRICT_PARSING); fail("field not supported"); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), "[the_parser] unknown field [not_supported_field], parser not found"); @@ -122,14 +124,13 @@ public class ObjectParserTests extends ESTestCase { class TestStruct { public String test; } - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); TestStruct s = new TestStruct(); objectParser.declareField((i, v, c) -> v.test = i.text(), new ParseField("test", "old_test"), ObjectParser.ValueType.STRING); - parser.setParseFieldMatcher(ParseFieldMatcher.STRICT); try { - objectParser.parse(parser, s); + objectParser.parse(parser, s, STRICT_PARSING); fail("deprecated value"); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), "Deprecated field [old_test] used, expected [test] instead"); @@ -137,8 +138,7 @@ public class ObjectParserTests extends ESTestCase { } assertNull(s.test); parser = XContentType.JSON.xContent().createParser("{\"old_test\" : \"foo\"}"); - parser.setParseFieldMatcher(ParseFieldMatcher.EMPTY); - objectParser.parse(parser, s); + objectParser.parse(parser, s, () -> ParseFieldMatcher.EMPTY); assertEquals("foo", s.test); } @@ -147,13 +147,12 @@ public class ObjectParserTests extends ESTestCase { class TestStruct { public String test; } - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); TestStruct s = new TestStruct(); objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("numeric_value"), ObjectParser.ValueType.FLOAT); - parser.setParseFieldMatcher(ParseFieldMatcher.STRICT); try { - objectParser.parse(parser, s); + objectParser.parse(parser, s, STRICT_PARSING); fail("wrong type - must be number"); } catch (IllegalArgumentException ex) { assertEquals(ex.getMessage(), "[foo] numeric_value doesn't support values of type: VALUE_BOOLEAN"); @@ -166,39 +165,40 @@ public class ObjectParserTests extends ESTestCase { public int test; TestStruct object; } - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); TestStruct s = new TestStruct(); s.object = new TestStruct(); objectParser.declareField((i, c, x) -> c.test = i.intValue(), new ParseField("test"), ValueType.INT); - objectParser.declareField((i, c, x) -> objectParser.parse(parser, c.object), new ParseField("object"), ValueType.OBJECT); - objectParser.parse(parser, s); + objectParser.declareField((i, c, x) -> objectParser.parse(parser, c.object, STRICT_PARSING), new ParseField("object"), + ValueType.OBJECT); + objectParser.parse(parser, s, STRICT_PARSING); assertEquals(s.test, 1); assertEquals(s.object.test, 2); } public void testParseNestedShortcut() throws IOException { XContentParser parser = XContentType.JSON.xContent().createParser("{ \"test\" : 1, \"object\" : { \"test\": 2}}"); - ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); + ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); objectParser.declareInt(StaticTestStruct::setTest, new ParseField("test")); objectParser.declareObject(StaticTestStruct::setObject, objectParser, new ParseField("object")); - StaticTestStruct s = objectParser.parse(parser); + StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING); assertEquals(s.test, 1); assertEquals(s.object.test, 2); } public void testEmptyObject() throws IOException { XContentParser parser = XContentType.JSON.xContent().createParser("{\"object\" : {}}"); - ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); + ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); objectParser.declareObject(StaticTestStruct::setObject, objectParser, new ParseField("object")); - StaticTestStruct s = objectParser.parse(parser); + StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING); assertNotNull(s.object); } public void testEmptyObjectInArray() throws IOException { XContentParser parser = XContentType.JSON.xContent().createParser("{\"object_array\" : [{}]}"); - ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); + ObjectParser objectParser = new ObjectParser<>("foo", StaticTestStruct::new); objectParser.declareObjectArray(StaticTestStruct::setObjectArray, objectParser, new ParseField("object_array")); - StaticTestStruct s = objectParser.parse(parser); + StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING); assertNotNull(s.objectArray); } @@ -233,9 +233,9 @@ public class ObjectParserTests extends ESTestCase { } } XContentParser parser = XContentType.JSON.xContent().createParser("{ \"test\" : \"FOO\" }"); - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); objectParser.declareString((struct, value) -> struct.set(TestEnum.valueOf(value)), new ParseField("test")); - TestStruct s = objectParser.parse(parser, new TestStruct()); + TestStruct s = objectParser.parse(parser, new TestStruct(), STRICT_PARSING); assertEquals(s.test, TestEnum.FOO); } @@ -329,7 +329,7 @@ public class ObjectParserTests extends ESTestCase { this.string_or_null = string_or_null; } } - ObjectParser objectParser = new ObjectParser<>("foo"); + ObjectParser objectParser = new ObjectParser<>("foo"); objectParser.declareInt(TestStruct::setInt_field, new ParseField("int_field")); objectParser.declareIntArray(TestStruct::setInt_array_field, new ParseField("int_array_field")); objectParser.declareLong(TestStruct::setLong_field, new ParseField("long_field")); @@ -343,7 +343,7 @@ public class ObjectParserTests extends ESTestCase { objectParser.declareStringOrNull(TestStruct::setString_or_null, new ParseField("string_or_null")); objectParser.declareBoolean(TestStruct::setNull_value, new ParseField("boolean_field")); - TestStruct parse = objectParser.parse(parser, new TestStruct()); + TestStruct parse = objectParser.parse(parser, new TestStruct(), STRICT_PARSING); assertArrayEquals(parse.double_array_field.toArray(), Arrays.asList(2.1d).toArray()); assertEquals(parse.double_field, 2.1d, 0.0d); @@ -372,7 +372,7 @@ public class ObjectParserTests extends ESTestCase { "{\"named\": {\n" + " \"a\": {}" + "}}"); - NamedObjectHolder h = NamedObjectHolder.PARSER.apply(parser, null); + NamedObjectHolder h = NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING); assertThat(h.named, hasSize(1)); assertEquals("a", h.named.get(0).name); assertFalse(h.namedSuppliedInOrder); @@ -383,7 +383,7 @@ public class ObjectParserTests extends ESTestCase { "{\"named\": [\n" + " {\"a\": {}}" + "]}"); - NamedObjectHolder h = NamedObjectHolder.PARSER.apply(parser, null); + NamedObjectHolder h = NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING); assertThat(h.named, hasSize(1)); assertEquals("a", h.named.get(0).name); assertTrue(h.namedSuppliedInOrder); @@ -394,7 +394,7 @@ public class ObjectParserTests extends ESTestCase { "{\"named\": [\n" + " {\"a\": {}, \"b\": {}}" + "]}"); - ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, null)); + ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING)); assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage()); assertEquals( "[named] can be a single object with any number of fields or an array where each entry is an object with a single field", @@ -406,7 +406,7 @@ public class ObjectParserTests extends ESTestCase { "{\"named\": [\n" + " {}" + "]}"); - ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, null)); + ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING)); assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage()); assertEquals( "[named] can be a single object with any number of fields or an array where each entry is an object with a single field", @@ -418,7 +418,7 @@ public class ObjectParserTests extends ESTestCase { "{\"named\": [\n" + " \"junk\"" + "]}"); - ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, null)); + ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING)); assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage()); assertEquals( "[named] can be a single object with any number of fields or an array where each entry is an object with a single field", @@ -432,17 +432,18 @@ public class ObjectParserTests extends ESTestCase { + "]}"); // Create our own parser for this test so we can disable support for the "ordered" mode specified by the array above - ObjectParser objectParser = new ObjectParser<>("named_object_holder", NamedObjectHolder::new); + ObjectParser objectParser = new ObjectParser<>("named_object_holder", + NamedObjectHolder::new); objectParser.declareNamedObjects(NamedObjectHolder::setNamed, NamedObject.PARSER, new ParseField("named")); // Now firing the xml through it fails - ParsingException e = expectThrows(ParsingException.class, () -> objectParser.apply(parser, null)); + ParsingException e = expectThrows(ParsingException.class, () -> objectParser.apply(parser, STRICT_PARSING)); assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage()); assertEquals("[named] doesn't support arrays. Use a single object with multiple fields.", e.getCause().getMessage()); } static class NamedObjectHolder { - public static final ObjectParser PARSER = new ObjectParser<>("named_object_holder", + public static final ObjectParser PARSER = new ObjectParser<>("named_object_holder", NamedObjectHolder::new); static { PARSER.declareNamedObjects(NamedObjectHolder::setNamed, NamedObject.PARSER, NamedObjectHolder::keepNamedInOrder, @@ -462,11 +463,11 @@ public class ObjectParserTests extends ESTestCase { } public static class NamedObject { - public static final NamedObjectParser PARSER; + public static final NamedObjectParser PARSER; static { - ObjectParser parser = new ObjectParser<>("named"); + ObjectParser parser = new ObjectParser<>("named"); parser.declareInt(NamedObject::setFoo, new ParseField("foo")); - PARSER = (XContentParser p, Void v, String name) -> parser.parse(p, new NamedObject(name)); + PARSER = (XContentParser p, ParseFieldMatcherSupplier v, String name) -> parser.parse(p, new NamedObject(name), STRICT_PARSING); } final String name; diff --git a/core/src/test/java/org/elasticsearch/search/SearchModuleTests.java b/core/src/test/java/org/elasticsearch/search/SearchModuleTests.java index 31d9722eced..393321e8e06 100644 --- a/core/src/test/java/org/elasticsearch/search/SearchModuleTests.java +++ b/core/src/test/java/org/elasticsearch/search/SearchModuleTests.java @@ -98,19 +98,17 @@ public class SearchModuleTests extends ModuleTestCase { IndicesQueriesRegistry indicesQueriesRegistry = module.getQueryParserRegistry(); XContentParser dummyParser = XContentHelper.createParser(new BytesArray("{}")); - dummyParser.setParseFieldMatcher(ParseFieldMatcher.EMPTY); for (String queryName : supportedQueries) { - indicesQueriesRegistry.lookup(queryName, dummyParser); + indicesQueriesRegistry.lookup(queryName, dummyParser, ParseFieldMatcher.EMPTY); } - dummyParser.setParseFieldMatcher(ParseFieldMatcher.STRICT); for (String queryName : NON_DEPRECATED_QUERIES) { - QueryParser queryParser = indicesQueriesRegistry.lookup(queryName, dummyParser); + QueryParser queryParser = indicesQueriesRegistry.lookup(queryName, dummyParser, ParseFieldMatcher.STRICT); assertThat(queryParser, notNullValue()); } for (String queryName : DEPRECATED_QUERIES) { try { - indicesQueriesRegistry.lookup(queryName, dummyParser); + indicesQueriesRegistry.lookup(queryName, dummyParser, ParseFieldMatcher.STRICT); fail("query is deprecated, getQueryParser should have failed in strict mode"); } catch(IllegalArgumentException e) { assertThat(e.getMessage(), containsString("Deprecated field [" + queryName + "] used")); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java index 4603326e3a8..3833d59ef34 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java @@ -235,7 +235,7 @@ public abstract class BaseAggregationTestCase> assertSame(XContentParser.Token.FIELD_NAME, parser.nextToken()); assertEquals(testAgg.type.name(), parser.currentName()); assertSame(XContentParser.Token.START_OBJECT, parser.nextToken()); - AggregatorBuilder newAgg = aggParsers.parser(testAgg.getType(), parser).parse(testAgg.name, parseContext); + AggregatorBuilder newAgg = aggParsers.parser(testAgg.getType(), ParseFieldMatcher.STRICT).parse(testAgg.name, parseContext); assertSame(XContentParser.Token.END_OBJECT, parser.currentToken()); assertSame(XContentParser.Token.END_OBJECT, parser.nextToken()); assertSame(XContentParser.Token.END_OBJECT, parser.nextToken()); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java index a3d4ff46e42..4c9311bb110 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java @@ -237,7 +237,7 @@ public abstract class BasePipelineAggregationTestCase newAgg = aggParsers.pipelineParser(testAgg.getWriteableName(), parser) + PipelineAggregatorBuilder newAgg = aggParsers.pipelineParser(testAgg.getWriteableName(), ParseFieldMatcher.STRICT) .parse(testAgg.name(), parseContext); assertSame(XContentParser.Token.END_OBJECT, parser.currentToken()); assertSame(XContentParser.Token.END_OBJECT, parser.nextToken()); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgTests.java index 04499e2fcde..e4d134b8e38 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/pipeline/moving/avg/MovAvgTests.java @@ -19,6 +19,7 @@ package org.elasticsearch.search.aggregations.pipeline.moving.avg; +import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; @@ -116,8 +117,8 @@ public class MovAvgTests extends BasePipelineAggregationTestCase newAgg = aggParsers.pipelineParser(expected.getWriteableName(), parser).parse(expected.name(), - parseContext); + PipelineAggregatorBuilder newAgg = aggParsers.pipelineParser(expected.getWriteableName(), ParseFieldMatcher.STRICT) + .parse(expected.name(), parseContext); assertSame(XContentParser.Token.END_OBJECT, parser.currentToken()); assertSame(XContentParser.Token.END_OBJECT, parser.nextToken()); assertSame(XContentParser.Token.END_OBJECT, parser.nextToken()); diff --git a/core/src/test/java/org/elasticsearch/search/sort/SortParserTests.java b/core/src/test/java/org/elasticsearch/search/sort/SortParserTests.java index c3dc8eab745..a5ef892bf17 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/SortParserTests.java +++ b/core/src/test/java/org/elasticsearch/search/sort/SortParserTests.java @@ -47,7 +47,7 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.endArray(); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); @@ -58,7 +58,7 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.endArray(); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); @@ -69,7 +69,7 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.endArray(); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); @@ -80,7 +80,7 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.endArray(); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); @@ -91,7 +91,7 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.endArray(); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); @@ -100,7 +100,7 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.field("location", new GeoPoint(1, 2)); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); @@ -109,7 +109,7 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.field("location", "1,2"); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); @@ -118,7 +118,7 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.field("location", "s3y0zh7w1z0g"); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); @@ -129,16 +129,36 @@ public class SortParserTests extends ESSingleNodeTestCase { sortBuilder.endArray(); sortBuilder.field("order", "desc"); sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); + sortBuilder.field("mode", "max"); sortBuilder.endObject(); parse(context, sortBuilder); } + public void testGeoDistanceSortDeprecatedSortModeException() throws Exception { + XContentBuilder mapping = jsonBuilder(); + mapping.startObject().startObject("type").startObject("properties").startObject("location").field("type", "geo_point").endObject().endObject().endObject().endObject(); + IndexService indexService = createIndex("testidx", Settings.builder().build(), "type", mapping); + TestSearchContext context = (TestSearchContext) createSearchContext(indexService); + context.getQueryShardContext().setTypes("type"); + + XContentBuilder sortBuilder = jsonBuilder(); + sortBuilder.startObject(); + sortBuilder.startArray("location"); + sortBuilder.startArray().value(1.2).value(3).endArray().startArray().value(5).value(6).endArray(); + sortBuilder.endArray(); + sortBuilder.field("order", "desc"); + sortBuilder.field("unit", "km"); + sortBuilder.field("sort_mode", "max"); + sortBuilder.endObject(); + IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> parse(context, sortBuilder)); + assertEquals("Deprecated field [sort_mode] used, expected [mode] instead", ex.getMessage()); + } + protected void parse(TestSearchContext context, XContentBuilder sortBuilder) throws Exception { QueryParseContext parseContext = context.getQueryShardContext().parseContext(); XContentParser parser = XContentHelper.createParser(sortBuilder.bytes()); - parser.setParseFieldMatcher(ParseFieldMatcher.STRICT); parseContext.reset(parser); + parseContext.parseFieldMatcher(ParseFieldMatcher.STRICT); parser.nextToken(); GeoDistanceSortBuilder.fromXContent(parseContext, null); } diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java index 8f6fe71d46e..fc5f1c69ecd 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java @@ -33,6 +33,8 @@ import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; @@ -80,7 +82,7 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler destParser = new ObjectParser<>("dest"); + ObjectParser 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")); @@ -94,7 +96,7 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler sourceParser.parse(p, v.getSearchRequest(), c), new ParseField("source"), ValueType.OBJECT); - PARSER.declareField((p, v, c) -> destParser.parse(p, v.getDestination(), null), new ParseField("dest"), ValueType.OBJECT); + PARSER.declareField((p, v, c) -> destParser.parse(p, v.getDestination(), c), new ParseField("dest"), ValueType.OBJECT); PARSER.declareInt(ReindexRequest::setSize, new ParseField("size")); PARSER.declareField((p, v, c) -> v.setScript(Script.parse(p, c.queryParseContext.parseFieldMatcher())), new ParseField("script"), ValueType.OBJECT); @@ -169,7 +171,7 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler Date: Fri, 15 Apr 2016 12:05:45 +0200 Subject: [PATCH 014/561] Rename context.parseFieldMatcher() to context.getParseFieldMatcher --- .../common/ParseFieldMatcherSupplier.java | 2 +- .../common/xcontent/ObjectParser.java | 2 +- .../index/query/BoolQueryBuilder.java | 12 ++-- .../index/query/BoostingQueryBuilder.java | 10 +-- .../index/query/CommonTermsQueryBuilder.java | 24 +++---- .../query/ConstantScoreQueryBuilder.java | 6 +- .../index/query/DisMaxQueryBuilder.java | 10 +-- .../index/query/ExistsQueryBuilder.java | 6 +- .../query/FieldMaskingSpanQueryBuilder.java | 8 +-- .../index/query/FuzzyQueryBuilder.java | 20 +++--- .../query/GeoBoundingBoxQueryBuilder.java | 32 ++++----- .../index/query/GeoDistanceQueryBuilder.java | 20 +++--- .../query/GeoDistanceRangeQueryBuilder.java | 34 ++++----- .../index/query/GeoPolygonQueryBuilder.java | 10 +-- .../index/query/GeoShapeQueryBuilder.java | 22 +++--- .../index/query/GeohashCellQuery.java | 10 +-- .../index/query/HasChildQueryBuilder.java | 18 ++--- .../index/query/HasParentQueryBuilder.java | 16 ++--- .../index/query/IdsQueryBuilder.java | 10 +-- .../index/query/IndicesQueryBuilder.java | 14 ++-- .../index/query/MatchAllQueryBuilder.java | 4 +- .../index/query/MatchNoneQueryBuilder.java | 4 +- .../query/MatchPhrasePrefixQueryBuilder.java | 12 ++-- .../index/query/MatchPhraseQueryBuilder.java | 10 +-- .../index/query/MatchQueryBuilder.java | 34 ++++----- .../index/query/MoreLikeThisQueryBuilder.java | 48 ++++++------- .../index/query/MultiMatchQueryBuilder.java | 40 +++++------ .../index/query/NestedQueryBuilder.java | 14 ++-- .../index/query/ParentIdQueryBuilder.java | 10 +-- .../index/query/PercolatorQueryBuilder.java | 20 +++--- .../index/query/PrefixQueryBuilder.java | 10 +-- .../index/query/QueryParseContext.java | 2 +- .../index/query/QueryRewriteContext.java | 15 +++- .../index/query/QueryShardContext.java | 28 +++----- .../index/query/QueryStringQueryBuilder.java | 60 ++++++++-------- .../index/query/RangeQueryBuilder.java | 28 ++++---- .../index/query/RegexpQueryBuilder.java | 18 ++--- .../index/query/ScriptQueryBuilder.java | 12 ++-- .../index/query/SimpleQueryStringBuilder.java | 24 +++---- .../query/SpanContainingQueryBuilder.java | 8 +-- .../index/query/SpanFirstQueryBuilder.java | 8 +-- .../query/SpanMultiTermQueryBuilder.java | 6 +- .../index/query/SpanNearQueryBuilder.java | 12 ++-- .../index/query/SpanNotQueryBuilder.java | 14 ++-- .../index/query/SpanOrQueryBuilder.java | 6 +- .../index/query/SpanTermQueryBuilder.java | 8 +-- .../index/query/SpanWithinQueryBuilder.java | 8 +-- .../index/query/TemplateQueryBuilder.java | 2 +- .../index/query/TermQueryBuilder.java | 8 +-- .../index/query/TermsQueryBuilder.java | 4 +- .../index/query/TypeQueryBuilder.java | 6 +- .../index/query/WildcardQueryBuilder.java | 12 ++-- .../index/query/WrapperQueryBuilder.java | 2 +- .../functionscore/DecayFunctionParser.java | 2 +- .../FunctionScoreQueryBuilder.java | 26 +++---- .../ScriptScoreFunctionBuilder.java | 6 +- .../action/search/RestMultiSearchAction.java | 2 +- .../rest/action/search/RestSearchAction.java | 2 +- .../aggregations/AggregatorParsers.java | 4 +- .../filters/FiltersAggregatorBuilder.java | 30 ++++---- .../bucket/nested/NestedParser.java | 2 +- .../bucket/sampler/SamplerParser.java | 2 +- .../ScriptedMetricAggregatorBuilder.java | 22 +++--- .../metrics/tophits/TopHitsParser.java | 42 +++++------ .../aggregations/pipeline/BucketHelpers.java | 2 +- .../bucketmetrics/BucketMetricsParser.java | 8 +-- .../bucketscript/BucketScriptParser.java | 18 ++--- .../bucketselector/BucketSelectorParser.java | 16 ++--- .../cumulativesum/CumulativeSumParser.java | 6 +- .../DerivativePipelineAggregatorBuilder.java | 26 +++---- .../pipeline/movavg/MovAvgParser.java | 20 +++--- .../pipeline/serialdiff/SerialDiffParser.java | 10 +-- .../support/AbstractValuesSourceParser.java | 14 ++-- .../search/builder/SearchSourceBuilder.java | 72 +++++++++---------- .../fetch/source/FetchSourceContext.java | 8 +-- .../search/rescore/RescoreBuilder.java | 2 +- .../search/sort/FieldSortBuilder.java | 12 ++-- .../search/sort/GeoDistanceSortBuilder.java | 2 +- .../search/sort/ScoreSortBuilder.java | 2 +- .../search/sort/ScriptSortBuilder.java | 2 +- .../search/suggest/SuggestBuilder.java | 2 +- .../search/suggest/SuggestionBuilder.java | 2 +- .../search/suggest/phrase/Laplace.java | 2 +- .../suggest/phrase/LinearInterpolation.java | 2 +- .../phrase/PhraseSuggestionBuilder.java | 2 +- .../search/suggest/phrase/SmoothingModel.java | 2 +- .../search/suggest/phrase/StupidBackoff.java | 2 +- .../suggest/term/TermSuggestionBuilder.java | 2 +- .../suggest/CustomSuggesterSearchIT.java | 2 +- .../index/reindex/RestReindexAction.java | 4 +- 90 files changed, 583 insertions(+), 582 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/ParseFieldMatcherSupplier.java b/core/src/main/java/org/elasticsearch/common/ParseFieldMatcherSupplier.java index b2b7b51ffcb..672890c2b97 100644 --- a/core/src/main/java/org/elasticsearch/common/ParseFieldMatcherSupplier.java +++ b/core/src/main/java/org/elasticsearch/common/ParseFieldMatcherSupplier.java @@ -32,5 +32,5 @@ public interface ParseFieldMatcherSupplier { /** * @return the parseFieldMatcher */ - ParseFieldMatcher parseFieldMatcher(); + ParseFieldMatcher getParseFieldMatcher(); } diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java index a9f6518211c..0f3d899152b 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/ObjectParser.java @@ -129,7 +129,7 @@ public final class ObjectParser { } } } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, DISABLE_COORD_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, DISABLE_COORD_FIELD)) { disableCoord = parser.booleanValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, MINIMUM_SHOULD_MATCH)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, MINIMUM_SHOULD_MATCH)) { minimumShouldMatch = parser.textOrNull(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, MINIMUM_NUMBER_SHOULD_MATCH)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, MINIMUM_NUMBER_SHOULD_MATCH)) { minimumShouldMatch = parser.textOrNull(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, ADJUST_PURE_NEGATIVE)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, ADJUST_PURE_NEGATIVE)) { adjustPureNegative = parser.booleanValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "[bool] query does not support [" + currentFieldName + "]"); diff --git a/core/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java index abfa400da69..2d263fa08ee 100644 --- a/core/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/BoostingQueryBuilder.java @@ -154,21 +154,21 @@ public class BoostingQueryBuilder extends AbstractQueryBuilder if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_OBJECT) { - if (parseContext.parseFieldMatcher().match(currentFieldName, QUERIES_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, QUERIES_FIELD)) { queriesFound = true; QueryBuilder query = parseContext.parseInnerQueryBuilder(); queries.add(query); @@ -146,7 +146,7 @@ public class DisMaxQueryBuilder extends AbstractQueryBuilder throw new ParsingException(parser.getTokenLocation(), "[dis_max] query does not support [" + currentFieldName + "]"); } } else if (token == XContentParser.Token.START_ARRAY) { - if (parseContext.parseFieldMatcher().match(currentFieldName, QUERIES_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, QUERIES_FIELD)) { queriesFound = true; while (token != XContentParser.Token.END_ARRAY) { QueryBuilder query = parseContext.parseInnerQueryBuilder(); @@ -157,11 +157,11 @@ public class DisMaxQueryBuilder extends AbstractQueryBuilder throw new ParsingException(parser.getTokenLocation(), "[dis_max] query does not support [" + currentFieldName + "]"); } } else { - if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, TIE_BREAKER_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, TIE_BREAKER_FIELD)) { tieBreaker = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "[dis_max] query does not support [" + currentFieldName + "]"); diff --git a/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java index cf7a72ebde5..dec6baf067c 100644 --- a/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/ExistsQueryBuilder.java @@ -98,11 +98,11 @@ public class ExistsQueryBuilder extends AbstractQueryBuilder if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, FIELD_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, FIELD_FIELD)) { fieldPattern = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); } else { throw new ParsingException(parser.getTokenLocation(), "[" + ExistsQueryBuilder.NAME + diff --git a/core/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java index 40f14574981..37a2be96280 100644 --- a/core/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/FieldMaskingSpanQueryBuilder.java @@ -118,7 +118,7 @@ public class FieldMaskingSpanQueryBuilder extends AbstractQueryBuilder i if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else { - if (parseContext.parseFieldMatcher().match(currentFieldName, TERM_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, TERM_FIELD)) { value = parser.objectBytes(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, VALUE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, VALUE_FIELD)) { value = parser.objectBytes(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, Fuzziness.FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, Fuzziness.FIELD)) { fuzziness = Fuzziness.parse(parser); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, PREFIX_LENGTH_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, PREFIX_LENGTH_FIELD)) { prefixLength = parser.intValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, MAX_EXPANSIONS_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, MAX_EXPANSIONS_FIELD)) { maxExpansions = parser.intValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, TRANSPOSITIONS_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, TRANSPOSITIONS_FIELD)) { transpositions = parser.booleanValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) { rewrite = parser.textOrNull(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "[fuzzy] query does not support [" + currentFieldName + "]"); @@ -348,7 +348,7 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder i query = new FuzzyQuery(new Term(fieldName, BytesRefs.toBytesRef(value)), maxEdits, prefixLength, maxExpansions, transpositions); } if (query instanceof MultiTermQuery) { - MultiTermQuery.RewriteMethod rewriteMethod = QueryParsers.parseRewriteMethod(context.parseFieldMatcher(), rewrite, null); + MultiTermQuery.RewriteMethod rewriteMethod = QueryParsers.parseRewriteMethod(context.getParseFieldMatcher(), rewrite, null); QueryParsers.setRewriteMethod((MultiTermQuery) query, rewriteMethod); } return query; diff --git a/core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java index a685145e081..db743b971c7 100644 --- a/core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilder.java @@ -418,30 +418,30 @@ public class GeoBoundingBoxQueryBuilder extends AbstractQueryBuilder(); while ((token = parser.nextToken()) != Token.END_ARRAY) { shell.add(GeoUtils.parseGeoPoint(parser)); @@ -288,16 +288,16 @@ public class GeoPolygonQueryBuilder extends AbstractQueryBuilder { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_ARRAY) { - if (parseContext.parseFieldMatcher().match(currentFieldName, VALUES_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, VALUES_FIELD)) { idsProvided = true; while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if ((token == XContentParser.Token.VALUE_STRING) || @@ -156,7 +156,7 @@ public class IdsQueryBuilder extends AbstractQueryBuilder { "Illegal value for id, expecting a string or number, got: " + token); } } - } else if (parseContext.parseFieldMatcher().match(currentFieldName, TYPE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, TYPE_FIELD)) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { String value = parser.textOrNull(); if (value == null) { @@ -169,11 +169,11 @@ public class IdsQueryBuilder extends AbstractQueryBuilder { "] query does not support [" + currentFieldName + "]"); } } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, TYPE_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, TYPE_FIELD)) { types = Collections.singletonList(parser.text()); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "[" + IdsQueryBuilder.NAME + diff --git a/core/src/main/java/org/elasticsearch/index/query/IndicesQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/IndicesQueryBuilder.java index d5caa16ea71..e3f6e32eb19 100644 --- a/core/src/main/java/org/elasticsearch/index/query/IndicesQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/IndicesQueryBuilder.java @@ -157,15 +157,15 @@ public class IndicesQueryBuilder extends AbstractQueryBuilder { matchQuery.setFuzzyPrefixLength(prefixLength); matchQuery.setMaxExpansions(maxExpansions); matchQuery.setTranspositions(fuzzyTranspositions); - matchQuery.setFuzzyRewriteMethod(QueryParsers.parseRewriteMethod(context.parseFieldMatcher(), fuzzyRewrite, null)); + matchQuery.setFuzzyRewriteMethod(QueryParsers.parseRewriteMethod(context.getParseFieldMatcher(), fuzzyRewrite, null)); matchQuery.setLenient(lenient); matchQuery.setCommonTermsCutoff(cutoffFrequency); matchQuery.setZeroTermsQuery(zeroTermsQuery); @@ -540,9 +540,9 @@ public class MatchQueryBuilder extends AbstractQueryBuilder { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, QUERY_FIELD)) { value = parser.objectText(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, TYPE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, TYPE_FIELD)) { String tStr = parser.text(); if ("boolean".equals(tStr)) { type = MatchQuery.Type.BOOLEAN; @@ -553,31 +553,31 @@ public class MatchQueryBuilder extends AbstractQueryBuilder { } else { throw new ParsingException(parser.getTokenLocation(), "[" + NAME + "] query does not support type " + tStr); } - } else if (parseContext.parseFieldMatcher().match(currentFieldName, ANALYZER_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, ANALYZER_FIELD)) { analyzer = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, SLOP_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, SLOP_FIELD)) { slop = parser.intValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, Fuzziness.FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, Fuzziness.FIELD)) { fuzziness = Fuzziness.parse(parser); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, PREFIX_LENGTH_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, PREFIX_LENGTH_FIELD)) { prefixLength = parser.intValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, MAX_EXPANSIONS_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, MAX_EXPANSIONS_FIELD)) { maxExpansion = parser.intValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, OPERATOR_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, OPERATOR_FIELD)) { operator = Operator.fromString(parser.text()); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, MINIMUM_SHOULD_MATCH_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, MINIMUM_SHOULD_MATCH_FIELD)) { minimumShouldMatch = parser.textOrNull(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, FUZZY_REWRITE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, FUZZY_REWRITE_FIELD)) { fuzzyRewrite = parser.textOrNull(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, FUZZY_TRANSPOSITIONS_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, FUZZY_TRANSPOSITIONS_FIELD)) { fuzzyTranspositions = parser.booleanValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, LENIENT_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, LENIENT_FIELD)) { lenient = parser.booleanValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, CUTOFF_FREQUENCY_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, CUTOFF_FREQUENCY_FIELD)) { cutOffFrequency = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, ZERO_TERMS_QUERY_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, ZERO_TERMS_QUERY_FIELD)) { String zeroTermsDocs = parser.text(); if ("none".equalsIgnoreCase(zeroTermsDocs)) { zeroTermsQuery = MatchQuery.ZeroTermsQuery.NONE; @@ -587,7 +587,7 @@ public class MatchQueryBuilder extends AbstractQueryBuilder { throw new ParsingException(parser.getTokenLocation(), "Unsupported zero_terms_docs value [" + zeroTermsDocs + "]"); } - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), diff --git a/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java index 1973a6a4772..b72122439b7 100644 --- a/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java @@ -841,33 +841,33 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { fields.add(parser.text()); } - } else if (parseContext.parseFieldMatcher().match(currentFieldName, Field.LIKE)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, Field.LIKE)) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { parseLikeField(parseContext, likeTexts, likeItems); } - } else if (parseContext.parseFieldMatcher().match(currentFieldName, Field.UNLIKE)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, Field.UNLIKE)) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { parseLikeField(parseContext, unlikeTexts, unlikeItems); } - } else if (parseContext.parseFieldMatcher().match(currentFieldName, Field.IDS)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, Field.IDS)) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (!token.isValue()) { throw new IllegalArgumentException("ids array element should only contain ids"); } likeItems.add(new Item(null, null, parser.text())); } - } else if (parseContext.parseFieldMatcher().match(currentFieldName, Field.DOCS)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, Field.DOCS)) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token != XContentParser.Token.START_OBJECT) { throw new IllegalArgumentException("docs array element should include an object"); } - likeItems.add(Item.parse(parser, parseContext.parseFieldMatcher(), new Item())); + likeItems.add(Item.parse(parser, parseContext.getParseFieldMatcher(), new Item())); } - } else if (parseContext.parseFieldMatcher().match(currentFieldName, Field.STOP_WORDS)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, Field.STOP_WORDS)) { stopWords = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { stopWords.add(parser.text()); @@ -913,9 +913,9 @@ public class MoreLikeThisQueryBuilder extends AbstractQueryBuilder if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_OBJECT) { - if (parseContext.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, QUERY_FIELD)) { query = parseContext.parseInnerQueryBuilder(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, INNER_HITS_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, INNER_HITS_FIELD)) { innerHitBuilder = InnerHitBuilder.fromXContent(parseContext); } else { throw new ParsingException(parser.getTokenLocation(), "[nested] query does not support [" + currentFieldName + "]"); } } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, PATH_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, PATH_FIELD)) { path = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, IGNORE_UNMAPPED_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, IGNORE_UNMAPPED_FIELD)) { ignoreUnmapped = parser.booleanValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, SCORE_MODE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, SCORE_MODE_FIELD)) { scoreMode = HasChildQueryBuilder.parseScoreMode(parser.text()); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "[nested] query does not support [" + currentFieldName + "]"); diff --git a/core/src/main/java/org/elasticsearch/index/query/ParentIdQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/ParentIdQueryBuilder.java index 5d664a132ad..419149ce992 100644 --- a/core/src/main/java/org/elasticsearch/index/query/ParentIdQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/ParentIdQueryBuilder.java @@ -130,15 +130,15 @@ public final class ParentIdQueryBuilder extends AbstractQueryBuilder if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else { - if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, PREFIX_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, PREFIX_FIELD)) { value = parser.textOrNull(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) { rewrite = parser.textOrNull(); } else { throw new ParsingException(parser.getTokenLocation(), @@ -176,7 +176,7 @@ public class PrefixQueryBuilder extends AbstractQueryBuilder @Override protected Query doToQuery(QueryShardContext context) throws IOException { - MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(context.parseFieldMatcher(), rewrite, null); + MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(context.getParseFieldMatcher(), rewrite, null); Query query = null; MappedFieldType fieldType = context.fieldMapper(fieldName); diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java index ee6c49234fd..c98ca70fc23 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java @@ -124,7 +124,7 @@ public class QueryParseContext implements ParseFieldMatcherSupplier { } @Override - public ParseFieldMatcher parseFieldMatcher() { + public ParseFieldMatcher getParseFieldMatcher() { return parseFieldMatcher; } diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java index 70de640539f..43535d689a9 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java @@ -20,6 +20,8 @@ package org.elasticsearch.index.query; import org.apache.lucene.index.IndexReader; import org.elasticsearch.client.Client; +import org.elasticsearch.common.ParseFieldMatcher; +import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.indices.query.IndicesQueriesRegistry; @@ -28,7 +30,7 @@ import org.elasticsearch.script.ScriptService; /** * Context object used to rewrite {@link QueryBuilder} instances into simplified version. */ -public class QueryRewriteContext { +public class QueryRewriteContext implements ParseFieldMatcherSupplier { protected final MapperService mapperService; protected final ScriptService scriptService; protected final IndexSettings indexSettings; @@ -80,12 +82,21 @@ public class QueryRewriteContext { return reader; } + public void parseFieldMatcher(ParseFieldMatcher parseFieldMatcher) { + this.parseContext.parseFieldMatcher(parseFieldMatcher); + } + + @Override + public ParseFieldMatcher getParseFieldMatcher() { + return parseContext.getParseFieldMatcher(); + } + /** * Returns a new {@link QueryParseContext} to parse template or wrapped queries. */ public QueryParseContext newParseContext() { QueryParseContext queryParseContext = new QueryParseContext(indicesQueriesRegistry); - queryParseContext.parseFieldMatcher(parseContext.parseFieldMatcher()); + queryParseContext.parseFieldMatcher(parseContext.getParseFieldMatcher()); return queryParseContext; } } diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java index 6420c235c2e..340bf0e9715 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java @@ -19,6 +19,14 @@ package org.elasticsearch.index.query; +import static java.util.Collections.unmodifiableMap; + +import java.io.IOException; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.index.IndexReader; import org.apache.lucene.queryparser.classic.MapperQueryParser; @@ -29,7 +37,6 @@ import org.apache.lucene.search.similarities.Similarity; import org.elasticsearch.Version; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; @@ -58,18 +65,10 @@ import org.elasticsearch.search.fetch.innerhits.InnerHitsContext; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.lookup.SearchLookup; -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import static java.util.Collections.unmodifiableMap; - /** * Context object used to create lucene queries on the shard level. */ -public class QueryShardContext extends QueryRewriteContext implements ParseFieldMatcherSupplier { +public class QueryShardContext extends QueryRewriteContext { private final MapperService mapperService; private final SimilarityService similarityService; @@ -114,15 +113,6 @@ public class QueryShardContext extends QueryRewriteContext implements ParseField this.types = source.getTypes(); } - public void parseFieldMatcher(ParseFieldMatcher parseFieldMatcher) { - this.parseContext.parseFieldMatcher(parseFieldMatcher); - } - - @Override - public ParseFieldMatcher parseFieldMatcher() { - return parseContext.parseFieldMatcher(); - } - public void reset() { allowUnmappedFields = indexSettings.isDefaultAllowUnmappedFields(); this.parseFieldMatcher(ParseFieldMatcher.EMPTY); diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java index e49b0cace4f..6806ae944c2 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryStringQueryBuilder.java @@ -667,7 +667,7 @@ public class QueryStringQueryBuilder extends AbstractQueryBuilder i if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else { - if (parseContext.parseFieldMatcher().match(currentFieldName, FROM_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, FROM_FIELD)) { from = parser.objectBytes(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, TO_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, TO_FIELD)) { to = parser.objectBytes(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, INCLUDE_LOWER_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, INCLUDE_LOWER_FIELD)) { includeLower = parser.booleanValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, INCLUDE_UPPER_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, INCLUDE_UPPER_FIELD)) { includeUpper = parser.booleanValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, GT_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, GT_FIELD)) { from = parser.objectBytes(); includeLower = false; - } else if (parseContext.parseFieldMatcher().match(currentFieldName, GTE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, GTE_FIELD)) { from = parser.objectBytes(); includeLower = true; - } else if (parseContext.parseFieldMatcher().match(currentFieldName, LT_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, LT_FIELD)) { to = parser.objectBytes(); includeUpper = false; - } else if (parseContext.parseFieldMatcher().match(currentFieldName, LTE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, LTE_FIELD)) { to = parser.objectBytes(); includeUpper = true; - } else if (parseContext.parseFieldMatcher().match(currentFieldName, TIME_ZONE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, TIME_ZONE_FIELD)) { timeZone = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, FORMAT_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, FORMAT_FIELD)) { format = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), @@ -358,9 +358,9 @@ public class RangeQueryBuilder extends AbstractQueryBuilder i } } } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, NAME_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, NAME_FIELD)) { queryName = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, FIELDDATA_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, FIELDDATA_FIELD)) { // ignore } else { throw new ParsingException(parser.getTokenLocation(), "[range] query does not support [" + currentFieldName + "]"); diff --git a/core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java index 7a19d1f719e..c895830d5a5 100644 --- a/core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java @@ -203,20 +203,20 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else { - if (parseContext.parseFieldMatcher().match(currentFieldName, VALUE_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, VALUE_FIELD)) { value = parser.textOrNull(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, REWRITE_FIELD)) { rewrite = parser.textOrNull(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, FLAGS_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, FLAGS_FIELD)) { String flags = parser.textOrNull(); flagsValue = RegexpFlag.resolveValue(flags); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, MAX_DETERMINIZED_STATES_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, MAX_DETERMINIZED_STATES_FIELD)) { maxDeterminizedStates = parser.intValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, FLAGS_VALUE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, FLAGS_VALUE_FIELD)) { flagsValue = parser.intValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), @@ -225,7 +225,7 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder } } } else { - if (parseContext.parseFieldMatcher().match(currentFieldName, NAME_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, NAME_FIELD)) { queryName = parser.text(); } else { fieldName = currentFieldName; @@ -252,7 +252,7 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder @Override protected Query doToQuery(QueryShardContext context) throws QueryShardException, IOException { - MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(context.parseFieldMatcher(), rewrite, null); + MultiTermQuery.RewriteMethod method = QueryParsers.parseRewriteMethod(context.getParseFieldMatcher(), rewrite, null); Query query = null; MappedFieldType fieldType = context.fieldMapper(fieldName); diff --git a/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java index 794160881f5..65be61d672b 100644 --- a/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java @@ -112,20 +112,20 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder } else if (parseContext.isDeprecatedSetting(currentFieldName)) { // skip } else if (token == XContentParser.Token.START_OBJECT) { - if (parseContext.parseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { - script = Script.parse(parser, parseContext.parseFieldMatcher()); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, PARAMS_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { + script = Script.parse(parser, parseContext.getParseFieldMatcher()); + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, PARAMS_FIELD)) { // TODO remove in 3.0 (here to support old script APIs) params = parser.map(); } else { throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]"); } } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (!scriptParameterParser.token(currentFieldName, token, parser, parseContext.parseFieldMatcher())) { + } else if (!scriptParameterParser.token(currentFieldName, token, parser, parseContext.getParseFieldMatcher())) { throw new ParsingException(parser.getTokenLocation(), "[script] query does not support [" + currentFieldName + "]"); } } diff --git a/core/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java b/core/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java index 86c32ea3670..5e2c88af923 100644 --- a/core/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/SimpleQueryStringBuilder.java @@ -439,7 +439,7 @@ public class SimpleQueryStringBuilder extends AbstractQueryBuilder)) { throw new ParsingException(parser.getTokenLocation(), "span_containing [big] must be of type span query"); } big = (SpanQueryBuilder) query; - } else if (parseContext.parseFieldMatcher().match(currentFieldName, LITTLE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, LITTLE_FIELD)) { QueryBuilder query = parseContext.parseInnerQueryBuilder(); if (!(query instanceof SpanQueryBuilder)) { throw new ParsingException(parser.getTokenLocation(), "span_containing [little] must be of type span query"); @@ -131,9 +131,9 @@ public class SpanContainingQueryBuilder extends AbstractQueryBuilder if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_ARRAY) { - if (parseContext.parseFieldMatcher().match(currentFieldName, CLAUSES_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, CLAUSES_FIELD)) { while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { QueryBuilder query = parseContext.parseInnerQueryBuilder(); if (!(query instanceof SpanQueryBuilder)) { @@ -121,9 +121,9 @@ public class SpanOrQueryBuilder extends AbstractQueryBuilder throw new ParsingException(parser.getTokenLocation(), "[span_or] query does not support [" + currentFieldName + "]"); } } else { - if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "[span_or] query does not support [" + currentFieldName + "]"); diff --git a/core/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java index ac90148ef53..a4bafc5001c 100644 --- a/core/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/SpanTermQueryBuilder.java @@ -115,13 +115,13 @@ public class SpanTermQueryBuilder extends BaseTermQueryBuilder { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else { - if (parseContext.parseFieldMatcher().match(currentFieldName, TERM_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, TERM_FIELD)) { value = parser.objectBytes(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, VALUE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, VALUE_FIELD)) { value = parser.objectBytes(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); } else { throw new ParsingException(parser.getTokenLocation(), diff --git a/core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java index 2ffe90faf74..19fe8da3011 100644 --- a/core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/TermsQueryBuilder.java @@ -271,9 +271,9 @@ public class TermsQueryBuilder extends AbstractQueryBuilder { fieldName = currentFieldName; termsLookup = TermsLookup.parseTermsLookup(parser); } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), diff --git a/core/src/main/java/org/elasticsearch/index/query/TypeQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/TypeQueryBuilder.java index 1e4490cfabf..129b0275527 100644 --- a/core/src/main/java/org/elasticsearch/index/query/TypeQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/TypeQueryBuilder.java @@ -94,11 +94,11 @@ public class TypeQueryBuilder extends AbstractQueryBuilder { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.NAME_FIELD)) { queryName = parser.text(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, AbstractQueryBuilder.BOOST_FIELD)) { boost = parser.floatValue(); - } else if (parseContext.parseFieldMatcher().match(currentFieldName, VALUE_FIELD)) { + } else if (parseContext.getParseFieldMatcher().match(currentFieldName, VALUE_FIELD)) { type = parser.utf8Bytes(); } else { throw new ParsingException(parser.getTokenLocation(), diff --git a/core/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java index 13a28d93b89..bf6921e9452 100644 --- a/core/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/WildcardQueryBuilder.java @@ -155,15 +155,15 @@ public class WildcardQueryBuilder extends AbstractQueryBuilder> im XContentBuilder builder = XContentFactory.jsonBuilder(); builder.copyCurrentStructure(parser); functionBytes = builder.bytes(); - } else if (context.parseFieldMatcher().match(currentFieldName, MULTI_VALUE_MODE)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, MULTI_VALUE_MODE)) { multiValueMode = MultiValueMode.fromString(parser.text()); } else { throw new ParsingException(parser.getTokenLocation(), "malformed score function score parameters."); diff --git a/core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java index a4b5fdd806c..3fcfa257c86 100644 --- a/core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java @@ -454,7 +454,7 @@ public class FunctionScoreQueryBuilder extends AbstractQueryBuilder scoreFunction = scoreFunctionsRegistry - .lookup(currentFieldName, parseContext.parser(), parseContext.parseFieldMatcher()) + .lookup(currentFieldName, parseContext.parser(), parseContext.getParseFieldMatcher()) .fromXContent(parseContext); filterFunctionBuilders.add(new FunctionScoreQueryBuilder.FilterFunctionBuilder(scoreFunction)); } } else if (token == XContentParser.Token.START_ARRAY) { - if (parseContext.parseFieldMatcher().match(currentFieldName, FUNCTIONS_FIELD)) { + if (parseContext.getParseFieldMatcher().match(currentFieldName, FUNCTIONS_FIELD)) { if (singleFunctionFound) { String errorString = "already found [" + singleFunctionName + "], now encountering [functions]."; handleMisplacedFunctionsDeclaration(parser.getTokenLocation(), errorString); @@ -495,17 +495,17 @@ public class FunctionScoreQueryBuilder extends AbstractQueryBuilder { public static final String NAME = InternalFilters.TYPE.name(); public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); @@ -220,21 +220,21 @@ public class FiltersAggregatorBuilder extends AggregatorBuilder(); String key = null; while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { @@ -243,7 +243,7 @@ public class FiltersAggregatorBuilder extends AggregatorBuilder filter = queryParseContext.parseInnerQueryBuilder(); keyedFilters.add(new FiltersAggregator.KeyedFilter(key, filter == null ? matchAllQuery() : filter)); } @@ -253,12 +253,12 @@ public class FiltersAggregatorBuilder extends AggregatorBuilder(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { QueryParseContext queryParseContext = new QueryParseContext(queriesRegistry); queryParseContext.reset(parser); - queryParseContext.parseFieldMatcher(context.parseFieldMatcher()); + queryParseContext.parseFieldMatcher(context.getParseFieldMatcher()); QueryBuilder filter = queryParseContext.parseInnerQueryBuilder(); nonKeyedFilters.add(filter == null ? QueryBuilders.matchAllQuery() : filter); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedParser.java index fb2fe3b701c..7584eb9148f 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedParser.java @@ -46,7 +46,7 @@ public class NestedParser implements Aggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, NestedAggregator.PATH_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, NestedAggregator.PATH_FIELD)) { path = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerParser.java index 4a366511ca1..22efaf4f28c 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerParser.java @@ -48,7 +48,7 @@ public class SamplerParser implements Aggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_NUMBER) { - if (context.parseFieldMatcher().match(currentFieldName, SamplerAggregator.SHARD_SIZE_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, SamplerAggregator.SHARD_SIZE_FIELD)) { shardSize = parser.intValue(); } else { throw new ParsingException(parser.getTokenLocation(), diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorBuilder.java index 355fdd76b98..677fd7b1617 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/scripted/ScriptedMetricAggregatorBuilder.java @@ -240,24 +240,24 @@ public class ScriptedMetricAggregatorBuilder extends AggregatorBuilder fieldNames = new ArrayList<>(); fieldNames.add(parser.text()); factory.fields(fieldNames); - } else if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { factory.sort(parser.text()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); } } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) { factory.fetchSource(FetchSourceContext.parse(context)); - } else if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELDS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELDS_FIELD)) { List scriptFields = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { String scriptFieldName = parser.currentName(); @@ -90,9 +90,9 @@ public class TopHitsParser implements Aggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { - if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELD)) { - script = Script.parse(parser, context.parseFieldMatcher()); - } else if (context.parseFieldMatcher().match(currentFieldName, + if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELD)) { + script = Script.parse(parser, context.getParseFieldMatcher()); + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.IGNORE_FAILURE_FIELD)) { ignoreFailure = parser.booleanValue(); } else { @@ -101,8 +101,8 @@ public class TopHitsParser implements Aggregator.Parser { parser.getTokenLocation()); } } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELD)) { - script = Script.parse(parser, context.parseFieldMatcher()); + if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELD)) { + script = Script.parse(parser, context.getParseFieldMatcher()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", @@ -120,9 +120,9 @@ public class TopHitsParser implements Aggregator.Parser { } } factory.scriptFields(scriptFields); - } else if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.HIGHLIGHT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.HIGHLIGHT_FIELD)) { factory.highlighter(HighlightBuilder.fromXContent(context)); - } else if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { List> sorts = SortBuilder.fromXContent(context); factory.sorts(sorts); } else { @@ -131,7 +131,7 @@ public class TopHitsParser implements Aggregator.Parser { } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FIELDS_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FIELDS_FIELD)) { List fieldNames = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { @@ -142,7 +142,7 @@ public class TopHitsParser implements Aggregator.Parser { } } factory.fields(fieldNames); - } else if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FIELDDATA_FIELDS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FIELDDATA_FIELDS_FIELD)) { List fieldDataFields = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { @@ -153,10 +153,10 @@ public class TopHitsParser implements Aggregator.Parser { } } factory.fieldDataFields(fieldDataFields); - } else if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { List> sorts = SortBuilder.fromXContent(context); factory.sorts(sorts); - } else if (context.parseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) { factory.fetchSource(FetchSourceContext.parse(context)); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketHelpers.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketHelpers.java index 98d364bcd07..21337b73043 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketHelpers.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/BucketHelpers.java @@ -64,7 +64,7 @@ public class BucketHelpers { public static GapPolicy parse(QueryParseContext context, String text, XContentLocation tokenLocation) { GapPolicy result = null; for (GapPolicy policy : values()) { - if (context.parseFieldMatcher().match(text, policy.parseField)) { + if (context.getParseFieldMatcher().match(text, policy.parseField)) { if (result == null) { result = policy; } else { diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsParser.java index dd2c4b20630..dbd0a5d128c 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/BucketMetricsParser.java @@ -59,17 +59,17 @@ public abstract class BucketMetricsParser implements PipelineAggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, FORMAT)) { + if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) { format = parser.text(); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { bucketsPaths = new String[] { parser.text() }; - } else if (context.parseFieldMatcher().match(currentFieldName, GAP_POLICY)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) { gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation()); } else { leftover.put(currentFieldName, parser.text()); } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { List paths = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { String path = parser.text(); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptParser.java index 91c9daecb84..9ec7cd40527 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptParser.java @@ -59,21 +59,21 @@ public class BucketScriptParser implements PipelineAggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, FORMAT)) { + if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) { format = parser.text(); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { bucketsPathsMap = new HashMap<>(); bucketsPathsMap.put("_value", parser.text()); - } else if (context.parseFieldMatcher().match(currentFieldName, GAP_POLICY)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) { gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation()); - } else if (context.parseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { - script = Script.parse(parser, context.parseFieldMatcher()); + } else if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { + script = Script.parse(parser, context.getParseFieldMatcher()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { List paths = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { String path = parser.text(); @@ -88,9 +88,9 @@ public class BucketScriptParser implements PipelineAggregator.Parser { "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { - script = Script.parse(parser, context.parseFieldMatcher()); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { + script = Script.parse(parser, context.getParseFieldMatcher()); + } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { Map map = parser.map(); bucketsPathsMap = new HashMap<>(); for (Map.Entry entry : map.entrySet()) { diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorParser.java index 8573cc737a8..320331afac4 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorParser.java @@ -58,19 +58,19 @@ public class BucketSelectorParser implements PipelineAggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { bucketsPathsMap = new HashMap<>(); bucketsPathsMap.put("_value", parser.text()); - } else if (context.parseFieldMatcher().match(currentFieldName, GAP_POLICY)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) { gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation()); - } else if (context.parseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { - script = Script.parse(parser, context.parseFieldMatcher()); + } else if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { + script = Script.parse(parser, context.getParseFieldMatcher()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { List paths = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { String path = parser.text(); @@ -85,9 +85,9 @@ public class BucketSelectorParser implements PipelineAggregator.Parser { "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { - script = Script.parse(parser, context.parseFieldMatcher()); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { + script = Script.parse(parser, context.getParseFieldMatcher()); + } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { Map map = parser.map(); bucketsPathsMap = new HashMap<>(); for (Map.Entry entry : map.entrySet()) { diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumParser.java index de0c9531477..1ae71c0f017 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumParser.java @@ -52,16 +52,16 @@ public class CumulativeSumParser implements PipelineAggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, FORMAT)) { + if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) { format = parser.text(); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { bucketsPaths = new String[] { parser.text() }; } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { List paths = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { String path = parser.text(); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java index f897bc6eafd..01238b48d53 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java @@ -19,6 +19,12 @@ package org.elasticsearch.search.aggregations.pipeline.derivative; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; + import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; @@ -33,20 +39,14 @@ import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.bucket.histogram.AbstractHistogramAggregatorFactory; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregatorFactory; import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval; +import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder; -import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Objects; public class DerivativePipelineAggregatorBuilder extends PipelineAggregatorBuilder { public static final String NAME = DerivativePipelineAggregator.TYPE.name(); public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); - + private static final ParseField FORMAT_FIELD = new ParseField("format"); private static final ParseField GAP_POLICY_FIELD = new ParseField("gap_policy"); private static final ParseField UNIT_FIELD = new ParseField("unit"); @@ -204,20 +204,20 @@ public class DerivativePipelineAggregatorBuilder extends PipelineAggregatorBuild if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, FORMAT_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, FORMAT_FIELD)) { format = parser.text(); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH_FIELD)) { bucketsPaths = new String[] { parser.text() }; - } else if (context.parseFieldMatcher().match(currentFieldName, GAP_POLICY_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY_FIELD)) { gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation()); - } else if (context.parseFieldMatcher().match(currentFieldName, UNIT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, UNIT_FIELD)) { units = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH_FIELD)) { List paths = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { String path = parser.text(); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java index d3af7cb95a0..1c63099c745 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java @@ -74,13 +74,13 @@ public class MovAvgParser implements PipelineAggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_NUMBER) { - if (context.parseFieldMatcher().match(currentFieldName, WINDOW)) { + if (context.getParseFieldMatcher().match(currentFieldName, WINDOW)) { window = parser.intValue(); if (window <= 0) { throw new ParsingException(parser.getTokenLocation(), "[" + currentFieldName + "] value must be a positive, " + "non-zero integer. Value supplied was [" + predict + "] in [" + pipelineAggregatorName + "]."); } - } else if (context.parseFieldMatcher().match(currentFieldName, PREDICT)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, PREDICT)) { predict = parser.intValue(); if (predict <= 0) { throw new ParsingException(parser.getTokenLocation(), "[" + currentFieldName + "] value must be a positive integer." @@ -91,20 +91,20 @@ public class MovAvgParser implements PipelineAggregator.Parser { "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, FORMAT)) { + if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) { format = parser.text(); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { bucketsPaths = new String[] { parser.text() }; - } else if (context.parseFieldMatcher().match(currentFieldName, GAP_POLICY)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) { gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation()); - } else if (context.parseFieldMatcher().match(currentFieldName, MODEL)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, MODEL)) { model = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { List paths = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { String path = parser.text(); @@ -116,14 +116,14 @@ public class MovAvgParser implements PipelineAggregator.Parser { "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, SETTINGS)) { + if (context.getParseFieldMatcher().match(currentFieldName, SETTINGS)) { settings = parser.map(); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.VALUE_BOOLEAN) { - if (context.parseFieldMatcher().match(currentFieldName, MINIMIZE)) { + if (context.getParseFieldMatcher().match(currentFieldName, MINIMIZE)) { minimize = parser.booleanValue(); } else { throw new ParsingException(parser.getTokenLocation(), @@ -163,7 +163,7 @@ public class MovAvgParser implements PipelineAggregator.Parser { MovAvgModel movAvgModel; try { - movAvgModel = modelParser.parse(settings, pipelineAggregatorName, factory.window(), context.parseFieldMatcher()); + movAvgModel = modelParser.parse(settings, pipelineAggregatorName, factory.window(), context.getParseFieldMatcher()); } catch (ParseException exception) { throw new ParsingException(parser.getTokenLocation(), "Could not parse settings for model [" + model + "].", exception); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffParser.java index 8a2a0df2edb..5eb9858a6dc 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffParser.java @@ -55,18 +55,18 @@ public class SerialDiffParser implements PipelineAggregator.Parser { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, FORMAT)) { + if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) { format = parser.text(); - } else if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { bucketsPaths = new String[] { parser.text() }; - } else if (context.parseFieldMatcher().match(currentFieldName, GAP_POLICY)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) { gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.VALUE_NUMBER) { - if (context.parseFieldMatcher().match(currentFieldName, LAG)) { + if (context.getParseFieldMatcher().match(currentFieldName, LAG)) { lag = parser.intValue(true); if (lag <= 0) { throw new ParsingException(parser.getTokenLocation(), @@ -79,7 +79,7 @@ public class SerialDiffParser implements PipelineAggregator.Parser { "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "]."); } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) { List paths = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { String path = parser.text(); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/support/AbstractValuesSourceParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/support/AbstractValuesSourceParser.java index d864fc97664..bf68f4d59f2 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/support/AbstractValuesSourceParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/support/AbstractValuesSourceParser.java @@ -103,7 +103,7 @@ public abstract class AbstractValuesSourceParser currentFieldName = parser.currentName(); } else if ("missing".equals(currentFieldName) && token.isValue()) { missing = parser.objectText(); - } else if (timezoneAware && context.parseFieldMatcher().match(currentFieldName, TIME_ZONE)) { + } else if (timezoneAware && context.getParseFieldMatcher().match(currentFieldName, TIME_ZONE)) { if (token == XContentParser.Token.VALUE_STRING) { timezone = DateTimeZone.forID(parser.text()); } else if (token == XContentParser.Token.VALUE_NUMBER) { @@ -126,22 +126,22 @@ public abstract class AbstractValuesSourceParser + valueType + "]. [" + type() + "] aggregation can only work on value of type [" + targetValueType + "]"); } - } else if (!token(aggregationName, currentFieldName, token, parser, context.parseFieldMatcher(), otherOptions)) { + } else if (!token(aggregationName, currentFieldName, token, parser, context.getParseFieldMatcher(), otherOptions)) { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]."); } - } else if (!token(aggregationName, currentFieldName, token, parser, context.parseFieldMatcher(), otherOptions)) { + } else if (!token(aggregationName, currentFieldName, token, parser, context.getParseFieldMatcher(), otherOptions)) { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]."); } } else if (scriptable && token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { - script = Script.parse(parser, context.parseFieldMatcher()); - } else if (!token(aggregationName, currentFieldName, token, parser, context.parseFieldMatcher(), otherOptions)) { + if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) { + script = Script.parse(parser, context.getParseFieldMatcher()); + } else if (!token(aggregationName, currentFieldName, token, parser, context.getParseFieldMatcher(), otherOptions)) { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]."); } - } else if (!token(aggregationName, currentFieldName, token, parser, context.parseFieldMatcher(), otherOptions)) { + } else if (!token(aggregationName, currentFieldName, token, parser, context.getParseFieldMatcher(), otherOptions)) { throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " [" + currentFieldName + "] in [" + aggregationName + "]."); } 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 a0cd54d4d87..a39d0273c2f 100644 --- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java @@ -995,47 +995,47 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { - if (context.parseFieldMatcher().match(currentFieldName, FROM_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, FROM_FIELD)) { from = parser.intValue(); - } else if (context.parseFieldMatcher().match(currentFieldName, SIZE_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SIZE_FIELD)) { size = parser.intValue(); - } else if (context.parseFieldMatcher().match(currentFieldName, TIMEOUT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, TIMEOUT_FIELD)) { timeoutInMillis = parser.longValue(); - } else if (context.parseFieldMatcher().match(currentFieldName, TERMINATE_AFTER_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, TERMINATE_AFTER_FIELD)) { terminateAfter = parser.intValue(); - } else if (context.parseFieldMatcher().match(currentFieldName, MIN_SCORE_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, MIN_SCORE_FIELD)) { minScore = parser.floatValue(); - } else if (context.parseFieldMatcher().match(currentFieldName, VERSION_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, VERSION_FIELD)) { version = parser.booleanValue(); - } else if (context.parseFieldMatcher().match(currentFieldName, EXPLAIN_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, EXPLAIN_FIELD)) { explain = parser.booleanValue(); - } else if (context.parseFieldMatcher().match(currentFieldName, TRACK_SCORES_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, TRACK_SCORES_FIELD)) { trackScores = parser.booleanValue(); - } else if (context.parseFieldMatcher().match(currentFieldName, _SOURCE_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, _SOURCE_FIELD)) { fetchSourceContext = FetchSourceContext.parse(context); - } else if (context.parseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) { field(parser.text()); - } else if (context.parseFieldMatcher().match(currentFieldName, SORT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SORT_FIELD)) { sort(parser.text()); - } else if (context.parseFieldMatcher().match(currentFieldName, PROFILE_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, PROFILE_FIELD)) { profile = parser.booleanValue(); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); } } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, QUERY_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, QUERY_FIELD)) { queryBuilder = context.parseInnerQueryBuilder(); - } else if (context.parseFieldMatcher().match(currentFieldName, POST_FILTER_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, POST_FILTER_FIELD)) { postQueryBuilder = context.parseInnerQueryBuilder(); - } else if (context.parseFieldMatcher().match(currentFieldName, _SOURCE_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, _SOURCE_FIELD)) { fetchSourceContext = FetchSourceContext.parse(context); - } else if (context.parseFieldMatcher().match(currentFieldName, SCRIPT_FIELDS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SCRIPT_FIELDS_FIELD)) { scriptFields = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { scriptFields.add(new ScriptField(context)); } - } else if (context.parseFieldMatcher().match(currentFieldName, INDICES_BOOST_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, INDICES_BOOST_FIELD)) { indexBoost = new ObjectFloatHashMap(); while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { @@ -1047,17 +1047,17 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ parser.getTokenLocation()); } } - } else if (context.parseFieldMatcher().match(currentFieldName, AGGREGATIONS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, AGGREGATIONS_FIELD)) { aggregations = aggParsers.parseAggregators(context); - } else if (context.parseFieldMatcher().match(currentFieldName, HIGHLIGHT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, HIGHLIGHT_FIELD)) { highlightBuilder = HighlightBuilder.fromXContent(context); - } else if (context.parseFieldMatcher().match(currentFieldName, INNER_HITS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, INNER_HITS_FIELD)) { innerHitsBuilder = InnerHitsBuilder.fromXContent(context); - } else if (context.parseFieldMatcher().match(currentFieldName, SUGGEST_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SUGGEST_FIELD)) { suggestBuilder = SuggestBuilder.fromXContent(context, suggesters); - } else if (context.parseFieldMatcher().match(currentFieldName, SORT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SORT_FIELD)) { sorts = new ArrayList<>(SortBuilder.fromXContent(context)); - } else if (context.parseFieldMatcher().match(currentFieldName, EXT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, EXT_FIELD)) { XContentBuilder xContentBuilder = XContentFactory.jsonBuilder().copyCurrentStructure(parser); ext = xContentBuilder.bytes(); } else { @@ -1066,7 +1066,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ } } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, FIELDS_FIELD)) { fieldNames = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { @@ -1076,7 +1076,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); } } - } else if (context.parseFieldMatcher().match(currentFieldName, FIELDDATA_FIELDS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, FIELDDATA_FIELDS_FIELD)) { fieldDataFields = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { @@ -1086,14 +1086,14 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); } } - } else if (context.parseFieldMatcher().match(currentFieldName, SORT_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SORT_FIELD)) { sorts = new ArrayList<>(SortBuilder.fromXContent(context)); - } else if (context.parseFieldMatcher().match(currentFieldName, RESCORE_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, RESCORE_FIELD)) { rescoreBuilders = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { rescoreBuilders.add(RescoreBuilder.parseFromXContent(context)); } - } else if (context.parseFieldMatcher().match(currentFieldName, STATS_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, STATS_FIELD)) { stats = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { @@ -1103,10 +1103,10 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); } } - } else if (context.parseFieldMatcher().match(currentFieldName, _SOURCE_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, _SOURCE_FIELD)) { fetchSourceContext = FetchSourceContext.parse(context); - } else if (context.parseFieldMatcher().match(currentFieldName, SEARCH_AFTER)) { - searchAfterBuilder = SearchAfterBuilder.fromXContent(parser, context.parseFieldMatcher()); + } else if (context.getParseFieldMatcher().match(currentFieldName, SEARCH_AFTER)) { + searchAfterBuilder = SearchAfterBuilder.fromXContent(parser, context.getParseFieldMatcher()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); @@ -1305,17 +1305,17 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token.isValue()) { - if (context.parseFieldMatcher().match(currentFieldName, SCRIPT_FIELD)) { - script = Script.parse(parser, context.parseFieldMatcher()); - } else if (context.parseFieldMatcher().match(currentFieldName, IGNORE_FAILURE_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, SCRIPT_FIELD)) { + script = Script.parse(parser, context.getParseFieldMatcher()); + } else if (context.getParseFieldMatcher().match(currentFieldName, IGNORE_FAILURE_FIELD)) { ignoreFailure = parser.booleanValue(); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); } } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, SCRIPT_FIELD)) { - script = Script.parse(parser, context.parseFieldMatcher()); + if (context.getParseFieldMatcher().match(currentFieldName, SCRIPT_FIELD)) { + script = Script.parse(parser, context.getParseFieldMatcher()); } else { throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); 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 891a2f09ec6..658bb1d72ee 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 @@ -169,7 +169,7 @@ public class FetchSourceContext implements Streamable, ToXContent { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_ARRAY) { - if (context.parseFieldMatcher().match(currentFieldName, INCLUDES_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, INCLUDES_FIELD)) { List includesList = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { @@ -180,7 +180,7 @@ public class FetchSourceContext implements Streamable, ToXContent { } } includes = includesList.toArray(new String[includesList.size()]); - } else if (context.parseFieldMatcher().match(currentFieldName, EXCLUDES_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, EXCLUDES_FIELD)) { List excludesList = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { if (token == XContentParser.Token.VALUE_STRING) { @@ -196,9 +196,9 @@ public class FetchSourceContext implements Streamable, ToXContent { parser.getTokenLocation()); } } else if (token == XContentParser.Token.VALUE_STRING) { - if (context.parseFieldMatcher().match(currentFieldName, INCLUDES_FIELD)) { + if (context.getParseFieldMatcher().match(currentFieldName, INCLUDES_FIELD)) { includes = new String[] {parser.text()}; - } else if (context.parseFieldMatcher().match(currentFieldName, EXCLUDES_FIELD)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, EXCLUDES_FIELD)) { excludes = new String[] {parser.text()}; } } else { diff --git a/core/src/main/java/org/elasticsearch/search/rescore/RescoreBuilder.java b/core/src/main/java/org/elasticsearch/search/rescore/RescoreBuilder.java index ae85a4e3fae..5b33769af44 100644 --- a/core/src/main/java/org/elasticsearch/search/rescore/RescoreBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/rescore/RescoreBuilder.java @@ -85,7 +85,7 @@ public abstract class RescoreBuilder> extends ToXC if (token == XContentParser.Token.FIELD_NAME) { fieldName = parser.currentName(); } else if (token.isValue()) { - if (parseContext.parseFieldMatcher().match(fieldName, WINDOW_SIZE_FIELD)) { + if (parseContext.getParseFieldMatcher().match(fieldName, WINDOW_SIZE_FIELD)) { windowSize = parser.intValue(); } else { throw new ParsingException(parser.getTokenLocation(), "rescore doesn't support [" + fieldName + "]"); diff --git a/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java index 21acd2b6c45..dfced1d8f57 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java @@ -337,17 +337,17 @@ public class FieldSortBuilder extends SortBuilder { if (token == XContentParser.Token.FIELD_NAME) { currentFieldName = parser.currentName(); } else if (token == XContentParser.Token.START_OBJECT) { - if (context.parseFieldMatcher().match(currentFieldName, NESTED_FILTER)) { + if (context.getParseFieldMatcher().match(currentFieldName, NESTED_FILTER)) { nestedFilter = context.parseInnerQueryBuilder(); } else { throw new ParsingException(parser.getTokenLocation(), "Expected " + NESTED_FILTER.getPreferredName() + " element."); } } else if (token.isValue()) { - if (context.parseFieldMatcher().match(currentFieldName, NESTED_PATH)) { + if (context.getParseFieldMatcher().match(currentFieldName, NESTED_PATH)) { nestedPath = parser.text(); - } else if (context.parseFieldMatcher().match(currentFieldName, MISSING)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, MISSING)) { missing = parser.objectText(); - } else if (context.parseFieldMatcher().match(currentFieldName, ORDER)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, ORDER)) { String sortOrder = parser.text(); if ("asc".equals(sortOrder)) { order = SortOrder.ASC; @@ -356,9 +356,9 @@ public class FieldSortBuilder extends SortBuilder { } else { throw new ParsingException(parser.getTokenLocation(), "Sort order [{}] not supported.", sortOrder); } - } else if (context.parseFieldMatcher().match(currentFieldName, SORT_MODE)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, SORT_MODE)) { sortMode = SortMode.fromString(parser.text()); - } else if (context.parseFieldMatcher().match(currentFieldName, UNMAPPED_TYPE)) { + } else if (context.getParseFieldMatcher().match(currentFieldName, UNMAPPED_TYPE)) { unmappedType = parser.text(); } else { throw new ParsingException(parser.getTokenLocation(), "Option [{}] not supported.", currentFieldName); diff --git a/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java index d8878fed298..ef86c45afd8 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java @@ -407,7 +407,7 @@ public class GeoDistanceSortBuilder extends SortBuilder */ public static GeoDistanceSortBuilder fromXContent(QueryParseContext context, String elementName) throws IOException { XContentParser parser = context.parser(); - ParseFieldMatcher parseFieldMatcher = context.parseFieldMatcher(); + ParseFieldMatcher parseFieldMatcher = context.getParseFieldMatcher(); String fieldName = null; List geoPoints = new ArrayList<>(); DistanceUnit unit = DistanceUnit.DEFAULT; diff --git a/core/src/main/java/org/elasticsearch/search/sort/ScoreSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/ScoreSortBuilder.java index 7f0f07045a8..8267429f77c 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/ScoreSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/ScoreSortBuilder.java @@ -84,7 +84,7 @@ public class ScoreSortBuilder extends SortBuilder { */ public static ScoreSortBuilder fromXContent(QueryParseContext context, String fieldName) throws IOException { XContentParser parser = context.parser(); - ParseFieldMatcher matcher = context.parseFieldMatcher(); + ParseFieldMatcher matcher = context.getParseFieldMatcher(); XContentParser.Token token; String currentName = parser.currentName(); diff --git a/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java index 2751d497519..3e0314bda1b 100644 --- a/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java @@ -231,7 +231,7 @@ public class ScriptSortBuilder extends SortBuilder { public static ScriptSortBuilder fromXContent(QueryParseContext context, String elementName) throws IOException { ScriptParameterParser scriptParameterParser = new ScriptParameterParser(); XContentParser parser = context.parser(); - ParseFieldMatcher parseField = context.parseFieldMatcher(); + ParseFieldMatcher parseField = context.getParseFieldMatcher(); Script script = null; ScriptSortType type = null; SortMode sortMode = null; diff --git a/core/src/main/java/org/elasticsearch/search/suggest/SuggestBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/SuggestBuilder.java index ff56f395a5c..b3493a9a66c 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/SuggestBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/SuggestBuilder.java @@ -140,7 +140,7 @@ public class SuggestBuilder extends ToXContentToBytes implements Writeable> extends static SuggestionBuilder fromXContent(QueryParseContext parseContext, Suggesters suggesters) throws IOException { XContentParser parser = parseContext.parser(); - ParseFieldMatcher parsefieldMatcher = parseContext.parseFieldMatcher(); + ParseFieldMatcher parsefieldMatcher = parseContext.getParseFieldMatcher(); XContentParser.Token token; String currentFieldName = null; String suggestText = null; diff --git a/core/src/main/java/org/elasticsearch/search/suggest/phrase/Laplace.java b/core/src/main/java/org/elasticsearch/search/suggest/phrase/Laplace.java index 15eb759f2ae..89b2e763540 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/phrase/Laplace.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/phrase/Laplace.java @@ -112,7 +112,7 @@ public final class Laplace extends SmoothingModel { if (token == XContentParser.Token.FIELD_NAME) { fieldName = parser.currentName(); } - if (token.isValue() && parseContext.parseFieldMatcher().match(fieldName, ALPHA_FIELD)) { + if (token.isValue() && parseContext.getParseFieldMatcher().match(fieldName, ALPHA_FIELD)) { alpha = parser.doubleValue(); } } diff --git a/core/src/main/java/org/elasticsearch/search/suggest/phrase/LinearInterpolation.java b/core/src/main/java/org/elasticsearch/search/suggest/phrase/LinearInterpolation.java index f351bebe5a8..ba25766c8e0 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/phrase/LinearInterpolation.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/phrase/LinearInterpolation.java @@ -138,7 +138,7 @@ public final class LinearInterpolation extends SmoothingModel { double trigramLambda = 0.0; double bigramLambda = 0.0; double unigramLambda = 0.0; - ParseFieldMatcher matcher = parseContext.parseFieldMatcher(); + ParseFieldMatcher matcher = parseContext.getParseFieldMatcher(); while ((token = parser.nextToken()) != Token.END_OBJECT) { if (token == XContentParser.Token.FIELD_NAME) { fieldName = parser.currentName(); diff --git a/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java index 299c57d8d26..177e2b7d518 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggestionBuilder.java @@ -493,7 +493,7 @@ public class PhraseSuggestionBuilder extends SuggestionBuilder, public static SmoothingModel fromXContent(QueryParseContext parseContext) throws IOException { XContentParser parser = parseContext.parser(); - ParseFieldMatcher parseFieldMatcher = parseContext.parseFieldMatcher(); + ParseFieldMatcher parseFieldMatcher = parseContext.getParseFieldMatcher(); XContentParser.Token token; String fieldName = null; SmoothingModel model = null; diff --git a/core/src/main/java/org/elasticsearch/search/suggest/phrase/StupidBackoff.java b/core/src/main/java/org/elasticsearch/search/suggest/phrase/StupidBackoff.java index cf1c436640b..4160fcb42d4 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/phrase/StupidBackoff.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/phrase/StupidBackoff.java @@ -115,7 +115,7 @@ public final class StupidBackoff extends SmoothingModel { if (token == XContentParser.Token.FIELD_NAME) { fieldName = parser.currentName(); } - if (token.isValue() && parseContext.parseFieldMatcher().match(fieldName, DISCOUNT_FIELD)) { + if (token.isValue() && parseContext.getParseFieldMatcher().match(fieldName, DISCOUNT_FIELD)) { discount = parser.doubleValue(); } } diff --git a/core/src/main/java/org/elasticsearch/search/suggest/term/TermSuggestionBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/term/TermSuggestionBuilder.java index 0676bbf8594..41a6e61301c 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/term/TermSuggestionBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/term/TermSuggestionBuilder.java @@ -392,7 +392,7 @@ public class TermSuggestionBuilder extends SuggestionBuilder sourceParser.parse(p, v.getSearchRequest(), c), new ParseField("source"), ValueType.OBJECT); PARSER.declareField((p, v, c) -> destParser.parse(p, v.getDestination(), c), new ParseField("dest"), ValueType.OBJECT); PARSER.declareInt(ReindexRequest::setSize, new ParseField("size")); - PARSER.declareField((p, v, c) -> v.setScript(Script.parse(p, c.queryParseContext.parseFieldMatcher())), new ParseField("script"), + PARSER.declareField((p, v, c) -> v.setScript(Script.parse(p, c.queryParseContext.getParseFieldMatcher())), new ParseField("script"), ValueType.OBJECT); PARSER.declareString(ReindexRequest::setConflicts, new ParseField("conflicts")); } @@ -185,7 +185,7 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler Date: Fri, 15 Apr 2016 09:42:29 -0400 Subject: [PATCH 015/561] fix IndexingMemoryController to use existing Settings API support to parse % or byte size, and to enforce min/max values; don't try to share string constants for settings in tests --- .../common/settings/Setting.java | 4 +- .../indices/IndexingMemoryController.java | 50 ++++++--------- .../IndexingMemoryControllerTests.java | 64 ++++++++++++++----- 3 files changed, 68 insertions(+), 50 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/settings/Setting.java b/core/src/main/java/org/elasticsearch/common/settings/Setting.java index a2ebe7a2c30..fa4dd312319 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/Setting.java +++ b/core/src/main/java/org/elasticsearch/common/settings/Setting.java @@ -523,9 +523,9 @@ public class Setting extends ToXContentToBytes { return new Setting<>(key, defaultValue, (s) -> ByteSizeValue.parseBytesSizeValue(s, key), properties); } - public static Setting byteSizeSetting(String key, ByteSizeValue value, ByteSizeValue minValue, ByteSizeValue maxValue, + public static Setting byteSizeSetting(String key, ByteSizeValue defaultValue, ByteSizeValue minValue, ByteSizeValue maxValue, Property... properties) { - return byteSizeSetting(key, (s) -> value.toString(), minValue, maxValue, properties); + return byteSizeSetting(key, (s) -> defaultValue.toString(), minValue, maxValue, properties); } public static Setting byteSizeSetting(String key, Function defaultValue, diff --git a/core/src/main/java/org/elasticsearch/indices/IndexingMemoryController.java b/core/src/main/java/org/elasticsearch/indices/IndexingMemoryController.java index 4536cf304c6..87035044297 100644 --- a/core/src/main/java/org/elasticsearch/indices/IndexingMemoryController.java +++ b/core/src/main/java/org/elasticsearch/indices/IndexingMemoryController.java @@ -52,37 +52,27 @@ import java.util.concurrent.locks.ReentrantLock; public class IndexingMemoryController extends AbstractComponent implements IndexingOperationListener, Closeable { /** How much heap (% or bytes) we will share across all actively indexing shards on this node (default: 10%). */ - public static final Setting INDEX_BUFFER_SIZE_SETTING = new Setting("indices.memory.index_buffer_size", (s) -> "10%", - (s) -> { - if (s.endsWith("%")) { - try { - Double.parseDouble(s.substring(0, s.length() - 1)); - } catch (NumberFormatException nfe) { - throw new IllegalArgumentException("unknown value for [indices.memory.index_buffer_size]: must be X% or a size value (e.g. XMB) but was: " + s); - } - } else { - try { - ByteSizeValue.parseBytesSizeValue(s, "indices.memory.index_buffer_size"); - } catch (Throwable t) { - throw new IllegalArgumentException("unknown value for [indices.memory.index_buffer_size]: must be X% or a size value (e.g. XMB) but " + t.getMessage()); - } - } - - return s; - }, - Property.NodeScope); + public static final Setting INDEX_BUFFER_SIZE_SETTING = Setting.byteSizeSetting("indices.memory.index_buffer_size", "10%", Property.NodeScope); /** Only applies when indices.memory.index_buffer_size is a %, to set a floor on the actual size in bytes (default: 48 MB). */ - public static final Setting MIN_INDEX_BUFFER_SIZE_SETTING = Setting.byteSizeSetting("indices.memory.min_index_buffer_size", new ByteSizeValue(48, ByteSizeUnit.MB), Property.NodeScope); + public static final Setting MIN_INDEX_BUFFER_SIZE_SETTING = Setting.byteSizeSetting("indices.memory.min_index_buffer_size", + new ByteSizeValue(48, ByteSizeUnit.MB), + new ByteSizeValue(0, ByteSizeUnit.BYTES), + new ByteSizeValue(Long.MAX_VALUE, ByteSizeUnit.BYTES), + Property.NodeScope); /** Only applies when indices.memory.index_buffer_size is a %, to set a ceiling on the actual size in bytes (default: not set). */ - public static final Setting MAX_INDEX_BUFFER_SIZE_SETTING = Setting.byteSizeSetting("indices.memory.max_index_buffer_size", new ByteSizeValue(-1), Property.NodeScope); + public static final Setting MAX_INDEX_BUFFER_SIZE_SETTING = Setting.byteSizeSetting("indices.memory.max_index_buffer_size", + new ByteSizeValue(-1), + new ByteSizeValue(-1), + new ByteSizeValue(Long.MAX_VALUE, ByteSizeUnit.BYTES), + Property.NodeScope); /** If we see no indexing operations after this much time for a given shard, we consider that shard inactive (default: 5 minutes). */ - public static final Setting SHARD_INACTIVE_TIME_SETTING = Setting.timeSetting("indices.memory.shard_inactive_time", TimeValue.timeValueMinutes(5), Property.NodeScope); + public static final Setting SHARD_INACTIVE_TIME_SETTING = Setting.positiveTimeSetting("indices.memory.shard_inactive_time", TimeValue.timeValueMinutes(5), Property.NodeScope); /** How frequently we check indexing memory usage (default: 5 seconds). */ - public static final Setting SHARD_MEMORY_INTERVAL_TIME_SETTING = Setting.timeSetting("indices.memory.interval", TimeValue.timeValueSeconds(5), Property.NodeScope); + public static final Setting SHARD_MEMORY_INTERVAL_TIME_SETTING = Setting.positiveTimeSetting("indices.memory.interval", TimeValue.timeValueSeconds(5), Property.NodeScope); private final ThreadPool threadPool; @@ -111,22 +101,20 @@ public class IndexingMemoryController extends AbstractComponent implements Index super(settings); this.indexShards = indexServices; - ByteSizeValue indexingBuffer; - String indexingBufferSetting = INDEX_BUFFER_SIZE_SETTING.get(settings); - if (indexingBufferSetting.endsWith("%")) { - double percent = Double.parseDouble(indexingBufferSetting.substring(0, indexingBufferSetting.length() - 1)); - indexingBuffer = new ByteSizeValue((long) (((double) jvmMemoryInBytes) * (percent / 100))); + ByteSizeValue indexingBuffer = INDEX_BUFFER_SIZE_SETTING.get(settings); + + String indexingBufferSetting = settings.get(INDEX_BUFFER_SIZE_SETTING.getKey()); + // null means we used the default (10%) + if (indexingBufferSetting == null || indexingBufferSetting.endsWith("%")) { + // We only apply the min/max when % value was used for the index buffer: ByteSizeValue minIndexingBuffer = MIN_INDEX_BUFFER_SIZE_SETTING.get(this.settings); ByteSizeValue maxIndexingBuffer = MAX_INDEX_BUFFER_SIZE_SETTING.get(this.settings); - if (indexingBuffer.bytes() < minIndexingBuffer.bytes()) { indexingBuffer = minIndexingBuffer; } if (maxIndexingBuffer.bytes() != -1 && indexingBuffer.bytes() > maxIndexingBuffer.bytes()) { indexingBuffer = maxIndexingBuffer; } - } else { - indexingBuffer = ByteSizeValue.parseBytesSizeValue(indexingBufferSetting, INDEX_BUFFER_SIZE_SETTING.getKey()); } this.indexingBuffer = indexingBuffer; diff --git a/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java b/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java index 4ffcb503a2f..9d42090ccf3 100644 --- a/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java +++ b/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java @@ -56,8 +56,6 @@ import java.util.concurrent.atomic.AtomicReference; import static java.util.Collections.emptyMap; import static java.util.Collections.emptySet; -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.test.hamcrest.ElasticsearchAssertions.assertNoFailures; import static org.hamcrest.Matchers.equalTo; @@ -76,7 +74,7 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase { public MockController(Settings settings) { super(Settings.builder() - .put(SHARD_MEMORY_INTERVAL_TIME_SETTING, "200h") // disable it + .put("indices.memory.interval", "200h") // disable it .put(settings) .build(), null, null, 100 * 1024 * 1024); // fix jvm mem size to 100mb @@ -176,12 +174,12 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase { } public void testShardAdditionAndRemoval() { - createIndex("test", Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 3).put(SETTING_NUMBER_OF_REPLICAS, 0).build()); + createIndex("test", Settings.builder().put("index.number_of_shards", 3).put("index.number_of_replicas", 0).build()); IndicesService indicesService = getInstanceFromNode(IndicesService.class); IndexService test = indicesService.indexService(resolveIndex("test")); MockController controller = new MockController(Settings.builder() - .put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING.getKey(), "4mb").build()); + .put("indices.memory.index_buffer_size", "4mb").build()); IndexShard shard0 = test.getShard(0); controller.simulateIndexing(shard0); controller.assertBuffer(shard0, 1); @@ -209,12 +207,12 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase { public void testActiveInactive() { - createIndex("test", Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 2).put(SETTING_NUMBER_OF_REPLICAS, 0).build()); + createIndex("test", Settings.builder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0).build()); IndicesService indicesService = getInstanceFromNode(IndicesService.class); IndexService test = indicesService.indexService(resolveIndex("test")); MockController controller = new MockController(Settings.builder() - .put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING.getKey(), "5mb") + .put("indices.memory.index_buffer_size", "5mb") .build()); IndexShard shard0 = test.getShard(0); @@ -248,27 +246,59 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase { public void testMinBufferSizes() { MockController controller = new MockController(Settings.builder() - .put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING.getKey(), "0.001%") - .put(IndexingMemoryController.MIN_INDEX_BUFFER_SIZE_SETTING.getKey(), "6mb").build()); + .put("indices.memory.index_buffer_size", "0.001%") + .put("indices.memory.min_index_buffer_size", "6mb").build()); assertThat(controller.indexingBufferSize(), equalTo(new ByteSizeValue(6, ByteSizeUnit.MB))); } + public void testNegativeMinIndexBufferSize() { + Exception e = expectThrows(IllegalArgumentException.class, + () -> new MockController(Settings.builder() + .put("indices.memory.min_index_buffer_size", "-6mb").build())); + assertEquals("Failed to parse value [-6mb] for setting [indices.memory.min_index_buffer_size] must be >= 0b", e.getMessage()); + + } + + public void testNegativeInterval() { + Exception e = expectThrows(IllegalArgumentException.class, + () -> new MockController(Settings.builder() + .put("indices.memory.interval", "-42s").build())); + assertEquals("Failed to parse value [-42s] for setting [indices.memory.interval] must be >= 0s", e.getMessage()); + + } + + public void testNegativeShardInactiveTime() { + Exception e = expectThrows(IllegalArgumentException.class, + () -> new MockController(Settings.builder() + .put("indices.memory.shard_inactive_time", "-42s").build())); + assertEquals("Failed to parse value [-42s] for setting [indices.memory.shard_inactive_time] must be >= 0s", e.getMessage()); + + } + + public void testNegative() { + Exception e = expectThrows(IllegalArgumentException.class, + () -> new MockController(Settings.builder() + .put("indices.memory.max_index_buffer_size", "-6mb").build())); + assertEquals("Failed to parse value [-6mb] for setting [indices.memory.max_index_buffer_size] must be >= -1b", e.getMessage()); + + } + public void testMaxBufferSizes() { MockController controller = new MockController(Settings.builder() - .put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING.getKey(), "90%") - .put(IndexingMemoryController.MAX_INDEX_BUFFER_SIZE_SETTING.getKey(), "6mb").build()); + .put("indices.memory.index_buffer_size", "90%") + .put("indices.memory.max_index_buffer_size", "6mb").build()); assertThat(controller.indexingBufferSize(), equalTo(new ByteSizeValue(6, ByteSizeUnit.MB))); } public void testThrottling() throws Exception { - createIndex("test", Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 3).put(SETTING_NUMBER_OF_REPLICAS, 0).build()); + createIndex("test", Settings.builder().put("index.number_of_shards", 3).put("index.number_of_replicas", 0).build()); IndicesService indicesService = getInstanceFromNode(IndicesService.class); IndexService test = indicesService.indexService(resolveIndex("test")); MockController controller = new MockController(Settings.builder() - .put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING.getKey(), "4mb").build()); + .put("indices.memory.index_buffer_size", "4mb").build()); IndexShard shard0 = test.getShard(0); IndexShard shard1 = test.getShard(1); IndexShard shard2 = test.getShard(2); @@ -326,8 +356,8 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase { // #10312 public void testDeletesAloneCanTriggerRefresh() throws Exception { createIndex("index", - Settings.builder().put(SETTING_NUMBER_OF_SHARDS, 1) - .put(SETTING_NUMBER_OF_REPLICAS, 0) + Settings.builder().put("index.number_of_shards", 1) + .put("index.number_of_replicas", 0) .put("index.refresh_interval", -1) .build()); ensureGreen(); @@ -347,7 +377,7 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase { assertNoFailures(r); // Make a shell of an IMC to check up on indexing buffer usage: - Settings settings = Settings.builder().put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING.getKey(), "1kb").build(); + Settings settings = Settings.builder().put("indices.memory.index_buffer_size", "1kb").build(); // TODO: would be cleaner if I could pass this 1kb setting to the single node this test created.... IndexingMemoryController imc = new IndexingMemoryController(settings, null, null) { @@ -408,7 +438,7 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase { IndexSearcherWrapper wrapper = new IndexSearcherWrapper() {}; shard.close("simon says", false); AtomicReference shardRef = new AtomicReference<>(); - Settings settings = Settings.builder().put(IndexingMemoryController.INDEX_BUFFER_SIZE_SETTING.getKey(), "50kb").build(); + Settings settings = Settings.builder().put("indices.memory.index_buffer_size", "50kb").build(); Iterable iterable = () -> (shardRef.get() == null) ? Collections.emptyList().iterator() : Collections.singleton(shardRef.get()).iterator(); AtomicInteger flushes = new AtomicInteger(); From a361f5b8105bc4896f1b71de547df8993d1c93b8 Mon Sep 17 00:00:00 2001 From: Mike McCandless Date: Fri, 15 Apr 2016 09:47:08 -0400 Subject: [PATCH 016/561] fix test method name --- .../elasticsearch/indices/IndexingMemoryControllerTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java b/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java index 9d42090ccf3..759288f3dc4 100644 --- a/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java +++ b/core/src/test/java/org/elasticsearch/indices/IndexingMemoryControllerTests.java @@ -276,7 +276,7 @@ public class IndexingMemoryControllerTests extends ESSingleNodeTestCase { } - public void testNegative() { + public void testNegativeMaxIndexBufferSize() { Exception e = expectThrows(IllegalArgumentException.class, () -> new MockController(Settings.builder() .put("indices.memory.max_index_buffer_size", "-6mb").build())); From 7f6a765a1efcfd5777f0cb1ad397b0fc3ec71c94 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 14 Apr 2016 16:02:17 -0400 Subject: [PATCH 017/561] Cut the sampler and diversified_sampler aggregations to registerAggregation and remove their PROTOTYPEs. Relates to #17085 --- .../elasticsearch/search/SearchModule.java | 9 ++- .../sampler/DiversifiedAggregatorBuilder.java | 55 ++++++++------ .../sampler/DiversifiedSamplerParser.java | 13 ---- .../sampler/SamplerAggregatorBuilder.java | 67 ++++++++++++++--- .../bucket/sampler/SamplerParser.java | 75 ------------------- 5 files changed, 93 insertions(+), 126 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerParser.java diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index c06fd014787..1318ac8ae1e 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -133,9 +133,10 @@ import org.elasticsearch.search.aggregations.bucket.range.geodistance.InternalGe import org.elasticsearch.search.aggregations.bucket.range.ipv4.IPv4RangeAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.range.ipv4.InternalIPv4Range; import org.elasticsearch.search.aggregations.bucket.range.ipv4.IpRangeParser; +import org.elasticsearch.search.aggregations.bucket.sampler.DiversifiedAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.sampler.DiversifiedSamplerParser; import org.elasticsearch.search.aggregations.bucket.sampler.InternalSampler; -import org.elasticsearch.search.aggregations.bucket.sampler.SamplerParser; +import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.sampler.UnmappedSampler; import org.elasticsearch.search.aggregations.bucket.significant.SignificantLongTerms; import org.elasticsearch.search.aggregations.bucket.significant.SignificantStringTerms; @@ -459,8 +460,10 @@ public class SearchModule extends AbstractModule { registerAggregation(FilterAggregatorBuilder::new, FilterAggregatorBuilder::parse, FilterAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(FiltersAggregatorBuilder::new, (n, c) -> FiltersAggregatorBuilder.parse(queryParserRegistry, n, c), FiltersAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerAggregatorParser(new SamplerParser()); - registerAggregatorParser(new DiversifiedSamplerParser()); + registerAggregation(SamplerAggregatorBuilder::new, SamplerAggregatorBuilder::parse, + SamplerAggregatorBuilder.AGGREGATION_NAME_FIELD); + registerAggregation(DiversifiedAggregatorBuilder::new, new DiversifiedSamplerParser(), + DiversifiedAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(TermsAggregatorBuilder::new, new TermsParser(), TermsAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregatorParser(new SignificantTermsParser(significanceHeuristicParserMapper, queryParserRegistry)); registerAggregation(RangeAggregatorBuilder::new, new RangeParser(), RangeAggregatorBuilder.AGGREGATION_NAME_FIELD); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorBuilder.java index d7e44ba8254..a8ff098ccc8 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedAggregatorBuilder.java @@ -19,14 +19,14 @@ package org.elasticsearch.search.aggregations.bucket.sampler; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.InternalAggregation.Type; import org.elasticsearch.search.aggregations.support.AggregationContext; -import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; @@ -37,10 +37,9 @@ import java.io.IOException; import java.util.Objects; public class DiversifiedAggregatorBuilder extends ValuesSourceAggregatorBuilder { - - public static final Type TYPE = new Type("diversified_sampler"); - - static final DiversifiedAggregatorBuilder PROTOTYPE = new DiversifiedAggregatorBuilder(""); + public static final String NAME = "diversified_sampler"; + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); + public static final Type TYPE = new Type(NAME); public static final int MAX_DOCS_PER_VALUE_DEFAULT = 1; @@ -52,6 +51,28 @@ public class DiversifiedAggregatorBuilder extends ValuesSourceAggregatorBuilder< super(name, TYPE, ValuesSourceType.ANY, null); } + /** + * Read from a stream. + */ + public DiversifiedAggregatorBuilder(StreamInput in) throws IOException { + super(in, TYPE, ValuesSourceType.ANY, null); + shardSize = in.readVInt(); + maxDocsPerValue = in.readVInt(); + executionHint = in.readOptionalString(); + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + out.writeVInt(shardSize); + out.writeVInt(maxDocsPerValue); + out.writeOptionalString(executionHint); + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; + } + /** * Set the max num docs to be returned from each shard. */ @@ -122,23 +143,6 @@ public class DiversifiedAggregatorBuilder extends ValuesSourceAggregatorBuilder< return builder; } - @Override - protected DiversifiedAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) throws IOException { - DiversifiedAggregatorBuilder factory = new DiversifiedAggregatorBuilder(name); - factory.shardSize = in.readVInt(); - factory.maxDocsPerValue = in.readVInt(); - factory.executionHint = in.readOptionalString(); - return factory; - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - out.writeVInt(shardSize); - out.writeVInt(maxDocsPerValue); - out.writeOptionalString(executionHint); - } - @Override protected int innerHashCode() { return Objects.hash(shardSize, maxDocsPerValue, executionHint); @@ -151,4 +155,9 @@ public class DiversifiedAggregatorBuilder extends ValuesSourceAggregatorBuilder< && Objects.equals(maxDocsPerValue, other.maxDocsPerValue) && Objects.equals(executionHint, other.executionHint); } + + @Override + public String getWriteableName() { + return NAME; + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedSamplerParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedSamplerParser.java index 79ac7ba7ed5..cb87e53f2c0 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedSamplerParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/DiversifiedSamplerParser.java @@ -22,7 +22,6 @@ package org.elasticsearch.search.aggregations.bucket.sampler; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.search.aggregations.AggregatorBuilder; import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.AnyValuesSourceParser; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSourceType; @@ -34,16 +33,10 @@ import java.util.Map; * */ public class DiversifiedSamplerParser extends AnyValuesSourceParser { - public DiversifiedSamplerParser() { super(true, false); } - @Override - public String type() { - return DiversifiedAggregatorBuilder.TYPE.name(); - } - @Override protected DiversifiedAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) { @@ -85,10 +78,4 @@ public class DiversifiedSamplerParser extends AnyValuesSourceParser { } return false; } - - @Override - public AggregatorBuilder getFactoryPrototypes() { - return DiversifiedAggregatorBuilder.PROTOTYPE; - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerAggregatorBuilder.java index d00ea80ae29..2f8a3fc29f5 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/sampler/SamplerAggregatorBuilder.java @@ -19,20 +19,24 @@ package org.elasticsearch.search.aggregations.bucket.sampler; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.aggregations.AggregatorBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregationContext; import java.io.IOException; import java.util.Objects; public class SamplerAggregatorBuilder extends AggregatorBuilder { - - static final SamplerAggregatorBuilder PROTOTYPE = new SamplerAggregatorBuilder(""); + public static final String NAME = InternalSampler.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); public static final int DEFAULT_SHARD_SAMPLE_SIZE = 100; @@ -42,6 +46,24 @@ public class SamplerAggregatorBuilder extends AggregatorBuilder Date: Fri, 15 Apr 2016 10:21:36 +0200 Subject: [PATCH 018/561] Add points to SegmentStats. #17775 This way points memory and disk usage will be reported in the stats API. Closes #16974 --- .../elasticsearch/index/engine/Engine.java | 1 + .../index/engine/SegmentsStats.java | 55 ++++++++++++------- .../indices/stats/IndicesStatsTests.java | 10 +++- .../index/engine/ShadowEngineTests.java | 6 ++ 4 files changed, 51 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/engine/Engine.java b/core/src/main/java/org/elasticsearch/index/engine/Engine.java index 7ed930ab956..5d702f44918 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/Engine.java +++ b/core/src/main/java/org/elasticsearch/index/engine/Engine.java @@ -426,6 +426,7 @@ public abstract class Engine implements Closeable { stats.addStoredFieldsMemoryInBytes(guardedRamBytesUsed(segmentReader.getFieldsReader())); stats.addTermVectorsMemoryInBytes(guardedRamBytesUsed(segmentReader.getTermVectorsReader())); stats.addNormsMemoryInBytes(guardedRamBytesUsed(segmentReader.getNormsReader())); + stats.addPointsMemoryInBytes(guardedRamBytesUsed(segmentReader.getPointsReader())); stats.addDocValuesMemoryInBytes(guardedRamBytesUsed(segmentReader.getDocValuesReader())); if (includeSegmentFileSizes) { diff --git a/core/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java b/core/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java index 10948f35d54..b4b80e32680 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java +++ b/core/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java @@ -21,7 +21,6 @@ package org.elasticsearch.index.engine; import com.carrotsearch.hppc.cursors.ObjectObjectCursor; -import org.elasticsearch.Version; import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; @@ -42,6 +41,7 @@ public class SegmentsStats implements Streamable, ToXContent { private long storedFieldsMemoryInBytes; private long termVectorsMemoryInBytes; private long normsMemoryInBytes; + private long pointsMemoryInBytes; private long docValuesMemoryInBytes; private long indexWriterMemoryInBytes; private long indexWriterMaxMemoryInBytes; @@ -67,6 +67,8 @@ public class SegmentsStats implements Streamable, ToXContent { .fPut("pay", "Payloads") .fPut("nvd", "Norms") .fPut("nvm", "Norms") + .fPut("dii", "Points") + .fPut("dim", "Points") .fPut("dvd", "DocValues") .fPut("dvm", "DocValues") .fPut("tvx", "Term Vector Index") @@ -98,6 +100,10 @@ public class SegmentsStats implements Streamable, ToXContent { this.normsMemoryInBytes += normsMemoryInBytes; } + public void addPointsMemoryInBytes(long pointsMemoryInBytes) { + this.pointsMemoryInBytes += pointsMemoryInBytes; + } + public void addDocValuesMemoryInBytes(long docValuesMemoryInBytes) { this.docValuesMemoryInBytes += docValuesMemoryInBytes; } @@ -143,6 +149,7 @@ public class SegmentsStats implements Streamable, ToXContent { addStoredFieldsMemoryInBytes(mergeStats.storedFieldsMemoryInBytes); addTermVectorsMemoryInBytes(mergeStats.termVectorsMemoryInBytes); addNormsMemoryInBytes(mergeStats.normsMemoryInBytes); + addPointsMemoryInBytes(mergeStats.pointsMemoryInBytes); addDocValuesMemoryInBytes(mergeStats.docValuesMemoryInBytes); addIndexWriterMemoryInBytes(mergeStats.indexWriterMemoryInBytes); addIndexWriterMaxMemoryInBytes(mergeStats.indexWriterMaxMemoryInBytes); @@ -213,6 +220,17 @@ public class SegmentsStats implements Streamable, ToXContent { return new ByteSizeValue(normsMemoryInBytes); } + /** + * Estimation of the points memory usage by a segment. + */ + public long getPointsMemoryInBytes() { + return this.pointsMemoryInBytes; + } + + public ByteSizeValue getPointsMemory() { + return new ByteSizeValue(pointsMemoryInBytes); + } + /** * Estimation of the doc values memory usage by a segment. */ @@ -287,6 +305,7 @@ public class SegmentsStats implements Streamable, ToXContent { builder.byteSizeField(Fields.STORED_FIELDS_MEMORY_IN_BYTES, Fields.STORED_FIELDS_MEMORY, storedFieldsMemoryInBytes); builder.byteSizeField(Fields.TERM_VECTORS_MEMORY_IN_BYTES, Fields.TERM_VECTORS_MEMORY, termVectorsMemoryInBytes); builder.byteSizeField(Fields.NORMS_MEMORY_IN_BYTES, Fields.NORMS_MEMORY, normsMemoryInBytes); + builder.byteSizeField(Fields.POINTS_MEMORY_IN_BYTES, Fields.POINTS_MEMORY, pointsMemoryInBytes); builder.byteSizeField(Fields.DOC_VALUES_MEMORY_IN_BYTES, Fields.DOC_VALUES_MEMORY, docValuesMemoryInBytes); builder.byteSizeField(Fields.INDEX_WRITER_MEMORY_IN_BYTES, Fields.INDEX_WRITER_MEMORY, indexWriterMemoryInBytes); builder.byteSizeField(Fields.INDEX_WRITER_MAX_MEMORY_IN_BYTES, Fields.INDEX_WRITER_MAX_MEMORY, indexWriterMaxMemoryInBytes); @@ -318,6 +337,8 @@ public class SegmentsStats implements Streamable, ToXContent { static final XContentBuilderString TERM_VECTORS_MEMORY_IN_BYTES = new XContentBuilderString("term_vectors_memory_in_bytes"); static final XContentBuilderString NORMS_MEMORY = new XContentBuilderString("norms_memory"); static final XContentBuilderString NORMS_MEMORY_IN_BYTES = new XContentBuilderString("norms_memory_in_bytes"); + static final XContentBuilderString POINTS_MEMORY = new XContentBuilderString("points_memory"); + static final XContentBuilderString POINTS_MEMORY_IN_BYTES = new XContentBuilderString("points_memory_in_bytes"); static final XContentBuilderString DOC_VALUES_MEMORY = new XContentBuilderString("doc_values_memory"); static final XContentBuilderString DOC_VALUES_MEMORY_IN_BYTES = new XContentBuilderString("doc_values_memory_in_bytes"); static final XContentBuilderString INDEX_WRITER_MEMORY = new XContentBuilderString("index_writer_memory"); @@ -342,24 +363,21 @@ public class SegmentsStats implements Streamable, ToXContent { storedFieldsMemoryInBytes = in.readLong(); termVectorsMemoryInBytes = in.readLong(); normsMemoryInBytes = in.readLong(); + pointsMemoryInBytes = in.readLong(); docValuesMemoryInBytes = in.readLong(); indexWriterMemoryInBytes = in.readLong(); versionMapMemoryInBytes = in.readLong(); indexWriterMaxMemoryInBytes = in.readLong(); bitsetMemoryInBytes = in.readLong(); - if (in.getVersion().onOrAfter(Version.V_5_0_0_alpha1)) { - int size = in.readVInt(); - ImmutableOpenMap.Builder map = ImmutableOpenMap.builder(size); - for (int i = 0; i < size; i++) { - String key = in.readString(); - Long value = in.readLong(); - map.put(key, value); - } - fileSizes = map.build(); - } else { - fileSizes = ImmutableOpenMap.of(); + int size = in.readVInt(); + ImmutableOpenMap.Builder map = ImmutableOpenMap.builder(size); + for (int i = 0; i < size; i++) { + String key = in.readString(); + Long value = in.readLong(); + map.put(key, value); } + fileSizes = map.build(); } @Override @@ -370,19 +388,18 @@ public class SegmentsStats implements Streamable, ToXContent { out.writeLong(storedFieldsMemoryInBytes); out.writeLong(termVectorsMemoryInBytes); out.writeLong(normsMemoryInBytes); + out.writeLong(pointsMemoryInBytes); out.writeLong(docValuesMemoryInBytes); out.writeLong(indexWriterMemoryInBytes); out.writeLong(versionMapMemoryInBytes); out.writeLong(indexWriterMaxMemoryInBytes); out.writeLong(bitsetMemoryInBytes); - if (out.getVersion().onOrAfter(Version.V_5_0_0_alpha1)) { - out.writeVInt(fileSizes.size()); - for (Iterator> it = fileSizes.iterator(); it.hasNext();) { - ObjectObjectCursor entry = it.next(); - out.writeString(entry.key); - out.writeLong(entry.value); - } + out.writeVInt(fileSizes.size()); + for (Iterator> it = fileSizes.iterator(); it.hasNext();) { + ObjectObjectCursor entry = it.next(); + out.writeString(entry.key); + out.writeLong(entry.value); } } } diff --git a/core/src/test/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsTests.java b/core/src/test/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsTests.java index 77bd7c89927..726dccee597 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsTests.java @@ -41,6 +41,7 @@ public class IndicesStatsTests extends ESSingleNodeTestCase { assertEquals(0, stats.getStoredFieldsMemoryInBytes()); assertEquals(0, stats.getTermVectorsMemoryInBytes()); assertEquals(0, stats.getNormsMemoryInBytes()); + assertEquals(0, stats.getPointsMemoryInBytes()); assertEquals(0, stats.getDocValuesMemoryInBytes()); } @@ -58,12 +59,15 @@ public class IndicesStatsTests extends ESSingleNodeTestCase { .field("type", "text") .field("term_vector", "with_positions_offsets_payloads") .endObject() + .startObject("baz") + .field("type", "long") + .endObject() .endObject() .endObject() .endObject(); assertAcked(client().admin().indices().prepareCreate("test").addMapping("doc", mapping)); ensureGreen("test"); - client().prepareIndex("test", "doc", "1").setSource("foo", "bar", "bar", "baz").get(); + client().prepareIndex("test", "doc", "1").setSource("foo", "bar", "bar", "baz", "baz", 42).get(); client().admin().indices().prepareRefresh("test").get(); IndicesStatsResponse rsp = client().admin().indices().prepareStats("test").get(); @@ -72,10 +76,11 @@ public class IndicesStatsTests extends ESSingleNodeTestCase { assertThat(stats.getStoredFieldsMemoryInBytes(), greaterThan(0L)); assertThat(stats.getTermVectorsMemoryInBytes(), greaterThan(0L)); assertThat(stats.getNormsMemoryInBytes(), greaterThan(0L)); + assertThat(stats.getPointsMemoryInBytes(), greaterThan(0L)); assertThat(stats.getDocValuesMemoryInBytes(), greaterThan(0L)); // now check multiple segments stats are merged together - client().prepareIndex("test", "doc", "2").setSource("foo", "bar", "bar", "baz").get(); + client().prepareIndex("test", "doc", "2").setSource("foo", "bar", "bar", "baz", "baz", 43).get(); client().admin().indices().prepareRefresh("test").get(); rsp = client().admin().indices().prepareStats("test").get(); @@ -84,6 +89,7 @@ public class IndicesStatsTests extends ESSingleNodeTestCase { assertThat(stats2.getStoredFieldsMemoryInBytes(), greaterThan(stats.getStoredFieldsMemoryInBytes())); assertThat(stats2.getTermVectorsMemoryInBytes(), greaterThan(stats.getTermVectorsMemoryInBytes())); assertThat(stats2.getNormsMemoryInBytes(), greaterThan(stats.getNormsMemoryInBytes())); + assertThat(stats2.getPointsMemoryInBytes(), greaterThan(stats.getPointsMemoryInBytes())); assertThat(stats2.getDocValuesMemoryInBytes(), greaterThan(stats.getDocValuesMemoryInBytes())); } diff --git a/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java b/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java index f33d26a80d6..6695fb471f6 100644 --- a/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java +++ b/core/src/test/java/org/elasticsearch/index/engine/ShadowEngineTests.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.engine; import org.apache.lucene.codecs.Codec; import org.apache.lucene.document.Field; +import org.apache.lucene.document.LongPoint; import org.apache.lucene.document.NumericDocValuesField; import org.apache.lucene.document.TextField; import org.apache.lucene.index.IndexWriterConfig; @@ -170,6 +171,7 @@ public class ShadowEngineTests extends ESTestCase { Field versionField = new NumericDocValuesField("_version", 0); document.add(uidField); document.add(versionField); + document.add(new LongPoint("point_field", 42)); // so that points report memory/disk usage return new ParsedDocument(uidField, versionField, id, type, routing, timestamp, ttl, Arrays.asList(document), source, mappingsUpdate); } @@ -300,6 +302,7 @@ public class ShadowEngineTests extends ESTestCase { assertThat(stats.getStoredFieldsMemoryInBytes(), greaterThan(0L)); assertThat(stats.getTermVectorsMemoryInBytes(), equalTo(0L)); assertThat(stats.getNormsMemoryInBytes(), greaterThan(0L)); + assertThat(stats.getPointsMemoryInBytes(), greaterThan(0L)); assertThat(stats.getDocValuesMemoryInBytes(), greaterThan(0L)); assertThat(segments.get(0).isCommitted(), equalTo(false)); assertThat(segments.get(0).isSearch(), equalTo(true)); @@ -317,6 +320,7 @@ public class ShadowEngineTests extends ESTestCase { assertThat(stats.getStoredFieldsMemoryInBytes(), equalTo(0L)); assertThat(stats.getTermVectorsMemoryInBytes(), equalTo(0L)); assertThat(stats.getNormsMemoryInBytes(), equalTo(0L)); + assertThat(stats.getPointsMemoryInBytes(), equalTo(0L)); assertThat(stats.getDocValuesMemoryInBytes(), equalTo(0L)); assertThat(segments.size(), equalTo(0)); @@ -356,6 +360,7 @@ public class ShadowEngineTests extends ESTestCase { assertThat(primaryEngine.segmentsStats(false).getStoredFieldsMemoryInBytes(), greaterThan(stats.getStoredFieldsMemoryInBytes())); assertThat(primaryEngine.segmentsStats(false).getTermVectorsMemoryInBytes(), equalTo(0L)); assertThat(primaryEngine.segmentsStats(false).getNormsMemoryInBytes(), greaterThan(stats.getNormsMemoryInBytes())); + assertThat(primaryEngine.segmentsStats(false).getPointsMemoryInBytes(), greaterThan(stats.getPointsMemoryInBytes())); assertThat(primaryEngine.segmentsStats(false).getDocValuesMemoryInBytes(), greaterThan(stats.getDocValuesMemoryInBytes())); assertThat(segments.get(0).getGeneration() < segments.get(1).getGeneration(), equalTo(true)); assertThat(segments.get(0).isCommitted(), equalTo(true)); @@ -380,6 +385,7 @@ public class ShadowEngineTests extends ESTestCase { assertThat(replicaEngine.segmentsStats(false).getStoredFieldsMemoryInBytes(), greaterThan(stats.getStoredFieldsMemoryInBytes())); assertThat(replicaEngine.segmentsStats(false).getTermVectorsMemoryInBytes(), equalTo(0L)); assertThat(replicaEngine.segmentsStats(false).getNormsMemoryInBytes(), greaterThan(stats.getNormsMemoryInBytes())); + assertThat(replicaEngine.segmentsStats(false).getPointsMemoryInBytes(), greaterThan(stats.getPointsMemoryInBytes())); assertThat(replicaEngine.segmentsStats(false).getDocValuesMemoryInBytes(), greaterThan(stats.getDocValuesMemoryInBytes())); assertThat(segments.get(0).getGeneration() < segments.get(1).getGeneration(), equalTo(true)); assertThat(segments.get(0).isCommitted(), equalTo(true)); From b5a58ece41a48f18275fffd1e3965b0319dbd05f Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 14 Apr 2016 16:25:49 -0400 Subject: [PATCH 019/561] Cut nested and reverse_nested aggregations to registerAggregation and remove their PROTOTYPES. Relates to #17085 --- .../elasticsearch/search/SearchModule.java | 9 +-- .../nested/NestedAggregatorBuilder.java | 69 ++++++++++++++---- .../bucket/nested/NestedParser.java | 72 ------------------- .../ReverseNestedAggregatorBuilder.java | 67 ++++++++++++++--- .../bucket/nested/ReverseNestedParser.java | 72 ------------------- 5 files changed, 118 insertions(+), 171 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedParser.java delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/ReverseNestedParser.java diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index 1318ac8ae1e..a597c9bf1b6 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -120,8 +120,8 @@ import org.elasticsearch.search.aggregations.bucket.missing.InternalMissing; import org.elasticsearch.search.aggregations.bucket.missing.MissingParser; import org.elasticsearch.search.aggregations.bucket.nested.InternalNested; import org.elasticsearch.search.aggregations.bucket.nested.InternalReverseNested; -import org.elasticsearch.search.aggregations.bucket.nested.NestedParser; -import org.elasticsearch.search.aggregations.bucket.nested.ReverseNestedParser; +import org.elasticsearch.search.aggregations.bucket.nested.NestedAggregatorBuilder; +import org.elasticsearch.search.aggregations.bucket.nested.ReverseNestedAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.range.InternalRange; import org.elasticsearch.search.aggregations.bucket.range.RangeAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.range.RangeParser; @@ -474,8 +474,9 @@ public class SearchModule extends AbstractModule { DateHistogramAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregatorParser(new GeoDistanceParser()); registerAggregatorParser(new GeoHashGridParser()); - registerAggregatorParser(new NestedParser()); - registerAggregatorParser(new ReverseNestedParser()); + registerAggregation(NestedAggregatorBuilder::new, NestedAggregatorBuilder::parse, NestedAggregatorBuilder.AGGREGATION_FIELD_NAME); + registerAggregation(ReverseNestedAggregatorBuilder::new, ReverseNestedAggregatorBuilder::parse, + ReverseNestedAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregatorParser(new TopHitsParser()); registerAggregatorParser(new GeoBoundsParser()); registerAggregatorParser(new GeoCentroidParser()); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregatorBuilder.java index 724eaec09ab..a0b17701ed1 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/nested/NestedAggregatorBuilder.java @@ -19,20 +19,24 @@ package org.elasticsearch.search.aggregations.bucket.nested; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.aggregations.AggregatorBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregationContext; import java.io.IOException; import java.util.Objects; public class NestedAggregatorBuilder extends AggregatorBuilder { - - static final NestedAggregatorBuilder PROTOTYPE = new NestedAggregatorBuilder("", ""); + public static final String NAME = InternalNested.TYPE.name(); + public static final ParseField AGGREGATION_FIELD_NAME = new ParseField(NAME); private final String path; @@ -51,6 +55,24 @@ public class NestedAggregatorBuilder extends AggregatorBuilder { - - static final ReverseNestedAggregatorBuilder PROTOTYPE = new ReverseNestedAggregatorBuilder(""); + public static final String NAME = InternalReverseNested.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); private String path; @@ -40,6 +44,24 @@ public class ReverseNestedAggregatorBuilder extends AggregatorBuilder Date: Tue, 29 Mar 2016 18:45:07 +0200 Subject: [PATCH 020/561] Clean up QueryParseContext and don't hold it inside QueryRewrite/ShardContext This change cleans up a few things in QueryParseContext and QueryShardContext that make it hard to reason about the state of these context objects and are thus error prone and should be simplified. Currently the parser that used in QueryParseContext can be set and reset any time from the outside, which makes reasoning about it hard. This change makes the parser a mandatory constructor argument removes ability to later set a different ParseFieldMatcher. If none is provided at construction time, the one set inside the parser is used. If a ParseFieldMatcher is specified at construction time, it is implicitely set on the parser that is beeing used. The ParseFieldMatcher is only kept inside the parser. Also currently the QueryShardContext historically holds an inner QueryParseContext (in the super class QueryRewriteContext), that is mainly used to hold the parser and parseFieldMatcher. For that reason, the parser can also be reset, which leads to the same problems as above. This change removes the QueryParseContext from QueryRewriteContext and removes the ability to reset or retrieve it from the QueryShardContext. Instead, `QueryRewriteContext#newParseContext(parser)` can be used to create new parse contexts with the given parser from a shard context when needed. --- .../percolate/TransportPercolateAction.java | 15 +- .../cluster/metadata/AliasValidator.java | 7 +- .../percolator/PercolatorFieldMapper.java | 18 +- .../index/query/QueryParseContext.java | 36 ++-- .../index/query/QueryRewriteContext.java | 18 +- .../index/query/QueryShardContext.java | 30 +--- .../index/query/TemplateQueryBuilder.java | 3 +- .../index/query/WrapperQueryBuilder.java | 3 +- .../action/search/RestMultiSearchAction.java | 23 ++- .../rest/action/search/RestSearchAction.java | 4 +- .../action/suggest/RestSuggestAction.java | 5 +- .../rest/action/support/RestActions.java | 9 +- .../elasticsearch/search/SearchService.java | 31 ++-- .../aggregations/AggregationParseElement.java | 4 +- .../filters/FiltersAggregatorBuilder.java | 10 +- .../significant/SignificantTermsParser.java | 4 +- .../index/query/AbstractQueryTestCase.java | 15 +- .../query/GeoShapeQueryBuilderTests.java | 4 +- .../query/support/InnerHitBuilderTests.java | 26 ++- .../query/support/InnerHitsBuilderTests.java | 4 +- .../AggregationCollectorTests.java | 4 +- .../aggregations/AggregatorParsingTests.java | 24 +-- .../aggregations/BaseAggregationTestCase.java | 4 +- .../BasePipelineAggregationTestCase.java | 6 +- .../geogrid/GeoHashGridParserTests.java | 24 +-- .../SignificanceHeuristicTests.java | 8 +- .../aggregations/metrics/TopHitsTests.java | 4 +- .../pipeline/moving/avg/MovAvgTests.java | 4 +- .../builder/SearchSourceBuilderTests.java | 5 +- .../highlight/HighlightBuilderTests.java | 24 +-- .../rescore/QueryRescoreBuilderTests.java | 25 ++- .../searchafter/SearchAfterBuilderTests.java | 7 +- .../search/sort/AbstractSortTestCase.java | 4 +- .../search/sort/FieldSortBuilderTests.java | 7 +- .../sort/GeoDistanceSortBuilderTests.java | 138 +++++++++++++-- .../search/sort/ScoreSortBuilderTests.java | 9 +- .../search/sort/ScriptSortBuilderTests.java | 22 +-- .../search/sort/SortBuilderTests.java | 4 +- .../search/sort/SortParserTests.java | 165 ------------------ .../AbstractSuggestionBuilderTestCase.java | 9 +- .../search/suggest/SuggestBuilderTests.java | 7 +- .../phrase/DirectCandidateGeneratorTests.java | 47 +++-- .../phrase/SmoothingModelTestCase.java | 6 +- .../messy/tests/TemplateQueryParserTests.java | 30 ++-- .../index/reindex/RestReindexAction.java | 27 +-- 45 files changed, 341 insertions(+), 542 deletions(-) delete mode 100644 core/src/test/java/org/elasticsearch/search/sort/SortParserTests.java diff --git a/core/src/main/java/org/elasticsearch/action/percolate/TransportPercolateAction.java b/core/src/main/java/org/elasticsearch/action/percolate/TransportPercolateAction.java index 4a3dfedb577..a1b4a883e48 100644 --- a/core/src/main/java/org/elasticsearch/action/percolate/TransportPercolateAction.java +++ b/core/src/main/java/org/elasticsearch/action/percolate/TransportPercolateAction.java @@ -18,6 +18,9 @@ */ package org.elasticsearch.action.percolate; +import java.io.IOException; +import java.util.Arrays; + import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.get.GetResponse; @@ -52,9 +55,6 @@ import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import java.io.IOException; -import java.util.Arrays; - public class TransportPercolateAction extends HandledTransportAction { private final Client client; @@ -196,9 +196,8 @@ public class TransportPercolateAction extends HandledTransportAction queryBuilder = queryParseContext.parseInnerQueryBuilder(); BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); boolQueryBuilder.must(queryBuilder); @@ -215,10 +214,8 @@ public class TransportPercolateAction extends HandledTransportAction queryBuilder = QueryBuilder.rewriteQuery(queryParseContext.parseInnerQueryBuilder(), queryShardContext); queryBuilder.toFilter(queryShardContext); } finally { - queryShardContext.reset(null); + queryShardContext.reset(); parser.close(); } } diff --git a/core/src/main/java/org/elasticsearch/index/percolator/PercolatorFieldMapper.java b/core/src/main/java/org/elasticsearch/index/percolator/PercolatorFieldMapper.java index 338de5c333d..7d1e3b08939 100644 --- a/core/src/main/java/org/elasticsearch/index/percolator/PercolatorFieldMapper.java +++ b/core/src/main/java/org/elasticsearch/index/percolator/PercolatorFieldMapper.java @@ -19,8 +19,6 @@ package org.elasticsearch.index.percolator; import org.apache.lucene.document.Field; -import org.apache.lucene.document.FieldType; -import org.apache.lucene.document.StoredField; import org.apache.lucene.index.DocValuesType; import org.apache.lucene.index.IndexOptions; import org.apache.lucene.search.Query; @@ -28,6 +26,7 @@ import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; +import org.elasticsearch.common.xcontent.XContentLocation; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; @@ -36,8 +35,6 @@ import org.elasticsearch.index.mapper.MapperParsingException; import org.elasticsearch.index.mapper.ParseContext; import org.elasticsearch.index.mapper.core.BinaryFieldMapper; import org.elasticsearch.index.mapper.core.KeywordFieldMapper; -import org.elasticsearch.index.mapper.core.StringFieldMapper; -import org.elasticsearch.index.query.ParsedQuery; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryShardContext; @@ -154,7 +151,8 @@ public class PercolatorFieldMapper extends FieldMapper { @Override public Mapper parse(ParseContext context) throws IOException { QueryShardContext queryShardContext = new QueryShardContext(this.queryShardContext); - QueryBuilder queryBuilder = parseQueryBuilder(queryShardContext.parseContext(), context.parser()); + XContentParser parser = context.parser(); + QueryBuilder queryBuilder = parseQueryBuilder(queryShardContext.newParseContext(parser), parser.getTokenLocation()); // Fetching of terms, shapes and indexed scripts happen during this rewrite: queryBuilder = queryBuilder.rewrite(queryShardContext); @@ -171,7 +169,7 @@ public class PercolatorFieldMapper extends FieldMapper { } public static Query parseQuery(QueryShardContext context, boolean mapUnmappedFieldsAsString, XContentParser parser) throws IOException { - return toQuery(context, mapUnmappedFieldsAsString, parseQueryBuilder(context.parseContext(), parser)); + return toQuery(context, mapUnmappedFieldsAsString, parseQueryBuilder(context.newParseContext(parser), parser.getTokenLocation())); } static Query toQuery(QueryShardContext context, boolean mapUnmappedFieldsAsString, QueryBuilder queryBuilder) throws IOException { @@ -190,7 +188,6 @@ public class PercolatorFieldMapper extends FieldMapper { // as an analyzed string. context.setAllowUnmappedFields(false); context.setMapUnmappedFieldAsString(mapUnmappedFieldsAsString); - context.parseFieldMatcher(context.getIndexSettings().getParseFieldMatcher()); try { return queryBuilder.toQuery(context); } finally { @@ -198,14 +195,11 @@ public class PercolatorFieldMapper extends FieldMapper { } } - static QueryBuilder parseQueryBuilder(QueryParseContext context, XContentParser parser) { - context.reset(parser); + static QueryBuilder parseQueryBuilder(QueryParseContext context, XContentLocation location) { try { return context.parseInnerQueryBuilder(); } catch (IOException e) { - throw new ParsingException(parser.getTokenLocation(), "Failed to parse", e); - } finally { - context.reset(null); + throw new ParsingException(location, "Failed to parse", e); } } diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java index c98ca70fc23..9201f8a52dc 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryParseContext.java @@ -19,6 +19,9 @@ package org.elasticsearch.index.query; +import java.io.IOException; +import java.util.Objects; + import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParseFieldMatcherSupplier; @@ -26,40 +29,27 @@ import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.indices.query.IndicesQueriesRegistry; -import java.io.IOException; - public class QueryParseContext implements ParseFieldMatcherSupplier { private static final ParseField CACHE = new ParseField("_cache").withAllDeprecated("Elasticsearch makes its own caching decisions"); private static final ParseField CACHE_KEY = new ParseField("_cache_key").withAllDeprecated("Filters are always used as cache keys"); - private XContentParser parser; - private ParseFieldMatcher parseFieldMatcher = ParseFieldMatcher.EMPTY; + private final XContentParser parser; + private final IndicesQueriesRegistry indicesQueriesRegistry; + private final ParseFieldMatcher parseFieldMatcher; - private IndicesQueriesRegistry indicesQueriesRegistry; - - public QueryParseContext(IndicesQueriesRegistry registry) { - this.indicesQueriesRegistry = registry; - } - - public void reset(XContentParser jp) { - this.parseFieldMatcher = ParseFieldMatcher.EMPTY; - this.parser = jp; + public QueryParseContext(IndicesQueriesRegistry registry, XContentParser parser, ParseFieldMatcher parseFieldMatcher) { + this.indicesQueriesRegistry = Objects.requireNonNull(registry, "indices queries registry cannot be null"); + this.parser = Objects.requireNonNull(parser, "parser cannot be null"); + this.parseFieldMatcher = Objects.requireNonNull(parseFieldMatcher, "parse field matcher cannot be null"); } public XContentParser parser() { return this.parser; } - public void parseFieldMatcher(ParseFieldMatcher parseFieldMatcher) { - if (parseFieldMatcher == null) { - throw new IllegalArgumentException("parseFieldMatcher must not be null"); - } - this.parseFieldMatcher = parseFieldMatcher; - } - public boolean isDeprecatedSetting(String setting) { - return parseFieldMatcher.match(setting, CACHE) || parseFieldMatcher.match(setting, CACHE_KEY); + return this.parseFieldMatcher.match(setting, CACHE) || this.parseFieldMatcher.match(setting, CACHE_KEY); } /** @@ -127,8 +117,4 @@ public class QueryParseContext implements ParseFieldMatcherSupplier { public ParseFieldMatcher getParseFieldMatcher() { return parseFieldMatcher; } - - public void parser(XContentParser innerParser) { - this.parser = innerParser; - } } diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java index 43535d689a9..ea16c7ea297 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryRewriteContext.java @@ -22,6 +22,7 @@ import org.apache.lucene.index.IndexReader; import org.elasticsearch.client.Client; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParseFieldMatcherSupplier; +import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.mapper.MapperService; import org.elasticsearch.indices.query.IndicesQueriesRegistry; @@ -35,7 +36,6 @@ public class QueryRewriteContext implements ParseFieldMatcherSupplier { protected final ScriptService scriptService; protected final IndexSettings indexSettings; protected final IndicesQueriesRegistry indicesQueriesRegistry; - protected final QueryParseContext parseContext; protected final IndexReader reader; public QueryRewriteContext(IndexSettings indexSettings, MapperService mapperService, ScriptService scriptService, @@ -44,7 +44,6 @@ public class QueryRewriteContext implements ParseFieldMatcherSupplier { this.scriptService = scriptService; this.indexSettings = indexSettings; this.indicesQueriesRegistry = indicesQueriesRegistry; - this.parseContext = new QueryParseContext(indicesQueriesRegistry); this.reader = reader; } @@ -82,21 +81,16 @@ public class QueryRewriteContext implements ParseFieldMatcherSupplier { return reader; } - public void parseFieldMatcher(ParseFieldMatcher parseFieldMatcher) { - this.parseContext.parseFieldMatcher(parseFieldMatcher); - } - @Override public ParseFieldMatcher getParseFieldMatcher() { - return parseContext.getParseFieldMatcher(); + return this.indexSettings.getParseFieldMatcher(); } /** - * Returns a new {@link QueryParseContext} to parse template or wrapped queries. + * Returns a new {@link QueryParseContext} that wraps the provided parser, using the ParseFieldMatcher settings that + * are configured in the index settings */ - public QueryParseContext newParseContext() { - QueryParseContext queryParseContext = new QueryParseContext(indicesQueriesRegistry); - queryParseContext.parseFieldMatcher(parseContext.getParseFieldMatcher()); - return queryParseContext; + public QueryParseContext newParseContext(XContentParser parser) { + return new QueryParseContext(indicesQueriesRegistry, parser, indexSettings.getParseFieldMatcher()); } } diff --git a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java index 340bf0e9715..ed87ead696a 100644 --- a/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java +++ b/core/src/main/java/org/elasticsearch/index/query/QueryShardContext.java @@ -36,7 +36,6 @@ import org.apache.lucene.search.join.BitSetProducer; import org.apache.lucene.search.similarities.Similarity; import org.elasticsearch.Version; import org.elasticsearch.common.Nullable; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; @@ -115,18 +114,12 @@ public class QueryShardContext extends QueryRewriteContext { public void reset() { allowUnmappedFields = indexSettings.isDefaultAllowUnmappedFields(); - this.parseFieldMatcher(ParseFieldMatcher.EMPTY); this.lookup = null; this.namedQueries.clear(); this.nestedScope = new NestedScope(); this.isFilter = false; } - public void reset(XContentParser jp) { - this.reset(); - this.parseContext.reset(jp); - } - public AnalysisService getAnalysisService() { return mapperService.analysisService(); } @@ -292,10 +285,6 @@ public class QueryShardContext extends QueryRewriteContext { return indexSettings.getIndexVersionCreated(); } - public QueryParseContext parseContext() { - return this.parseContext; - } - public boolean matchesIndices(String... indices) { for (String index : indices) { if (indexSettings.matchesIndexName(index)) { @@ -334,38 +323,35 @@ public class QueryShardContext extends QueryRewriteContext { */ @Nullable public ParsedQuery parseInnerFilter(XContentParser parser) throws IOException { - reset(parser); + reset(); try { - parseFieldMatcher(indexSettings.getParseFieldMatcher()); - Query filter = QueryBuilder.rewriteQuery(parseContext().parseInnerQueryBuilder(), this).toFilter(this); + Query filter = QueryBuilder.rewriteQuery(newParseContext(parser).parseInnerQueryBuilder(), this).toFilter(this); if (filter == null) { return null; } return new ParsedQuery(filter, copyNamedQueries()); } finally { - reset(null); + reset(); } } private ParsedQuery innerParse(XContentParser parser) throws IOException, QueryShardException { - reset(parser); + reset(); try { - parseFieldMatcher(indexSettings.getParseFieldMatcher()); - Query query = parseInnerQuery(); + Query query = parseInnerQuery(parser); return new ParsedQuery(query, copyNamedQueries()); } finally { - reset(null); + reset(); } } - public Query parseInnerQuery() throws IOException { - return toQuery(this.parseContext().parseInnerQueryBuilder(), this); + public Query parseInnerQuery(XContentParser parser) throws IOException { + return toQuery(this.newParseContext(parser).parseInnerQueryBuilder(), this); } public ParsedQuery toQuery(QueryBuilder queryBuilder) { reset(); - parseFieldMatcher(indexSettings.getParseFieldMatcher()); try { Query query = toQuery(queryBuilder, this); return new ParsedQuery(query, copyNamedQueries()); diff --git a/core/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java index 109ba4ee30a..e51a18b6adc 100644 --- a/core/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/TemplateQueryBuilder.java @@ -177,9 +177,8 @@ public class TemplateQueryBuilder extends AbstractQueryBuilder queryBuilder = queryParseContext.parseInnerQueryBuilder(); if (boost() != DEFAULT_BOOST || queryName() != null) { final BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder(); diff --git a/core/src/main/java/org/elasticsearch/index/query/WrapperQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/WrapperQueryBuilder.java index 0d330e8a36e..4af7081f308 100644 --- a/core/src/main/java/org/elasticsearch/index/query/WrapperQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/WrapperQueryBuilder.java @@ -162,8 +162,7 @@ public class WrapperQueryBuilder extends AbstractQueryBuilder doRewrite(QueryRewriteContext context) throws IOException { try (XContentParser qSourceParser = XContentFactory.xContent(source).createParser(source)) { - QueryParseContext parseContext = context.newParseContext(); - parseContext.reset(qSourceParser); + QueryParseContext parseContext = context.newParseContext(qSourceParser); final QueryBuilder queryBuilder = parseContext.parseInnerQueryBuilder(); if (boost() != DEFAULT_BOOST || queryName() != null) { diff --git a/core/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java b/core/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java index 762f2ce31a9..879a1e750b6 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java @@ -19,6 +19,14 @@ package org.elasticsearch.rest.action.search; +import static org.elasticsearch.common.xcontent.support.XContentMapValues.lenientNodeBooleanValue; +import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeStringArrayValue; +import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeStringValue; +import static org.elasticsearch.rest.RestRequest.Method.GET; +import static org.elasticsearch.rest.RestRequest.Method.POST; + +import java.util.Map; + import org.elasticsearch.action.search.MultiSearchRequest; import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.support.IndicesOptions; @@ -46,14 +54,6 @@ import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.search.suggest.Suggesters; -import java.util.Map; - -import static org.elasticsearch.common.xcontent.support.XContentMapValues.lenientNodeBooleanValue; -import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeStringArrayValue; -import static org.elasticsearch.common.xcontent.support.XContentMapValues.nodeStringValue; -import static org.elasticsearch.rest.RestRequest.Method.GET; -import static org.elasticsearch.rest.RestRequest.Method.POST; - /** */ public class RestMultiSearchAction extends BaseRestHandler { @@ -120,7 +120,6 @@ public class RestMultiSearchAction extends BaseRestHandler { int from = 0; int length = data.length(); byte marker = xContent.streamSeparator(); - final QueryParseContext queryParseContext = new QueryParseContext(indicesQueriesRegistry); while (true) { int nextMarker = findNextMarker(marker, from, data, length); if (nextMarker == -1) { @@ -188,14 +187,14 @@ public class RestMultiSearchAction extends BaseRestHandler { final BytesReference slice = data.slice(from, nextMarker - from); if (isTemplateRequest) { try (XContentParser parser = XContentFactory.xContent(slice).createParser(slice)) { - queryParseContext.reset(parser); - queryParseContext.parseFieldMatcher(parseFieldMatcher); + final QueryParseContext queryParseContext = new QueryParseContext(indicesQueriesRegistry, parser, parseFieldMatcher); Template template = TemplateQueryBuilder.parse(parser, queryParseContext.getParseFieldMatcher(), "params", "template"); searchRequest.template(template); } } else { try (XContentParser requestParser = XContentFactory.xContent(slice).createParser(slice)) { - queryParseContext.reset(requestParser); + final QueryParseContext queryParseContext = new QueryParseContext(indicesQueriesRegistry, requestParser, + parseFieldMatcher); searchRequest.source(SearchSourceBuilder.fromXContent(queryParseContext, aggParsers, suggesters)); } } 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 481231770e5..5a65c8df116 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 @@ -122,10 +122,8 @@ public class RestSearchAction extends BaseRestHandler { } } if (restContent != null) { - QueryParseContext context = new QueryParseContext(indicesQueriesRegistry); try (XContentParser parser = XContentFactory.xContent(restContent).createParser(restContent)) { - context.reset(parser); - context.parseFieldMatcher(parseFieldMatcher); + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, parseFieldMatcher); if (isTemplateRequest) { Template template = TemplateQueryBuilder.parse(parser, context.getParseFieldMatcher(), "params", "template"); searchRequest.template(template); diff --git a/core/src/main/java/org/elasticsearch/rest/action/suggest/RestSuggestAction.java b/core/src/main/java/org/elasticsearch/rest/action/suggest/RestSuggestAction.java index 1bbc662929c..c5c6174b02b 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/suggest/RestSuggestAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/suggest/RestSuggestAction.java @@ -27,7 +27,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; @@ -80,9 +79,7 @@ public class RestSuggestAction extends BaseRestHandler { if (RestActions.hasBodyContent(request)) { final BytesReference sourceBytes = RestActions.getRestContent(request); try (XContentParser parser = XContentFactory.xContent(sourceBytes).createParser(sourceBytes)) { - final QueryParseContext context = new QueryParseContext(queryRegistry); - context.reset(parser); - context.parseFieldMatcher(parseFieldMatcher); + final QueryParseContext context = new QueryParseContext(queryRegistry, parser, parseFieldMatcher); searchRequest.source().suggest(SuggestBuilder.fromXContent(context, suggesters)); } } else { diff --git a/core/src/main/java/org/elasticsearch/rest/action/support/RestActions.java b/core/src/main/java/org/elasticsearch/rest/action/support/RestActions.java index 55063664343..004f67a9dba 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/support/RestActions.java +++ b/core/src/main/java/org/elasticsearch/rest/action/support/RestActions.java @@ -40,9 +40,6 @@ import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.index.query.QueryStringQueryBuilder; import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.rest.RestRequest; -import org.elasticsearch.search.aggregations.AggregatorParsers; -import org.elasticsearch.search.builder.SearchSourceBuilder; -import org.elasticsearch.search.suggest.Suggesters; import java.io.IOException; @@ -135,15 +132,11 @@ public class RestActions { } public static QueryBuilder getQueryContent(BytesReference source, IndicesQueriesRegistry indicesQueriesRegistry, ParseFieldMatcher parseFieldMatcher) { - QueryParseContext context = new QueryParseContext(indicesQueriesRegistry); try (XContentParser requestParser = XContentFactory.xContent(source).createParser(source)) { - context.reset(requestParser); - context.parseFieldMatcher(parseFieldMatcher); + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, requestParser, parseFieldMatcher); return context.parseTopLevelQueryBuilder(); } catch (IOException e) { throw new ElasticsearchException("failed to parse source", e); - } finally { - context.reset(null); } } diff --git a/core/src/main/java/org/elasticsearch/search/SearchService.java b/core/src/main/java/org/elasticsearch/search/SearchService.java index d1c724eaf36..7f2cd4c4c1b 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchService.java +++ b/core/src/main/java/org/elasticsearch/search/SearchService.java @@ -19,7 +19,18 @@ package org.elasticsearch.search; -import com.carrotsearch.hppc.ObjectFloatHashMap; +import static java.util.Collections.unmodifiableMap; +import static org.elasticsearch.common.unit.TimeValue.timeValueMillis; +import static org.elasticsearch.common.unit.TimeValue.timeValueMinutes; + +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.atomic.AtomicLong; import org.apache.lucene.search.FieldDoc; import org.apache.lucene.search.Sort; @@ -98,18 +109,7 @@ import org.elasticsearch.search.sort.SortBuilder; import org.elasticsearch.search.suggest.Suggesters; import org.elasticsearch.threadpool.ThreadPool; -import java.io.IOException; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.atomic.AtomicLong; - -import static java.util.Collections.unmodifiableMap; -import static org.elasticsearch.common.unit.TimeValue.timeValueMillis; -import static org.elasticsearch.common.unit.TimeValue.timeValueMinutes; +import com.carrotsearch.hppc.ObjectFloatHashMap; /** * @@ -569,9 +569,8 @@ public class SearchService extends AbstractLifecycleComponent imp ExecutableScript executable = this.scriptService.executable(request.template(), ScriptContext.Standard.SEARCH, Collections.emptyMap()); BytesReference run = (BytesReference) executable.run(); try (XContentParser parser = XContentFactory.xContent(run).createParser(run)) { - QueryParseContext queryParseContext = new QueryParseContext(indicesService.getIndicesQueryRegistry()); - queryParseContext.reset(parser); - queryParseContext.parseFieldMatcher(parseFieldMatcher); + QueryParseContext queryParseContext = new QueryParseContext(indicesService.getIndicesQueryRegistry(), parser, + parseFieldMatcher); parseSource(context, SearchSourceBuilder.fromXContent(queryParseContext, aggParsers, suggesters)); } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/AggregationParseElement.java b/core/src/main/java/org/elasticsearch/search/aggregations/AggregationParseElement.java index 8f769feb241..2c94fc45ffc 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/AggregationParseElement.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/AggregationParseElement.java @@ -62,9 +62,7 @@ public class AggregationParseElement implements SearchParseElement { @Override public void parse(XContentParser parser, SearchContext context) throws Exception { - QueryParseContext parseContext = new QueryParseContext(queriesRegistry); - parseContext.reset(parser); - parseContext.parseFieldMatcher(context.parseFieldMatcher()); + QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, context.parseFieldMatcher()); AggregatorFactories.Builder builders = aggregatorParsers.parseAggregators(parseContext); AggregationContext aggContext = new AggregationContext(context); AggregatorFactories factories = builders.build(aggContext, null); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregatorBuilder.java index 5387de2bbe4..bbd017e2caf 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/filters/FiltersAggregatorBuilder.java @@ -241,9 +241,8 @@ public class FiltersAggregatorBuilder extends AggregatorBuilder filter = queryParseContext.parseInnerQueryBuilder(); keyedFilters.add(new FiltersAggregator.KeyedFilter(key, filter == null ? matchAllQuery() : filter)); } @@ -256,9 +255,8 @@ public class FiltersAggregatorBuilder extends AggregatorBuilder(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - QueryParseContext queryParseContext = new QueryParseContext(queriesRegistry); - queryParseContext.reset(parser); - queryParseContext.parseFieldMatcher(context.getParseFieldMatcher()); + QueryParseContext queryParseContext = new QueryParseContext(queriesRegistry, parser, + context.getParseFieldMatcher()); QueryBuilder filter = queryParseContext.parseInnerQueryBuilder(); nonKeyedFilters.add(filter == null ? QueryBuilders.matchAllQuery() : filter); } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsParser.java index 6f761ab752a..08d3f57e7fc 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsParser.java @@ -92,9 +92,7 @@ public class SignificantTermsParser extends AbstractTermsParser { otherOptions.put(SignificantTermsAggregatorBuilder.HEURISTIC, significanceHeuristic); return true; } else if (parseFieldMatcher.match(currentFieldName, SignificantTermsAggregatorBuilder.BACKGROUND_FILTER)) { - QueryParseContext queryParseContext = new QueryParseContext(queriesRegistry); - queryParseContext.reset(parser); - queryParseContext.parseFieldMatcher(parseFieldMatcher); + QueryParseContext queryParseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher); QueryBuilder filter = queryParseContext.parseInnerQueryBuilder(); otherOptions.put(SignificantTermsAggregatorBuilder.BACKGROUND_FILTER, filter); return true; diff --git a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java index aa6aa51982f..0f373d3664d 100644 --- a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java @@ -524,9 +524,7 @@ public abstract class AbstractQueryTestCase> } private QueryBuilder parseQuery(XContentParser parser, ParseFieldMatcher matcher) throws IOException { - QueryParseContext context = createParseContext(); - context.reset(parser); - context.parseFieldMatcher(matcher); + QueryParseContext context = createParseContext(parser, matcher); QueryBuilder parseInnerQueryBuilder = context.parseInnerQueryBuilder(); assertNull(parser.nextToken()); return parseInnerQueryBuilder; @@ -728,19 +726,14 @@ public abstract class AbstractQueryTestCase> * @return a new {@link QueryShardContext} based on the base test index and queryParserService */ protected static QueryShardContext createShardContext() { - QueryShardContext queryCreationContext = new QueryShardContext(queryShardContext); - queryCreationContext.reset(); - queryCreationContext.parseFieldMatcher(ParseFieldMatcher.STRICT); - return queryCreationContext; + return new QueryShardContext(queryShardContext); } /** * @return a new {@link QueryParseContext} based on the base test index and queryParserService */ - protected static QueryParseContext createParseContext() { - QueryParseContext queryParseContext = new QueryParseContext(indicesQueriesRegistry); - queryParseContext.reset(null); - queryParseContext.parseFieldMatcher(ParseFieldMatcher.STRICT); + protected static QueryParseContext createParseContext(XContentParser parser, ParseFieldMatcher matcher) { + QueryParseContext queryParseContext = new QueryParseContext(indicesQueriesRegistry, parser, matcher); return queryParseContext; } diff --git a/core/src/test/java/org/elasticsearch/index/query/GeoShapeQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/GeoShapeQueryBuilderTests.java index b4e0e0f18c2..b335cfabb6c 100644 --- a/core/src/test/java/org/elasticsearch/index/query/GeoShapeQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/GeoShapeQueryBuilderTests.java @@ -256,12 +256,12 @@ public class GeoShapeQueryBuilderTests extends AbstractQueryTestCase rewrite = sqb.rewrite(queryShardContext()); + QueryBuilder rewrite = sqb.rewrite(createShardContext()); GeoShapeQueryBuilder geoShapeQueryBuilder = new GeoShapeQueryBuilder(GEO_SHAPE_FIELD_NAME, indexedShapeToReturn); geoShapeQueryBuilder.strategy(sqb.strategy()); geoShapeQueryBuilder.relation(sqb.relation()); diff --git a/core/src/test/java/org/elasticsearch/index/query/support/InnerHitBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/support/InnerHitBuilderTests.java index d3d9c5f7cde..e85baee2324 100644 --- a/core/src/test/java/org/elasticsearch/index/query/support/InnerHitBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/support/InnerHitBuilderTests.java @@ -18,6 +18,17 @@ */ package org.elasticsearch.index.query.support; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.not; +import static org.hamcrest.Matchers.sameInstance; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Supplier; + import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; @@ -46,17 +57,6 @@ import org.elasticsearch.test.ESTestCase; import org.junit.AfterClass; import org.junit.BeforeClass; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Supplier; - -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.sameInstance; - public class InnerHitBuilderTests extends ESTestCase { private static final int NUMBER_OF_TESTBUILDERS = 20; @@ -86,8 +86,6 @@ public class InnerHitBuilderTests extends ESTestCase { } public void testFromAndToXContent() throws Exception { - QueryParseContext context = new QueryParseContext(indicesQueriesRegistry); - context.parseFieldMatcher(new ParseFieldMatcher(Settings.EMPTY)); for (int runs = 0; runs < NUMBER_OF_TESTBUILDERS; runs++) { InnerHitBuilder innerHit = randomInnerHits(); XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); @@ -97,7 +95,7 @@ public class InnerHitBuilderTests extends ESTestCase { innerHit.toXContent(builder, ToXContent.EMPTY_PARAMS); XContentParser parser = XContentHelper.createParser(builder.bytes()); - context.reset(parser); + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY); InnerHitBuilder secondInnerHits = InnerHitBuilder.fromXContent(context); assertThat(innerHit, not(sameInstance(secondInnerHits))); assertThat(innerHit, equalTo(secondInnerHits)); diff --git a/core/src/test/java/org/elasticsearch/index/query/support/InnerHitsBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/support/InnerHitsBuilderTests.java index 533416d9184..c095573b5a8 100644 --- a/core/src/test/java/org/elasticsearch/index/query/support/InnerHitsBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/support/InnerHitsBuilderTests.java @@ -72,8 +72,6 @@ public class InnerHitsBuilderTests extends ESTestCase { } public void testFromAndToXContent() throws Exception { - QueryParseContext context = new QueryParseContext(indicesQueriesRegistry); - context.parseFieldMatcher(new ParseFieldMatcher(Settings.EMPTY)); for (int runs = 0; runs < NUMBER_OF_TESTBUILDERS; runs++) { InnerHitsBuilder innerHits = randomInnerHits(); XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); @@ -83,7 +81,7 @@ public class InnerHitsBuilderTests extends ESTestCase { innerHits.toXContent(builder, ToXContent.EMPTY_PARAMS); XContentParser parser = XContentHelper.createParser(builder.bytes()); - context.reset(parser); + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY); parser.nextToken(); InnerHitsBuilder secondInnerHits = InnerHitsBuilder.fromXContent(context); assertThat(innerHits, not(sameInstance(secondInnerHits))); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/AggregationCollectorTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/AggregationCollectorTests.java index a1a6bc830e2..f2b16c3e3ee 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/AggregationCollectorTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/AggregationCollectorTests.java @@ -63,9 +63,7 @@ public class AggregationCollectorTests extends ESSingleNodeTestCase { AggregatorParsers parser = getInstanceFromNode(AggregatorParsers.class); IndicesQueriesRegistry queriesRegistry = getInstanceFromNode(IndicesQueriesRegistry.class); XContentParser aggParser = JsonXContent.jsonXContent.createParser(agg); - QueryParseContext parseContext = new QueryParseContext(queriesRegistry); - parseContext.reset(aggParser); - parseContext.parseFieldMatcher(ParseFieldMatcher.STRICT); + QueryParseContext parseContext = new QueryParseContext(queriesRegistry, aggParser, ParseFieldMatcher.STRICT); aggParser.nextToken(); SearchContext searchContext = createSearchContext(index); AggregationContext aggContext = new AggregationContext(searchContext); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java b/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java index 12cfd10c29b..a7b8ed064bc 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/AggregatorParsingTests.java @@ -210,9 +210,7 @@ public class AggregatorParsingTests extends ESTestCase { .endObject().string(); try { XContentParser parser = XContentFactory.xContent(source).createParser(source); - QueryParseContext parseContext = new QueryParseContext(queriesRegistry); - parseContext.reset(parser); - parseContext.parseFieldMatcher(parseFieldMatcher); + QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher); assertSame(XContentParser.Token.START_OBJECT, parser.nextToken()); aggParsers.parseAggregators(parseContext); fail(); @@ -246,9 +244,7 @@ public class AggregatorParsingTests extends ESTestCase { .endObject().string(); try { XContentParser parser = XContentFactory.xContent(source).createParser(source); - QueryParseContext parseContext = new QueryParseContext(queriesRegistry); - parseContext.reset(parser); - parseContext.parseFieldMatcher(parseFieldMatcher); + QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher); assertSame(XContentParser.Token.START_OBJECT, parser.nextToken()); aggParsers.parseAggregators(parseContext); fail(); @@ -286,9 +282,7 @@ public class AggregatorParsingTests extends ESTestCase { .endObject().string(); try { XContentParser parser = XContentFactory.xContent(source).createParser(source); - QueryParseContext parseContext = new QueryParseContext(queriesRegistry); - parseContext.reset(parser); - parseContext.parseFieldMatcher(parseFieldMatcher); + QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher); assertSame(XContentParser.Token.START_OBJECT, parser.nextToken()); aggParsers.parseAggregators(parseContext); fail(); @@ -314,9 +308,7 @@ public class AggregatorParsingTests extends ESTestCase { .endObject().string(); try { XContentParser parser = XContentFactory.xContent(source).createParser(source); - QueryParseContext parseContext = new QueryParseContext(queriesRegistry); - parseContext.reset(parser); - parseContext.parseFieldMatcher(parseFieldMatcher); + QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher); assertSame(XContentParser.Token.START_OBJECT, parser.nextToken()); aggParsers.parseAggregators(parseContext); fail(); @@ -344,9 +336,7 @@ public class AggregatorParsingTests extends ESTestCase { .endObject().string(); try { XContentParser parser = XContentFactory.xContent(source).createParser(source); - QueryParseContext parseContext = new QueryParseContext(queriesRegistry); - parseContext.reset(parser); - parseContext.parseFieldMatcher(parseFieldMatcher); + QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher); assertSame(XContentParser.Token.START_OBJECT, parser.nextToken()); aggParsers.parseAggregators(parseContext); fail(); @@ -374,9 +364,7 @@ public class AggregatorParsingTests extends ESTestCase { .endObject().string(); try { XContentParser parser = XContentFactory.xContent(source).createParser(source); - QueryParseContext parseContext = new QueryParseContext(queriesRegistry); - parseContext.reset(parser); - parseContext.parseFieldMatcher(parseFieldMatcher); + QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher); assertSame(XContentParser.Token.START_OBJECT, parser.nextToken()); aggParsers.parseAggregators(parseContext); fail(); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java index 3833d59ef34..5e5dc92393a 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java @@ -225,9 +225,7 @@ public abstract class BaseAggregationTestCase> factoriesBuilder.toXContent(builder, ToXContent.EMPTY_PARAMS); XContentBuilder shuffled = shuffleXContent(builder, Collections.emptySet()); XContentParser parser = XContentFactory.xContent(shuffled.bytes()).createParser(shuffled.bytes()); - QueryParseContext parseContext = new QueryParseContext(queriesRegistry); - parseContext.reset(parser); - parseContext.parseFieldMatcher(parseFieldMatcher); + QueryParseContext parseContext = new QueryParseContext(queriesRegistry, parser, parseFieldMatcher); assertSame(XContentParser.Token.START_OBJECT, parser.nextToken()); assertSame(XContentParser.Token.FIELD_NAME, parser.nextToken()); assertEquals(testAgg.name, parser.currentName()); diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java index 4c9311bb110..29db7aee5e9 100644 --- a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java @@ -227,9 +227,9 @@ public abstract class BasePipelineAggregationTestCase T expectParseThrows(Class exceptionClass, String highlightElement) throws IOException { + private static T expectParseThrows(Class exceptionClass, String highlightElement) throws IOException { XContentParser parser = XContentFactory.xContent(highlightElement).createParser(highlightElement); - QueryParseContext context = new QueryParseContext(indicesQueriesRegistry); - context.reset(parser); + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT); return expectThrows(exceptionClass, () -> HighlightBuilder.fromXContent(context)); } @@ -401,14 +398,13 @@ public class HighlightBuilderTests extends ESTestCase { * adds a simple json test for this. */ public void testParsingTagsSchema() throws IOException { - QueryParseContext context = new QueryParseContext(indicesQueriesRegistry); - context.parseFieldMatcher(new ParseFieldMatcher(Settings.EMPTY)); + String highlightElement = "{\n" + " \"tags_schema\" : \"styled\"\n" + "}\n"; XContentParser parser = XContentFactory.xContent(highlightElement).createParser(highlightElement); - context.reset(parser); + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY); HighlightBuilder highlightBuilder = HighlightBuilder.fromXContent(context); assertArrayEquals("setting tags_schema 'styled' should alter pre_tags", HighlightBuilder.DEFAULT_STYLED_PRE_TAG, highlightBuilder.preTags()); @@ -420,7 +416,7 @@ public class HighlightBuilderTests extends ESTestCase { "}\n"; parser = XContentFactory.xContent(highlightElement).createParser(highlightElement); - context.reset(parser); + context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY); highlightBuilder = HighlightBuilder.fromXContent(context); assertArrayEquals("setting tags_schema 'default' should alter pre_tags", HighlightBuilder.DEFAULT_PRE_TAGS, highlightBuilder.preTags()); @@ -438,26 +434,24 @@ public class HighlightBuilderTests extends ESTestCase { * test parsing empty highlight or empty fields blocks */ public void testParsingEmptyStructure() throws IOException { - QueryParseContext context = new QueryParseContext(indicesQueriesRegistry); - context.parseFieldMatcher(new ParseFieldMatcher(Settings.EMPTY)); String highlightElement = "{ }"; XContentParser parser = XContentFactory.xContent(highlightElement).createParser(highlightElement); - context.reset(parser); + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY); HighlightBuilder highlightBuilder = HighlightBuilder.fromXContent(context); assertEquals("expected plain HighlightBuilder", new HighlightBuilder(), highlightBuilder); highlightElement = "{ \"fields\" : { } }"; parser = XContentFactory.xContent(highlightElement).createParser(highlightElement); - context.reset(parser); + context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY); highlightBuilder = HighlightBuilder.fromXContent(context); assertEquals("defining no field should return plain HighlightBuilder", new HighlightBuilder(), highlightBuilder); highlightElement = "{ \"fields\" : { \"foo\" : { } } }"; parser = XContentFactory.xContent(highlightElement).createParser(highlightElement); - context.reset(parser); + context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.EMPTY); highlightBuilder = HighlightBuilder.fromXContent(context); assertEquals("expected HighlightBuilder with field", new HighlightBuilder().field(new Field("foo")), highlightBuilder); } diff --git a/core/src/test/java/org/elasticsearch/search/rescore/QueryRescoreBuilderTests.java b/core/src/test/java/org/elasticsearch/search/rescore/QueryRescoreBuilderTests.java index 102b4850bd6..1b221e3199d 100644 --- a/core/src/test/java/org/elasticsearch/search/rescore/QueryRescoreBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/rescore/QueryRescoreBuilderTests.java @@ -130,8 +130,6 @@ public class QueryRescoreBuilderTests extends ESTestCase { * creates random rescorer, renders it to xContent and back to new instance that should be equal to original */ public void testFromXContent() throws IOException { - QueryParseContext context = new QueryParseContext(indicesQueriesRegistry); - context.parseFieldMatcher(new ParseFieldMatcher(Settings.EMPTY)); for (int runs = 0; runs < NUMBER_OF_TESTBUILDERS; runs++) { RescoreBuilder rescoreBuilder = randomRescoreBuilder(); XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); @@ -143,7 +141,7 @@ public class QueryRescoreBuilderTests extends ESTestCase { XContentParser parser = XContentHelper.createParser(shuffled.bytes()); - context.reset(parser); + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT); parser.nextToken(); RescoreBuilder secondRescoreBuilder = RescoreBuilder.parseFromXContent(context); assertNotSame(rescoreBuilder, secondRescoreBuilder); @@ -188,14 +186,12 @@ public class QueryRescoreBuilderTests extends ESTestCase { * test parsing exceptions for incorrect rescorer syntax */ public void testUnknownFieldsExpection() throws IOException { - QueryParseContext context = new QueryParseContext(indicesQueriesRegistry); - context.parseFieldMatcher(new ParseFieldMatcher(Settings.EMPTY)); String rescoreElement = "{\n" + " \"window_size\" : 20,\n" + " \"bad_rescorer_name\" : { }\n" + "}\n"; - prepareContext(context, rescoreElement); + QueryParseContext context = createContext(rescoreElement); try { RescoreBuilder.parseFromXContent(context); fail("expected a parsing exception"); @@ -206,7 +202,7 @@ public class QueryRescoreBuilderTests extends ESTestCase { rescoreElement = "{\n" + " \"bad_fieldName\" : 20\n" + "}\n"; - prepareContext(context, rescoreElement); + context = createContext(rescoreElement); try { RescoreBuilder.parseFromXContent(context); fail("expected a parsing exception"); @@ -218,7 +214,7 @@ public class QueryRescoreBuilderTests extends ESTestCase { " \"window_size\" : 20,\n" + " \"query\" : [ ]\n" + "}\n"; - prepareContext(context, rescoreElement); + context = createContext(rescoreElement); try { RescoreBuilder.parseFromXContent(context); fail("expected a parsing exception"); @@ -227,7 +223,7 @@ public class QueryRescoreBuilderTests extends ESTestCase { } rescoreElement = "{ }"; - prepareContext(context, rescoreElement); + context = createContext(rescoreElement); try { RescoreBuilder.parseFromXContent(context); fail("expected a parsing exception"); @@ -239,7 +235,7 @@ public class QueryRescoreBuilderTests extends ESTestCase { " \"window_size\" : 20,\n" + " \"query\" : { \"bad_fieldname\" : 1.0 } \n" + "}\n"; - prepareContext(context, rescoreElement); + context = createContext(rescoreElement); try { RescoreBuilder.parseFromXContent(context); fail("expected a parsing exception"); @@ -251,7 +247,7 @@ public class QueryRescoreBuilderTests extends ESTestCase { " \"window_size\" : 20,\n" + " \"query\" : { \"rescore_query\" : { \"unknown_queryname\" : { } } } \n" + "}\n"; - prepareContext(context, rescoreElement); + context = createContext(rescoreElement); try { RescoreBuilder.parseFromXContent(context); fail("expected a parsing exception"); @@ -263,18 +259,19 @@ public class QueryRescoreBuilderTests extends ESTestCase { " \"window_size\" : 20,\n" + " \"query\" : { \"rescore_query\" : { \"match_all\" : { } } } \n" + "}\n"; - prepareContext(context, rescoreElement); + context = createContext(rescoreElement); RescoreBuilder.parseFromXContent(context); } /** * create a new parser from the rescorer string representation and reset context with it */ - private static void prepareContext(QueryParseContext context, String rescoreElement) throws IOException { + private static QueryParseContext createContext(String rescoreElement) throws IOException { XContentParser parser = XContentFactory.xContent(rescoreElement).createParser(rescoreElement); - context.reset(parser); + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT); // move to first token, this is where the internal fromXContent assertTrue(parser.nextToken() == XContentParser.Token.START_OBJECT); + return context; } private static RescoreBuilder mutate(RescoreBuilder original) throws IOException { diff --git a/core/src/test/java/org/elasticsearch/search/searchafter/SearchAfterBuilderTests.java b/core/src/test/java/org/elasticsearch/search/searchafter/SearchAfterBuilderTests.java index d15c88dc825..14bf8eac7e6 100644 --- a/core/src/test/java/org/elasticsearch/search/searchafter/SearchAfterBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/searchafter/SearchAfterBuilderTests.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.text.Text; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; @@ -212,8 +211,6 @@ public class SearchAfterBuilderTests extends ESTestCase { } public void testFromXContent() throws Exception { - QueryParseContext context = new QueryParseContext(indicesQueriesRegistry); - context.parseFieldMatcher(new ParseFieldMatcher(Settings.EMPTY)); for (int runs = 0; runs < 20; runs++) { SearchAfterBuilder searchAfterBuilder = randomJsonSearchFromBuilder(); XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); @@ -224,7 +221,7 @@ public class SearchAfterBuilderTests extends ESTestCase { searchAfterBuilder.innerToXContent(builder); builder.endObject(); XContentParser parser = XContentHelper.createParser(builder.bytes()); - context.reset(parser); + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, ParseFieldMatcher.STRICT); parser.nextToken(); parser.nextToken(); parser.nextToken(); @@ -234,7 +231,7 @@ public class SearchAfterBuilderTests extends ESTestCase { assertEquals(searchAfterBuilder.hashCode(), secondSearchAfterBuilder.hashCode()); } } - + public void testWithNullArray() throws Exception { SearchAfterBuilder builder = new SearchAfterBuilder(); try { diff --git a/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java b/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java index d25abd12f35..fecc048f291 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/sort/AbstractSortTestCase.java @@ -21,6 +21,7 @@ package org.elasticsearch.search.sort; import org.apache.lucene.search.SortField; import org.apache.lucene.util.Accountable; +import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; @@ -141,8 +142,7 @@ public abstract class AbstractSortTestCase> extends EST String elementName = itemParser.currentName(); itemParser.nextToken(); - QueryParseContext context = new QueryParseContext(indicesQueriesRegistry); - context.reset(itemParser); + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT); T parsedItem = fromXContent(context, elementName); assertNotSame(testItem, parsedItem); assertEquals(testItem, parsedItem); diff --git a/core/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java b/core/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java index 1ea2180f5e0..5ca9aef658c 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/sort/FieldSortBuilderTests.java @@ -22,7 +22,6 @@ package org.elasticsearch.search.sort; import org.apache.lucene.search.SortField; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; @@ -109,10 +108,8 @@ public class FieldSortBuilderTests extends AbstractSortTestCase { @Override @@ -215,8 +220,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase GeoDistanceSortBuilder.fromXContent(context, "")); assertEquals("sort_mode [sum] isn't supported for sorting by geo distance", e.getMessage()); @@ -311,8 +312,7 @@ public class GeoDistanceSortBuilderTests extends AbstractSortTestCase parse(sortBuilder)); + assertEquals("Deprecated field [sort_mode] used, expected [mode] instead", ex.getMessage()); + } + + private static GeoDistanceSortBuilder parse(XContentBuilder sortBuilder) throws Exception { + XContentParser parser = XContentHelper.createParser(sortBuilder.bytes()); + QueryParseContext parseContext = new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT); + parser.nextToken(); + return GeoDistanceSortBuilder.fromXContent(parseContext, null); + } + @Override protected GeoDistanceSortBuilder fromXContent(QueryParseContext context, String fieldName) throws IOException { return GeoDistanceSortBuilder.fromXContent(context, fieldName); diff --git a/core/src/test/java/org/elasticsearch/search/sort/ScoreSortBuilderTests.java b/core/src/test/java/org/elasticsearch/search/sort/ScoreSortBuilderTests.java index 2a99c8318db..142a88c4036 100644 --- a/core/src/test/java/org/elasticsearch/search/sort/ScoreSortBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/search/sort/ScoreSortBuilderTests.java @@ -23,7 +23,6 @@ package org.elasticsearch.search.sort; import org.apache.lucene.search.SortField; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryParseContext; @@ -67,8 +66,6 @@ public class ScoreSortBuilderTests extends AbstractSortTestCase> parseSort(String jsonString) throws IOException { XContentParser itemParser = XContentHelper.createParser(new BytesArray(jsonString)); - QueryParseContext context = new QueryParseContext(indicesQueriesRegistry); - context.reset(itemParser); + QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, itemParser, ParseFieldMatcher.STRICT); assertEquals(XContentParser.Token.START_OBJECT, itemParser.nextToken()); assertEquals(XContentParser.Token.FIELD_NAME, itemParser.nextToken()); diff --git a/core/src/test/java/org/elasticsearch/search/sort/SortParserTests.java b/core/src/test/java/org/elasticsearch/search/sort/SortParserTests.java deleted file mode 100644 index a5ef892bf17..00000000000 --- a/core/src/test/java/org/elasticsearch/search/sort/SortParserTests.java +++ /dev/null @@ -1,165 +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.sort; - -import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.geo.GeoPoint; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentHelper; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.index.IndexService; -import org.elasticsearch.index.query.QueryParseContext; -import org.elasticsearch.test.ESSingleNodeTestCase; -import org.elasticsearch.test.TestSearchContext; - -import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; - -public class SortParserTests extends ESSingleNodeTestCase { - public void testGeoDistanceSortParserManyPointsNoException() throws Exception { - XContentBuilder mapping = jsonBuilder(); - mapping.startObject().startObject("type").startObject("properties").startObject("location").field("type", "geo_point").endObject().endObject().endObject().endObject(); - IndexService indexService = createIndex("testidx", Settings.builder().build(), "type", mapping); - TestSearchContext context = (TestSearchContext) createSearchContext(indexService); - context.getQueryShardContext().setTypes("type"); - - XContentBuilder sortBuilder = jsonBuilder(); - sortBuilder.startObject(); - sortBuilder.startArray("location"); - sortBuilder.startArray().value(1.2).value(3).endArray().startArray().value(5).value(6).endArray(); - sortBuilder.endArray(); - sortBuilder.field("order", "desc"); - sortBuilder.field("unit", "km"); - sortBuilder.field("mode", "max"); - sortBuilder.endObject(); - parse(context, sortBuilder); - - sortBuilder = jsonBuilder(); - sortBuilder.startObject(); - sortBuilder.startArray("location"); - sortBuilder.value(new GeoPoint(1.2, 3)).value(new GeoPoint(1.2, 3)); - sortBuilder.endArray(); - sortBuilder.field("order", "desc"); - sortBuilder.field("unit", "km"); - sortBuilder.field("mode", "max"); - sortBuilder.endObject(); - parse(context, sortBuilder); - - sortBuilder = jsonBuilder(); - sortBuilder.startObject(); - sortBuilder.startArray("location"); - sortBuilder.value("1,2").value("3,4"); - sortBuilder.endArray(); - sortBuilder.field("order", "desc"); - sortBuilder.field("unit", "km"); - sortBuilder.field("mode", "max"); - sortBuilder.endObject(); - parse(context, sortBuilder); - - sortBuilder = jsonBuilder(); - sortBuilder.startObject(); - sortBuilder.startArray("location"); - sortBuilder.value("s3y0zh7w1z0g").value("s6wjr4et3f8v"); - sortBuilder.endArray(); - sortBuilder.field("order", "desc"); - sortBuilder.field("unit", "km"); - sortBuilder.field("mode", "max"); - sortBuilder.endObject(); - parse(context, sortBuilder); - - sortBuilder = jsonBuilder(); - sortBuilder.startObject(); - sortBuilder.startArray("location"); - sortBuilder.value(1.2).value(3); - sortBuilder.endArray(); - sortBuilder.field("order", "desc"); - sortBuilder.field("unit", "km"); - sortBuilder.field("mode", "max"); - sortBuilder.endObject(); - parse(context, sortBuilder); - - sortBuilder = jsonBuilder(); - sortBuilder.startObject(); - sortBuilder.field("location", new GeoPoint(1, 2)); - sortBuilder.field("order", "desc"); - sortBuilder.field("unit", "km"); - sortBuilder.field("mode", "max"); - sortBuilder.endObject(); - parse(context, sortBuilder); - - sortBuilder = jsonBuilder(); - sortBuilder.startObject(); - sortBuilder.field("location", "1,2"); - sortBuilder.field("order", "desc"); - sortBuilder.field("unit", "km"); - sortBuilder.field("mode", "max"); - sortBuilder.endObject(); - parse(context, sortBuilder); - - sortBuilder = jsonBuilder(); - sortBuilder.startObject(); - sortBuilder.field("location", "s3y0zh7w1z0g"); - sortBuilder.field("order", "desc"); - sortBuilder.field("unit", "km"); - sortBuilder.field("mode", "max"); - sortBuilder.endObject(); - parse(context, sortBuilder); - - sortBuilder = jsonBuilder(); - sortBuilder.startObject(); - sortBuilder.startArray("location"); - sortBuilder.value(new GeoPoint(1, 2)).value("s3y0zh7w1z0g").startArray().value(1).value(2).endArray().value("1,2"); - sortBuilder.endArray(); - sortBuilder.field("order", "desc"); - sortBuilder.field("unit", "km"); - sortBuilder.field("mode", "max"); - sortBuilder.endObject(); - parse(context, sortBuilder); - } - - public void testGeoDistanceSortDeprecatedSortModeException() throws Exception { - XContentBuilder mapping = jsonBuilder(); - mapping.startObject().startObject("type").startObject("properties").startObject("location").field("type", "geo_point").endObject().endObject().endObject().endObject(); - IndexService indexService = createIndex("testidx", Settings.builder().build(), "type", mapping); - TestSearchContext context = (TestSearchContext) createSearchContext(indexService); - context.getQueryShardContext().setTypes("type"); - - XContentBuilder sortBuilder = jsonBuilder(); - sortBuilder.startObject(); - sortBuilder.startArray("location"); - sortBuilder.startArray().value(1.2).value(3).endArray().startArray().value(5).value(6).endArray(); - sortBuilder.endArray(); - sortBuilder.field("order", "desc"); - sortBuilder.field("unit", "km"); - sortBuilder.field("sort_mode", "max"); - sortBuilder.endObject(); - IllegalArgumentException ex = expectThrows(IllegalArgumentException.class, () -> parse(context, sortBuilder)); - assertEquals("Deprecated field [sort_mode] used, expected [mode] instead", ex.getMessage()); - } - - protected void parse(TestSearchContext context, XContentBuilder sortBuilder) throws Exception { - QueryParseContext parseContext = context.getQueryShardContext().parseContext(); - XContentParser parser = XContentHelper.createParser(sortBuilder.bytes()); - parseContext.reset(parser); - parseContext.parseFieldMatcher(ParseFieldMatcher.STRICT); - parser.nextToken(); - GeoDistanceSortBuilder.fromXContent(parseContext, null); - } -} diff --git a/core/src/test/java/org/elasticsearch/search/suggest/AbstractSuggestionBuilderTestCase.java b/core/src/test/java/org/elasticsearch/search/suggest/AbstractSuggestionBuilderTestCase.java index ccf8700af05..710f001a276 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/AbstractSuggestionBuilderTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/AbstractSuggestionBuilderTestCase.java @@ -146,8 +146,6 @@ public abstract class AbstractSuggestionBuilderTestCase { * creates random suggestion builder, renders it to xContent and back to new instance that should be equal to original */ public void testFromXContent() throws IOException { - QueryParseContext context = new QueryParseContext(null); - context.parseFieldMatcher(new ParseFieldMatcher(Settings.EMPTY)); for (int runs = 0; runs < NUMBER_OF_RUNS; runs++) { SuggestBuilder suggestBuilder = createTestModel(); XContentBuilder xContentBuilder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); @@ -79,8 +77,7 @@ public class SuggestBuilderTests extends WritableTestCase { } suggestBuilder.toXContent(xContentBuilder, ToXContent.EMPTY_PARAMS); XContentParser parser = XContentHelper.createParser(xContentBuilder.bytes()); - context.reset(parser); - + QueryParseContext context = new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT); SuggestBuilder secondSuggestBuilder = SuggestBuilder.fromXContent(context, suggesters); assertNotSame(suggestBuilder, secondSuggestBuilder); assertEquals(suggestBuilder, secondSuggestBuilder); diff --git a/core/src/test/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGeneratorTests.java b/core/src/test/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGeneratorTests.java index b0fc5509687..a3a5ea01c33 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGeneratorTests.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/phrase/DirectCandidateGeneratorTests.java @@ -23,7 +23,6 @@ import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; @@ -41,6 +40,7 @@ import static org.hamcrest.Matchers.equalTo; public class DirectCandidateGeneratorTests extends ESTestCase{ + private static final IndicesQueriesRegistry mockRegistry = new IndicesQueriesRegistry(); private static final int NUMBER_OF_RUNS = 20; @@ -110,8 +110,6 @@ public class DirectCandidateGeneratorTests extends ESTestCase{ * creates random candidate generator, renders it to xContent and back to new instance that should be equal to original */ public void testFromXContent() throws IOException { - QueryParseContext context = new QueryParseContext(new IndicesQueriesRegistry()); - context.parseFieldMatcher(new ParseFieldMatcher(Settings.EMPTY)); for (int runs = 0; runs < NUMBER_OF_RUNS; runs++) { DirectCandidateGeneratorBuilder generator = randomCandidateGenerator(); XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); @@ -121,7 +119,7 @@ public class DirectCandidateGeneratorTests extends ESTestCase{ generator.toXContent(builder, ToXContent.EMPTY_PARAMS); XContentParser parser = XContentHelper.createParser(builder.bytes()); - context.reset(parser); + QueryParseContext context = new QueryParseContext(mockRegistry, parser, ParseFieldMatcher.STRICT); parser.nextToken(); DirectCandidateGeneratorBuilder secondGenerator = DirectCandidateGeneratorBuilder.fromXContent(context); assertNotSame(generator, secondGenerator); @@ -152,43 +150,38 @@ public class DirectCandidateGeneratorTests extends ESTestCase{ * test that bad xContent throws exception */ public void testIllegalXContent() throws IOException { - QueryParseContext context = new QueryParseContext(new IndicesQueriesRegistry()); - context.parseFieldMatcher(new ParseFieldMatcher(Settings.EMPTY)); - // test missing fieldname String directGenerator = "{ }"; - XContentParser parser = XContentFactory.xContent(directGenerator).createParser(directGenerator); - context.reset(parser); - Exception e = expectThrows(IllegalArgumentException.class, () -> DirectCandidateGeneratorBuilder.fromXContent(context)); - assertEquals("[direct_generator] expects exactly one field parameter, but found []", e.getMessage()); + assertIllegalXContent(directGenerator, IllegalArgumentException.class, + "[direct_generator] expects exactly one field parameter, but found []"); // test two fieldnames directGenerator = "{ \"field\" : \"f1\", \"field\" : \"f2\" }"; - parser = XContentFactory.xContent(directGenerator).createParser(directGenerator); - context.reset(parser); - e = expectThrows(IllegalArgumentException.class, () -> DirectCandidateGeneratorBuilder.fromXContent(context)); - assertEquals("[direct_generator] expects exactly one field parameter, but found [f2, f1]", e.getMessage()); + assertIllegalXContent(directGenerator, IllegalArgumentException.class, + "[direct_generator] expects exactly one field parameter, but found [f2, f1]"); // test unknown field directGenerator = "{ \"unknown_param\" : \"f1\" }"; - parser = XContentFactory.xContent(directGenerator).createParser(directGenerator); - context.reset(parser); - e = expectThrows(IllegalArgumentException.class, () -> DirectCandidateGeneratorBuilder.fromXContent(context)); - assertEquals("[direct_generator] unknown field [unknown_param], parser not found", e.getMessage()); + assertIllegalXContent(directGenerator, IllegalArgumentException.class, + "[direct_generator] unknown field [unknown_param], parser not found"); // test bad value for field (e.g. size expects an int) directGenerator = "{ \"size\" : \"xxl\" }"; - parser = XContentFactory.xContent(directGenerator).createParser(directGenerator); - context.reset(parser); - e = expectThrows(ParsingException.class, () -> DirectCandidateGeneratorBuilder.fromXContent(context)); - assertEquals("[direct_generator] failed to parse field [size]", e.getMessage()); + assertIllegalXContent(directGenerator, ParsingException.class, + "[direct_generator] failed to parse field [size]"); // test unexpected token directGenerator = "{ \"size\" : [ \"xxl\" ] }"; - parser = XContentFactory.xContent(directGenerator).createParser(directGenerator); - context.reset(parser); - e = expectThrows(IllegalArgumentException.class, () -> DirectCandidateGeneratorBuilder.fromXContent(context)); - assertEquals("[direct_generator] size doesn't support values of type: START_ARRAY", e.getMessage()); + assertIllegalXContent(directGenerator, IllegalArgumentException.class, + "[direct_generator] size doesn't support values of type: START_ARRAY"); + } + + private static void assertIllegalXContent(String directGenerator, Class exceptionClass, String exceptionMsg) + throws IOException { + XContentParser parser = XContentFactory.xContent(directGenerator).createParser(directGenerator); + QueryParseContext context = new QueryParseContext(mockRegistry, parser, ParseFieldMatcher.STRICT); + Exception e = expectThrows(exceptionClass, () -> DirectCandidateGeneratorBuilder.fromXContent(context)); + assertEquals(exceptionMsg, e.getMessage()); } /** diff --git a/core/src/test/java/org/elasticsearch/search/suggest/phrase/SmoothingModelTestCase.java b/core/src/test/java/org/elasticsearch/search/suggest/phrase/SmoothingModelTestCase.java index c91e157178f..1731ddd7c4f 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/phrase/SmoothingModelTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/phrase/SmoothingModelTestCase.java @@ -36,7 +36,6 @@ import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.lucene.BytesRefs; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; @@ -93,9 +92,6 @@ public abstract class SmoothingModelTestCase extends ESTestCase { * Test that creates new smoothing model from a random test smoothing model and checks both for equality */ public void testFromXContent() throws IOException { - QueryParseContext context = new QueryParseContext(new IndicesQueriesRegistry()); - context.parseFieldMatcher(new ParseFieldMatcher(Settings.EMPTY)); - SmoothingModel testModel = createTestModel(); XContentBuilder contentBuilder = XContentFactory.contentBuilder(randomFrom(XContentType.values())); if (randomBoolean()) { @@ -105,7 +101,7 @@ public abstract class SmoothingModelTestCase extends ESTestCase { testModel.innerToXContent(contentBuilder, ToXContent.EMPTY_PARAMS); contentBuilder.endObject(); XContentParser parser = XContentHelper.createParser(contentBuilder.bytes()); - context.reset(parser); + QueryParseContext context = new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT); parser.nextToken(); // go to start token, real parsing would do that in the outer element parser SmoothingModel parsedModel = fromXContent(context); assertNotSame(testModel, parsedModel); diff --git a/modules/lang-mustache/src/test/java/org/elasticsearch/messy/tests/TemplateQueryParserTests.java b/modules/lang-mustache/src/test/java/org/elasticsearch/messy/tests/TemplateQueryParserTests.java index 4523843c4c3..37cae5092cb 100644 --- a/modules/lang-mustache/src/test/java/org/elasticsearch/messy/tests/TemplateQueryParserTests.java +++ b/modules/lang-mustache/src/test/java/org/elasticsearch/messy/tests/TemplateQueryParserTests.java @@ -18,10 +18,6 @@ */ package org.elasticsearch.messy.tests; -import java.io.IOException; -import java.lang.reflect.Proxy; -import java.util.Collections; - import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; import org.apache.lucene.util.Accountable; @@ -75,6 +71,10 @@ import org.elasticsearch.threadpool.ThreadPoolModule; import org.junit.After; import org.junit.Before; +import java.io.IOException; +import java.lang.reflect.Proxy; +import java.util.Collections; + import static org.hamcrest.Matchers.containsString; /** @@ -163,10 +163,11 @@ public class TemplateQueryParserTests extends ESTestCase { String templateString = "{" + "\"query\":{\"match_{{template}}\": {}}," + "\"params\":{\"template\":\"all\"}" + "}"; XContentParser templateSourceParser = XContentFactory.xContent(templateString).createParser(templateString); - context.reset(templateSourceParser); + context.reset(); templateSourceParser.nextToken(); - Query query = QueryBuilder.rewriteQuery(TemplateQueryBuilder.fromXContent(context.parseContext()), context).toQuery(context); + Query query = QueryBuilder.rewriteQuery(TemplateQueryBuilder.fromXContent(context.newParseContext(templateSourceParser)), + context).toQuery(context); assertTrue("Parsing template query failed.", query instanceof MatchAllDocsQuery); } @@ -174,9 +175,9 @@ public class TemplateQueryParserTests extends ESTestCase { String templateString = "{" + " \"inline\" : \"{ \\\"match_{{#use_it}}{{template}}{{/use_it}}\\\":{} }\"," + " \"params\":{" + " \"template\":\"all\"," + " \"use_it\": true" + " }" + "}"; XContentParser templateSourceParser = XContentFactory.xContent(templateString).createParser(templateString); - context.reset(templateSourceParser); + context.reset(); - Query query = QueryBuilder.rewriteQuery(TemplateQueryBuilder.fromXContent(context.parseContext()), context).toQuery(context); + Query query = QueryBuilder.rewriteQuery(TemplateQueryBuilder.fromXContent(context.newParseContext(templateSourceParser)), context).toQuery(context); assertTrue("Parsing template query failed.", query instanceof MatchAllDocsQuery); } @@ -190,10 +191,10 @@ public class TemplateQueryParserTests extends ESTestCase { + " \"params\":{" + " \"size\":2" + " }\n" + "}"; XContentParser templateSourceParser = XContentFactory.xContent(templateString).createParser(templateString); - context.reset(templateSourceParser); + context.reset(); try { - TemplateQueryBuilder.fromXContent(context.parseContext()).rewrite(context); + TemplateQueryBuilder.fromXContent(context.newParseContext(templateSourceParser)).rewrite(context); fail("Expected ParsingException"); } catch (ParsingException e) { assertThat(e.getMessage(), containsString("query malformed, no field after start_object")); @@ -204,11 +205,12 @@ public class TemplateQueryParserTests extends ESTestCase { String templateString = "{ \"file\": \"storedTemplate\" ,\"params\":{\"template\":\"all\" } } "; XContentParser templateSourceParser = XContentFactory.xContent(templateString).createParser(templateString); - context.reset(templateSourceParser); + context.reset(); templateSourceParser.nextToken(); - Query query = QueryBuilder.rewriteQuery(TemplateQueryBuilder.fromXContent(context.parseContext()), context).toQuery(context); + Query query = QueryBuilder.rewriteQuery(TemplateQueryBuilder.fromXContent(context.newParseContext(templateSourceParser)), + context).toQuery(context); assertTrue("Parsing template query failed.", query instanceof MatchAllDocsQuery); } @@ -216,10 +218,10 @@ public class TemplateQueryParserTests extends ESTestCase { String templateString = "{ \"file\": \"storedTemplate\" ,\"params\":{\"template\":\"all\" } } "; XContentParser templateSourceParser = XContentFactory.xContent(templateString).createParser(templateString); - context.reset(templateSourceParser); + context.reset(); templateSourceParser.nextToken(); try { - TemplateQueryBuilder.fromXContent(context.parseContext()).toQuery(context); + TemplateQueryBuilder.fromXContent(context.newParseContext(templateSourceParser)).toQuery(context); fail(); } catch (UnsupportedOperationException ex) { assertEquals("this query must be rewritten first", ex.getMessage()); diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java index 96000720299..02e4d74bd48 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java @@ -78,8 +78,7 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler destParser = new ObjectParser<>("dest"); @@ -98,7 +97,7 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler sourceParser.parse(p, v.getSearchRequest(), c), new ParseField("source"), ValueType.OBJECT); PARSER.declareField((p, v, c) -> destParser.parse(p, v.getDestination(), c), new ParseField("dest"), ValueType.OBJECT); PARSER.declareInt(ReindexRequest::setSize, new ParseField("size")); - PARSER.declareField((p, v, c) -> v.setScript(Script.parse(p, c.queryParseContext.getParseFieldMatcher())), new ParseField("script"), + PARSER.declareField((p, v, c) -> v.setScript(Script.parse(p, c.getParseFieldMatcher())), new ParseField("script"), ValueType.OBJECT); PARSER.declareString(ReindexRequest::setConflicts, new ParseField("conflicts")); } @@ -121,8 +120,8 @@ public class RestReindexAction extends AbstractBaseReindexRestHandler Date: Fri, 15 Apr 2016 17:13:12 +0200 Subject: [PATCH 021/561] Build: Allow for file based deploy, sign packages This allows for a local file based deploy without needed nexus auth information. Also signing of packages has been added, either via gradle.properties or using system properties as a fallback. The property build.repository allows to configure another endpoint if no snapshot build is done. Fix creation of .asc file for tar.gz distribution Closes #17405 --- build.gradle | 36 ++++++++++++++++++++++++++--------- distribution/build.gradle | 9 +++++++++ distribution/tar/build.gradle | 5 ++++- 3 files changed, 40 insertions(+), 10 deletions(-) diff --git a/build.gradle b/build.gradle index 761e1986eb1..dab1c256d23 100644 --- a/build.gradle +++ b/build.gradle @@ -18,6 +18,8 @@ */ import com.bmuschko.gradle.nexus.NexusPlugin +import org.eclipse.jgit.lib.Repository +import org.eclipse.jgit.lib.RepositoryBuilder import org.gradle.plugins.ide.eclipse.model.SourceFolder // common maven publishing configuration @@ -50,21 +52,37 @@ subprojects { javadoc = true tests = false } + nexus { + Repository repo = new RepositoryBuilder().findGitDir(new File('.')).build() + String shortHash = repo.resolve('HEAD')?.name?.substring(0,7) + String buildSnapshot = System.getProperty('build.snapshot', 'true') + if (buildSnapshot == 'false') { + repositoryUrl = project.hasProperty('build.repository') ? project.property('build.repository') : "file://${System.getenv('HOME')}/elasticsearch-releases/${version}-${shortHash}/" + } + } // we have our own username/password prompts so that they only happen once - // TODO: add gpg signing prompts + // TODO: add gpg signing prompts, which is tricky, as the buildDeb/buildRpm tasks are executed before this code block project.gradle.taskGraph.whenReady { taskGraph -> if (taskGraph.allTasks.any { it.name == 'uploadArchives' }) { Console console = System.console() - if (project.hasProperty('nexusUsername') == false) { - String nexusUsername = console.readLine('\nNexus username: ') + // no need for username/password on local deploy + if (project.nexus.repositoryUrl.startsWith('file://')) { project.rootProject.allprojects.each { - it.ext.nexusUsername = nexusUsername + it.ext.nexusUsername = 'foo' + it.ext.nexusPassword = 'bar' } - } - if (project.hasProperty('nexusPassword') == false) { - String nexusPassword = new String(console.readPassword('\nNexus password: ')) - project.rootProject.allprojects.each { - it.ext.nexusPassword = nexusPassword + } else { + if (project.hasProperty('nexusUsername') == false) { + String nexusUsername = console.readLine('\nNexus username: ') + project.rootProject.allprojects.each { + it.ext.nexusUsername = nexusUsername + } + } + if (project.hasProperty('nexusPassword') == false) { + String nexusPassword = new String(console.readPassword('\nNexus password: ')) + project.rootProject.allprojects.each { + it.ext.nexusPassword = nexusPassword + } } } } diff --git a/distribution/build.gradle b/distribution/build.gradle index 0bfa1703d57..4050f9ccd02 100644 --- a/distribution/build.gradle +++ b/distribution/build.gradle @@ -287,6 +287,15 @@ configure(subprojects.findAll { ['deb', 'rpm'].contains(it.name) }) { we see it. We'll add it back on to the file name though. */ version project.version.replace('-SNAPSHOT', '') + // signing setup + if (project.hasProperty('signing.password') && System.getProperty('build.snapshot', 'true') == 'false') { + signingKeyId = project.hasProperty('signing.keyId') ? project.property('signing.keyId') : 'D88E42B4' + signingKeyPassphrase = project.property('signing.password') + signingKeyRingFile = project.hasProperty('signing.secretKeyRingFile') ? + project.file(project.property('signing.secretKeyRingFile')) : + new File(new File(System.getProperty('user.home'), '.gnupg'), 'secring.gpg') + } + String scripts = "${packagingFiles}/scripts" preInstall file("${scripts}/preinst") postInstall file("${scripts}/postinst") diff --git a/distribution/tar/build.gradle b/distribution/tar/build.gradle index 7230ab50799..624f5b57022 100644 --- a/distribution/tar/build.gradle +++ b/distribution/tar/build.gradle @@ -26,5 +26,8 @@ task buildTar(type: Tar) { artifacts { 'default' buildTar - archives buildTar + project.afterEvaluate { + // gradle is broken for extensions that contain a dot, so we must be explicit about the name of the .asc file + project.signArchives.singleSignature.type = 'tar.gz.asc' + } } From c966d14f8b3d8b76f214f6b397b3b894ac92ffbf Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Fri, 15 Apr 2016 11:35:05 -0400 Subject: [PATCH 022/561] [build] Don't resolve the revision hash unless you need it This fixes the build for folks that build without git installed locally and should speed up the general case because we aren't trying to resolve git information when it isn't really needed. --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index dab1c256d23..21e7a49bd4c 100644 --- a/build.gradle +++ b/build.gradle @@ -53,10 +53,10 @@ subprojects { tests = false } nexus { - Repository repo = new RepositoryBuilder().findGitDir(new File('.')).build() - String shortHash = repo.resolve('HEAD')?.name?.substring(0,7) String buildSnapshot = System.getProperty('build.snapshot', 'true') if (buildSnapshot == 'false') { + Repository repo = new RepositoryBuilder().findGitDir(new File('.')).build() + String shortHash = repo.resolve('HEAD')?.name?.substring(0,7) repositoryUrl = project.hasProperty('build.repository') ? project.property('build.repository') : "file://${System.getenv('HOME')}/elasticsearch-releases/${version}-${shortHash}/" } } From 4e77adf38e3bdec774cffee351e3c31f8b9cf25a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Fri, 15 Apr 2016 17:47:19 +0200 Subject: [PATCH 023/561] Clean up creation of shard context in AbstractQueryTestCase The queryShardContext we create during setup was sometimes accessed directly, sometimes by making a copy through the createShardContext() helper. This should be the default. Also making sure that strict parsing is switched on via IndexSettings in the test testup. --- .../index/query/AbstractQueryTestCase.java | 25 +++++++++-------- .../index/query/BoolQueryBuilderTests.java | 8 +++--- .../query/BoostingQueryBuilderTests.java | 5 ++-- .../GeoBoundingBoxQueryBuilderTests.java | 10 ++++--- .../query/GeoDistanceQueryBuilderTests.java | 12 ++++---- .../query/GeoDistanceRangeQueryTests.java | 8 +++--- .../query/GeoPolygonQueryBuilderTests.java | 7 ++--- .../query/GeoShapeQueryBuilderTests.java | 4 +-- .../query/GeohashCellQueryBuilderTests.java | 7 ++--- .../query/HasChildQueryBuilderTests.java | 10 +++---- .../query/HasParentQueryBuilderTests.java | 10 +++---- .../index/query/NestedQueryBuilderTests.java | 20 ++++++------- .../query/ParentIdQueryBuilderTests.java | 10 +++---- .../query/PercolatorQueryBuilderTests.java | 6 ++-- .../index/query/RangeQueryBuilderTests.java | 28 +++++++++++-------- .../query/TemplateQueryBuilderTests.java | 13 ++++----- .../index/query/TermsQueryBuilderTests.java | 4 +-- .../index/query/TypeQueryBuilderTests.java | 12 ++++---- .../index/query/WrapperQueryBuilderTests.java | 16 ++++++----- .../FunctionScoreQueryBuilderTests.java | 4 +-- 20 files changed, 112 insertions(+), 107 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java index 0f373d3664d..471d1d7baca 100644 --- a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java @@ -120,7 +120,6 @@ import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.Objects; import java.util.Set; import java.util.concurrent.ExecutionException; @@ -158,11 +157,6 @@ public abstract class AbstractQueryTestCase> private static int queryNameId = 0; private static SearchModule searchModule; - - protected static QueryShardContext queryShardContext() { - return queryShardContext; - } - protected static IndexFieldDataService indexFieldDataService() { return indexFieldDataService; } @@ -200,13 +194,15 @@ public abstract class AbstractQueryTestCase> @BeforeClass public static void init() throws IOException { // we have to prefer CURRENT since with the range of versions we support it's rather unlikely to get the current actually. - indexVersionCreated = randomBoolean() ? Version.CURRENT : VersionUtils.randomVersionBetween(random(), Version.V_2_0_0_beta1, Version.CURRENT); + indexVersionCreated = randomBoolean() ? Version.CURRENT + : VersionUtils.randomVersionBetween(random(), Version.V_2_0_0_beta1, Version.CURRENT); Settings settings = Settings.builder() .put("node.name", AbstractQueryTestCase.class.toString()) .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) .put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), false) .build(); Settings indexSettings = Settings.builder() + .put(ParseFieldMatcher.PARSE_STRICT, true) .put(IndexMetaData.SETTING_VERSION_CREATED, indexVersionCreated).build(); final ThreadPool threadPool = new ThreadPool(settings); index = new Index(randomAsciiOfLengthBetween(1, 10), "_na_"); @@ -236,14 +232,16 @@ public abstract class AbstractQueryTestCase> Set engines = new HashSet<>(); engines.add(mockScriptEngine); List customContexts = new ArrayList<>(); - ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class, MockScriptEngine.TYPES))); + ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections + .singletonList(new ScriptEngineRegistry.ScriptEngineRegistration(MockScriptEngine.class, MockScriptEngine.TYPES))); bind(ScriptEngineRegistry.class).toInstance(scriptEngineRegistry); ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customContexts); bind(ScriptContextRegistry.class).toInstance(scriptContextRegistry); ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry); bind(ScriptSettings.class).toInstance(scriptSettings); try { - ScriptService scriptService = new ScriptService(settings, new Environment(settings), engines, null, scriptEngineRegistry, scriptContextRegistry, scriptSettings); + ScriptService scriptService = new ScriptService(settings, new Environment(settings), engines, null, + scriptEngineRegistry, scriptContextRegistry, scriptSettings); bind(ScriptService.class).toInstance(scriptService); } catch (IOException e) { throw new IllegalStateException("error while binding ScriptService", e); @@ -285,10 +283,12 @@ public abstract class AbstractQueryTestCase> ScriptService scriptService = injector.getInstance(ScriptService.class); SimilarityService similarityService = new SimilarityService(idxSettings, Collections.emptyMap()); MapperRegistry mapperRegistry = injector.getInstance(MapperRegistry.class); - MapperService mapperService = new MapperService(idxSettings, analysisService, similarityService, mapperRegistry, () -> queryShardContext); + MapperService mapperService = new MapperService(idxSettings, analysisService, similarityService, mapperRegistry, + () -> queryShardContext); IndicesFieldDataCache indicesFieldDataCache = new IndicesFieldDataCache(settings, new IndexFieldDataCache.Listener() { }); - indexFieldDataService = new IndexFieldDataService(idxSettings, indicesFieldDataCache, injector.getInstance(CircuitBreakerService.class), mapperService); + indexFieldDataService = new IndexFieldDataService(idxSettings, indicesFieldDataCache, + injector.getInstance(CircuitBreakerService.class), mapperService); BitsetFilterCache bitsetFilterCache = new BitsetFilterCache(idxSettings, new BitsetFilterCache.Listener() { @Override public void onCache(ShardId shardId, Accountable accountable) { @@ -302,7 +302,8 @@ public abstract class AbstractQueryTestCase> }); PercolatorQueryCache percolatorQueryCache = new PercolatorQueryCache(idxSettings, () -> queryShardContext); indicesQueriesRegistry = injector.getInstance(IndicesQueriesRegistry.class); - queryShardContext = new QueryShardContext(idxSettings, bitsetFilterCache, indexFieldDataService, mapperService, similarityService, scriptService, indicesQueriesRegistry, percolatorQueryCache, null); + queryShardContext = new QueryShardContext(idxSettings, bitsetFilterCache, indexFieldDataService, mapperService, similarityService, + scriptService, indicesQueriesRegistry, percolatorQueryCache, null); //create some random type with some default field, those types will stick around for all of the subclasses currentTypes = new String[randomIntBetween(0, 5)]; for (int i = 0; i < currentTypes.length; i++) { diff --git a/core/src/test/java/org/elasticsearch/index/query/BoolQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/BoolQueryBuilderTests.java index 4ed593c6ff7..b6b97f6fbf2 100644 --- a/core/src/test/java/org/elasticsearch/index/query/BoolQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/BoolQueryBuilderTests.java @@ -366,7 +366,7 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase rewritten = boolQueryBuilder.rewrite(queryShardContext()); + QueryBuilder rewritten = boolQueryBuilder.rewrite(createShardContext()); if (mustRewrite == false && boolQueryBuilder.must().isEmpty()) { // if it's empty we rewrite to match all assertEquals(rewritten, new MatchAllQueryBuilder()); @@ -398,15 +398,15 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase rewritten = boolQueryBuilder.rewrite(queryShardContext()); + QueryBuilder rewritten = boolQueryBuilder.rewrite(createShardContext()); BoolQueryBuilder expected = new BoolQueryBuilder(); expected.must(new WrapperQueryBuilder(new MatchAllQueryBuilder().toString())); assertEquals(expected, rewritten); expected = new BoolQueryBuilder(); expected.must(new MatchAllQueryBuilder()); - QueryBuilder rewrittenAgain = rewritten.rewrite(queryShardContext()); + QueryBuilder rewrittenAgain = rewritten.rewrite(createShardContext()); assertEquals(rewrittenAgain, expected); - assertEquals(QueryBuilder.rewriteQuery(boolQueryBuilder, queryShardContext()), expected); + assertEquals(QueryBuilder.rewriteQuery(boolQueryBuilder, createShardContext()), expected); } } diff --git a/core/src/test/java/org/elasticsearch/index/query/BoostingQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/BoostingQueryBuilderTests.java index 414ab1f1131..27c888aa9dd 100644 --- a/core/src/test/java/org/elasticsearch/index/query/BoostingQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/BoostingQueryBuilderTests.java @@ -20,7 +20,6 @@ package org.elasticsearch.index.query; import org.apache.lucene.queries.BoostingQuery; -import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; import java.io.IOException; @@ -109,12 +108,12 @@ public class BoostingQueryBuilderTests extends AbstractQueryTestCase rewrite = qb.rewrite(queryShardContext()); + QueryBuilder rewrite = qb.rewrite(createShardContext()); if (positive instanceof MatchAllQueryBuilder && negative instanceof MatchAllQueryBuilder) { assertSame(rewrite, qb); } else { assertNotSame(rewrite, qb); - assertEquals(new BoostingQueryBuilder(positive.rewrite(queryShardContext()), negative.rewrite(queryShardContext())), rewrite); + assertEquals(new BoostingQueryBuilder(positive.rewrite(createShardContext()), negative.rewrite(createShardContext())), rewrite); } } } diff --git a/core/src/test/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilderTests.java index 734495189b9..558d8b0e3f1 100644 --- a/core/src/test/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/GeoBoundingBoxQueryBuilderTests.java @@ -439,8 +439,9 @@ public class GeoBoundingBoxQueryBuilderTests extends AbstractQueryTestCase failingQueryBuilder.toQuery(queryShardContext())); + QueryShardException e = expectThrows(QueryShardException.class, () -> failingQueryBuilder.toQuery(shardContext)); assertThat(e.getMessage(), containsString("failed to find geo_point field [unmapped]")); } } diff --git a/core/src/test/java/org/elasticsearch/index/query/GeoDistanceQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/GeoDistanceQueryBuilderTests.java index dff2b667d25..13036ce168d 100644 --- a/core/src/test/java/org/elasticsearch/index/query/GeoDistanceQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/GeoDistanceQueryBuilderTests.java @@ -19,11 +19,9 @@ package org.elasticsearch.index.query; -import org.locationtech.spatial4j.shape.Point; -import org.apache.lucene.spatial.geopoint.search.GeoPointDistanceQuery; - import org.apache.lucene.search.MatchNoDocsQuery; import org.apache.lucene.search.Query; +import org.apache.lucene.spatial.geopoint.search.GeoPointDistanceQuery; import org.apache.lucene.spatial.util.GeoEncodingUtils; import org.elasticsearch.Version; import org.elasticsearch.common.geo.GeoDistance; @@ -31,6 +29,7 @@ import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.unit.DistanceUnit; import org.elasticsearch.index.search.geo.GeoDistanceRangeQuery; import org.elasticsearch.test.geo.RandomShapeGenerator; +import org.locationtech.spatial4j.shape.Point; import java.io.IOException; @@ -384,7 +383,7 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase 0); Query parsedQuery = parseQuery(query).toQuery(createShardContext()); - Version version = queryShardContext().indexVersionCreated(); + Version version = createShardContext().indexVersionCreated(); if (version.before(Version.V_2_2_0)) { GeoDistanceRangeQuery q = (GeoDistanceRangeQuery) parsedQuery; assertThat(q.fieldName(), equalTo(GEO_POINT_FIELD_NAME)); @@ -430,13 +429,14 @@ public class GeoDistanceQueryBuilderTests extends AbstractQueryTestCase failingQueryBuilder.toQuery(queryShardContext())); + QueryShardException e = expectThrows(QueryShardException.class, () -> failingQueryBuilder.toQuery(shardContext)); assertThat(e.getMessage(), containsString("failed to find geo_point field [unmapped]")); } } diff --git a/core/src/test/java/org/elasticsearch/index/query/GeoDistanceRangeQueryTests.java b/core/src/test/java/org/elasticsearch/index/query/GeoDistanceRangeQueryTests.java index ab50922e201..d9aef7270b3 100644 --- a/core/src/test/java/org/elasticsearch/index/query/GeoDistanceRangeQueryTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/GeoDistanceRangeQueryTests.java @@ -47,7 +47,7 @@ public class GeoDistanceRangeQueryTests extends AbstractQueryTestCase failingQueryBuilder.toQuery(queryShardContext())); + QueryShardException e = expectThrows(QueryShardException.class, () -> failingQueryBuilder.toQuery(createShardContext())); assertThat(e.getMessage(), containsString("failed to find geo_point field [unmapped]")); } } diff --git a/core/src/test/java/org/elasticsearch/index/query/GeoPolygonQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/GeoPolygonQueryBuilderTests.java index dd91a0e5ead..55b7f24770c 100644 --- a/core/src/test/java/org/elasticsearch/index/query/GeoPolygonQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/GeoPolygonQueryBuilderTests.java @@ -19,8 +19,6 @@ package org.elasticsearch.index.query; -import org.locationtech.spatial4j.shape.jts.JtsGeometry; - import com.vividsolutions.jts.geom.Coordinate; import org.apache.lucene.search.MatchNoDocsQuery; @@ -36,6 +34,7 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.search.geo.GeoPolygonQuery; import org.elasticsearch.test.geo.RandomShapeGenerator; import org.elasticsearch.test.geo.RandomShapeGenerator.ShapeType; +import org.locationtech.spatial4j.shape.jts.JtsGeometry; import java.io.IOException; import java.util.ArrayList; @@ -364,13 +363,13 @@ public class GeoPolygonQueryBuilderTests extends AbstractQueryTestCase polygon = randomPolygon(randomIntBetween(4, 50)); final GeoPolygonQueryBuilder queryBuilder = new GeoPolygonQueryBuilder("unmapped", polygon); queryBuilder.ignoreUnmapped(true); - Query query = queryBuilder.toQuery(queryShardContext()); + Query query = queryBuilder.toQuery(createShardContext()); assertThat(query, notNullValue()); assertThat(query, instanceOf(MatchNoDocsQuery.class)); final GeoPolygonQueryBuilder failingQueryBuilder = new GeoPolygonQueryBuilder("unmapped", polygon); failingQueryBuilder.ignoreUnmapped(false); - QueryShardException e = expectThrows(QueryShardException.class, () -> failingQueryBuilder.toQuery(queryShardContext())); + QueryShardException e = expectThrows(QueryShardException.class, () -> failingQueryBuilder.toQuery(createShardContext())); assertThat(e.getMessage(), containsString("failed to find geo_point field [unmapped]")); } } diff --git a/core/src/test/java/org/elasticsearch/index/query/GeoShapeQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/GeoShapeQueryBuilderTests.java index b335cfabb6c..08f988c2a0b 100644 --- a/core/src/test/java/org/elasticsearch/index/query/GeoShapeQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/GeoShapeQueryBuilderTests.java @@ -273,13 +273,13 @@ public class GeoShapeQueryBuilderTests extends AbstractQueryTestCase failingQueryBuilder.toQuery(queryShardContext())); + QueryShardException e = expectThrows(QueryShardException.class, () -> failingQueryBuilder.toQuery(createShardContext())); assertThat(e.getMessage(), containsString("failed to find geo_shape field [unmapped]")); } } diff --git a/core/src/test/java/org/elasticsearch/index/query/GeohashCellQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/GeohashCellQueryBuilderTests.java index ff61a9b7cf1..1a7f4e362ac 100644 --- a/core/src/test/java/org/elasticsearch/index/query/GeohashCellQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/GeohashCellQueryBuilderTests.java @@ -19,8 +19,6 @@ package org.elasticsearch.index.query; -import org.locationtech.spatial4j.shape.Point; - import org.apache.lucene.index.Term; import org.apache.lucene.queries.TermsQuery; import org.apache.lucene.search.MatchNoDocsQuery; @@ -32,6 +30,7 @@ import org.elasticsearch.index.mapper.geo.BaseGeoPointFieldMapper; import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper; import org.elasticsearch.index.query.GeohashCellQuery.Builder; import org.elasticsearch.test.geo.RandomShapeGenerator; +import org.locationtech.spatial4j.shape.Point; import java.io.IOException; @@ -163,13 +162,13 @@ public class GeohashCellQueryBuilderTests extends AbstractQueryTestCase public void testIgnoreUnmapped() throws IOException { final GeohashCellQuery.Builder queryBuilder = new GeohashCellQuery.Builder("unmapped", "c"); queryBuilder.ignoreUnmapped(true); - Query query = queryBuilder.toQuery(queryShardContext()); + Query query = queryBuilder.toQuery(createShardContext()); assertThat(query, notNullValue()); assertThat(query, instanceOf(MatchNoDocsQuery.class)); final GeohashCellQuery.Builder failingQueryBuilder = new GeohashCellQuery.Builder("unmapped", "c"); failingQueryBuilder.ignoreUnmapped(false); - QueryShardException e = expectThrows(QueryShardException.class, () -> failingQueryBuilder.toQuery(queryShardContext())); + QueryShardException e = expectThrows(QueryShardException.class, () -> failingQueryBuilder.toQuery(createShardContext())); assertThat(e.getMessage(), containsString("failed to parse [" + GeohashCellQuery.NAME + "] query. missing [" + BaseGeoPointFieldMapper.CONTENT_TYPE + "] field [unmapped]")); } diff --git a/core/src/test/java/org/elasticsearch/index/query/HasChildQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/HasChildQueryBuilderTests.java index 08a207940e0..1b8238a8cac 100644 --- a/core/src/test/java/org/elasticsearch/index/query/HasChildQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/HasChildQueryBuilderTests.java @@ -71,7 +71,7 @@ public class HasChildQueryBuilderTests extends AbstractQueryTestCase failingQueryBuilder.toQuery(queryShardContext())); + QueryShardException e = expectThrows(QueryShardException.class, () -> failingQueryBuilder.toQuery(createShardContext())); assertThat(e.getMessage(), containsString("[" + HasChildQueryBuilder.NAME + "] no mapping found for type [unmapped]")); } } diff --git a/core/src/test/java/org/elasticsearch/index/query/HasParentQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/HasParentQueryBuilderTests.java index 7cd87f93fae..5f956581fc7 100644 --- a/core/src/test/java/org/elasticsearch/index/query/HasParentQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/HasParentQueryBuilderTests.java @@ -58,7 +58,7 @@ public class HasParentQueryBuilderTests extends AbstractQueryTestCase failingQueryBuilder.toQuery(queryShardContext())); + QueryShardException e = expectThrows(QueryShardException.class, () -> failingQueryBuilder.toQuery(createShardContext())); assertThat(e.getMessage(), containsString("[" + HasParentQueryBuilder.NAME + "] query configured 'parent_type' [unmapped] is not a valid type")); } diff --git a/core/src/test/java/org/elasticsearch/index/query/NestedQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/NestedQueryBuilderTests.java index 4c679879ad5..c8a3914fa13 100644 --- a/core/src/test/java/org/elasticsearch/index/query/NestedQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/NestedQueryBuilderTests.java @@ -29,26 +29,26 @@ import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.index.fielddata.IndexFieldDataService; import org.elasticsearch.index.mapper.MapperService; +import org.elasticsearch.index.query.support.InnerHitBuilder; +import org.elasticsearch.search.fetch.innerhits.InnerHitsContext; import org.elasticsearch.search.internal.SearchContext; import org.elasticsearch.search.sort.FieldSortBuilder; import org.elasticsearch.search.sort.SortOrder; import org.elasticsearch.test.TestSearchContext; -import org.elasticsearch.index.query.support.InnerHitBuilder; -import org.elasticsearch.search.fetch.innerhits.InnerHitsContext; import java.io.IOException; -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.notNullValue; public class NestedQueryBuilderTests extends AbstractQueryTestCase { @Override public void setUp() throws Exception { super.setUp(); - MapperService mapperService = queryShardContext().getMapperService(); + MapperService mapperService = createShardContext().getMapperService(); mapperService.merge("nested_doc", new CompressedXContent(PutMappingRequest.buildFromSimplifiedDef("nested_doc", STRING_FIELD_NAME, "type=text", INT_FIELD_NAME, "type=integer", @@ -63,9 +63,9 @@ public class NestedQueryBuilderTests extends AbstractQueryTestCase failingQueryBuilder.toQuery(queryShardContext())); + IllegalStateException e = expectThrows(IllegalStateException.class, () -> failingQueryBuilder.toQuery(createShardContext())); assertThat(e.getMessage(), containsString("[" + NestedQueryBuilder.NAME + "] failed to find nested object under path [unmapped]")); } } diff --git a/core/src/test/java/org/elasticsearch/index/query/ParentIdQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/ParentIdQueryBuilderTests.java index 20e8c1efa62..b6ded9ada8a 100644 --- a/core/src/test/java/org/elasticsearch/index/query/ParentIdQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/ParentIdQueryBuilderTests.java @@ -47,7 +47,7 @@ public class ParentIdQueryBuilderTests extends AbstractQueryTestCase failingQueryBuilder.toQuery(queryShardContext())); + QueryShardException e = expectThrows(QueryShardException.class, () -> failingQueryBuilder.toQuery(createShardContext())); assertThat(e.getMessage(), containsString("[" + ParentIdQueryBuilder.NAME + "] no mapping found for type [unmapped]")); } diff --git a/core/src/test/java/org/elasticsearch/index/query/PercolatorQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/PercolatorQueryBuilderTests.java index b4e0775f0ed..4009d37a0a3 100644 --- a/core/src/test/java/org/elasticsearch/index/query/PercolatorQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/PercolatorQueryBuilderTests.java @@ -121,12 +121,12 @@ public class PercolatorQueryBuilderTests extends AbstractQueryTestCase rewrite = pqb.rewrite(queryShardContext()); + QueryBuilder rewrite = pqb.rewrite(createShardContext()); PercolatorQueryBuilder geoShapeQueryBuilder = new PercolatorQueryBuilder(pqb.getDocumentType(), documentSource); assertEquals(geoShapeQueryBuilder, rewrite); } @@ -135,7 +135,7 @@ public class PercolatorQueryBuilderTests extends AbstractQueryTestCase rewritten = query.rewrite(queryShardContext); assertThat(rewritten, instanceOf(RangeQueryBuilder.class)); RangeQueryBuilder rewrittenRange = (RangeQueryBuilder) rewritten; @@ -474,6 +475,7 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase rewritten = query.rewrite(queryShardContext); assertThat(rewritten, instanceOf(MatchNoneQueryBuilder.class)); } @@ -490,6 +492,7 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase rewritten = query.rewrite(queryShardContext); assertThat(rewritten, sameInstance(query)); } @@ -506,11 +509,12 @@ public class RangeQueryBuilderTests extends AbstractQueryTestCase rewritten = query.rewrite(queryShardContext); assertThat(rewritten, sameInstance(query)); } diff --git a/core/src/test/java/org/elasticsearch/index/query/TemplateQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/TemplateQueryBuilderTests.java index 9426ef1f631..a6dc42a266e 100644 --- a/core/src/test/java/org/elasticsearch/index/query/TemplateQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/TemplateQueryBuilderTests.java @@ -24,7 +24,6 @@ import org.apache.lucene.search.MatchAllDocsQuery; import org.apache.lucene.search.Query; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; -import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.script.Script.ScriptParseException; import org.elasticsearch.script.ScriptService.ScriptType; @@ -124,35 +123,35 @@ public class TemplateQueryBuilderTests extends AbstractQueryTestCase builder = new TemplateQueryBuilder(new Template(query, ScriptType.INLINE, "mockscript", XContentType.JSON, Collections.emptyMap())); try { - builder.toQuery(queryShardContext()); + builder.toQuery(createShardContext()); fail(); } catch (UnsupportedOperationException ex) { assertEquals("this query must be rewritten first", ex.getMessage()); } - assertEquals(new MatchAllQueryBuilder(), builder.rewrite(queryShardContext())); + assertEquals(new MatchAllQueryBuilder(), builder.rewrite(createShardContext())); } public void testRewriteWithInnerName() throws IOException { final String query = "{ \"match_all\" : {\"_name\" : \"foobar\"}}"; QueryBuilder builder = new TemplateQueryBuilder(new Template(query, ScriptType.INLINE, "mockscript", XContentType.JSON, Collections.emptyMap())); - assertEquals(new MatchAllQueryBuilder().queryName("foobar"), builder.rewrite(queryShardContext())); + assertEquals(new MatchAllQueryBuilder().queryName("foobar"), builder.rewrite(createShardContext())); builder = new TemplateQueryBuilder(new Template(query, ScriptType.INLINE, "mockscript", XContentType.JSON, Collections.emptyMap())).queryName("outer"); assertEquals(new BoolQueryBuilder().must(new MatchAllQueryBuilder().queryName("foobar")).queryName("outer"), - builder.rewrite(queryShardContext())); + builder.rewrite(createShardContext())); } public void testRewriteWithInnerBoost() throws IOException { final TermQueryBuilder query = new TermQueryBuilder("foo", "bar").boost(2); QueryBuilder builder = new TemplateQueryBuilder(new Template(query.toString(), ScriptType.INLINE, "mockscript", XContentType.JSON, Collections.emptyMap())); - assertEquals(query, builder.rewrite(queryShardContext())); + assertEquals(query, builder.rewrite(createShardContext())); builder = new TemplateQueryBuilder(new Template(query.toString(), ScriptType.INLINE, "mockscript", XContentType.JSON, Collections.emptyMap())).boost(3); - assertEquals(new BoolQueryBuilder().must(query).boost(3), builder.rewrite(queryShardContext())); + assertEquals(new BoolQueryBuilder().must(query).boost(3), builder.rewrite(createShardContext())); } @Override diff --git a/core/src/test/java/org/elasticsearch/index/query/TermsQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/TermsQueryBuilderTests.java index fb571dd63fd..108714e4981 100644 --- a/core/src/test/java/org/elasticsearch/index/query/TermsQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/TermsQueryBuilderTests.java @@ -295,12 +295,12 @@ public class TermsQueryBuilderTests extends AbstractQueryTestCase x != null).collect(Collectors.toList()))); // terms lookup removes null values } } diff --git a/core/src/test/java/org/elasticsearch/index/query/TypeQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/TypeQueryBuilderTests.java index ce8377439fc..db9a4d8e7cd 100644 --- a/core/src/test/java/org/elasticsearch/index/query/TypeQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/TypeQueryBuilderTests.java @@ -35,7 +35,7 @@ public class TypeQueryBuilderTests extends AbstractQueryTestCase innerQuery = queryBuilder.rewrite(queryShardContext()); + QueryBuilder innerQuery = queryBuilder.rewrite(createShardContext()); Query expected = rewrite(innerQuery.toQuery(context)); assertEquals(rewrite(query), expected); } @@ -133,29 +133,31 @@ public class WrapperQueryBuilderTests extends AbstractQueryTestCase rewrite = qb.rewrite(queryShardContext()); + QueryBuilder rewrite = qb.rewrite(createShardContext()); assertEquals(tqb, rewrite); } public void testRewriteWithInnerName() throws IOException { QueryBuilder builder = new WrapperQueryBuilder("{ \"match_all\" : {\"_name\" : \"foobar\"}}"); - assertEquals(new MatchAllQueryBuilder().queryName("foobar"), builder.rewrite(queryShardContext())); + QueryShardContext shardContext = createShardContext(); + assertEquals(new MatchAllQueryBuilder().queryName("foobar"), builder.rewrite(shardContext)); builder = new WrapperQueryBuilder("{ \"match_all\" : {\"_name\" : \"foobar\"}}").queryName("outer"); assertEquals(new BoolQueryBuilder().must(new MatchAllQueryBuilder().queryName("foobar")).queryName("outer"), - builder.rewrite(queryShardContext())); + builder.rewrite(shardContext)); } public void testRewriteWithInnerBoost() throws IOException { final TermQueryBuilder query = new TermQueryBuilder("foo", "bar").boost(2); QueryBuilder builder = new WrapperQueryBuilder(query.toString()); - assertEquals(query, builder.rewrite(queryShardContext())); + QueryShardContext shardContext = createShardContext(); + assertEquals(query, builder.rewrite(shardContext)); builder = new WrapperQueryBuilder(query.toString()).boost(3); - assertEquals(new BoolQueryBuilder().must(query).boost(3), builder.rewrite(queryShardContext())); + assertEquals(new BoolQueryBuilder().must(query).boost(3), builder.rewrite(shardContext)); } @Override diff --git a/core/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilderTests.java index ed5ee94c8ef..31b1b4ecd11 100644 --- a/core/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilderTests.java @@ -613,7 +613,7 @@ public class FunctionScoreQueryBuilderTests extends AbstractQueryTestCase Date: Fri, 15 Apr 2016 11:08:32 -0400 Subject: [PATCH 024/561] Cut geo aggregations to registerAggregation and remove their prototypes. Relates to #17085 --- .../elasticsearch/search/SearchModule.java | 14 +++- .../geogrid/GeoGridAggregatorBuilder.java | 71 ++++++++++-------- .../bucket/geogrid/GeoHashGridParser.java | 9 --- .../GeoDistanceAggregatorBuilder.java | 74 ++++++++++--------- .../range/geodistance/GeoDistanceParser.java | 11 --- .../geobounds/GeoBoundsAggregatorBuilder.java | 43 +++++++---- .../metrics/geobounds/GeoBoundsParser.java | 11 --- .../GeoCentroidAggregatorBuilder.java | 42 +++++++---- .../geocentroid/GeoCentroidParser.java | 10 --- 9 files changed, 144 insertions(+), 141 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index a597c9bf1b6..044e2c18d61 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -107,6 +107,7 @@ import org.elasticsearch.search.aggregations.bucket.filter.FilterAggregatorBuild import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter; import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.filters.InternalFilters; +import org.elasticsearch.search.aggregations.bucket.geogrid.GeoGridAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGridParser; import org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGrid; import org.elasticsearch.search.aggregations.bucket.global.GlobalParser; @@ -128,6 +129,7 @@ import org.elasticsearch.search.aggregations.bucket.range.RangeParser; import org.elasticsearch.search.aggregations.bucket.range.date.DateRangeAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.range.date.DateRangeParser; import org.elasticsearch.search.aggregations.bucket.range.date.InternalDateRange; +import org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceParser; import org.elasticsearch.search.aggregations.bucket.range.geodistance.InternalGeoDistance; import org.elasticsearch.search.aggregations.bucket.range.ipv4.IPv4RangeAggregatorBuilder; @@ -155,8 +157,10 @@ import org.elasticsearch.search.aggregations.metrics.avg.AvgParser; import org.elasticsearch.search.aggregations.metrics.avg.InternalAvg; import org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityParser; import org.elasticsearch.search.aggregations.metrics.cardinality.InternalCardinality; +import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsParser; import org.elasticsearch.search.aggregations.metrics.geobounds.InternalGeoBounds; +import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidParser; import org.elasticsearch.search.aggregations.metrics.geocentroid.InternalGeoCentroid; import org.elasticsearch.search.aggregations.metrics.max.InternalMax; @@ -472,14 +476,16 @@ public class SearchModule extends AbstractModule { registerAggregation(HistogramAggregatorBuilder::new, new HistogramParser(), HistogramAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(DateHistogramAggregatorBuilder::new, new DateHistogramParser(), DateHistogramAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerAggregatorParser(new GeoDistanceParser()); - registerAggregatorParser(new GeoHashGridParser()); + registerAggregation(GeoDistanceAggregatorBuilder::new, new GeoDistanceParser(), + GeoDistanceAggregatorBuilder.AGGREGATION_NAME_FIELD); + registerAggregation(GeoGridAggregatorBuilder::new, new GeoHashGridParser(), GeoGridAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(NestedAggregatorBuilder::new, NestedAggregatorBuilder::parse, NestedAggregatorBuilder.AGGREGATION_FIELD_NAME); registerAggregation(ReverseNestedAggregatorBuilder::new, ReverseNestedAggregatorBuilder::parse, ReverseNestedAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregatorParser(new TopHitsParser()); - registerAggregatorParser(new GeoBoundsParser()); - registerAggregatorParser(new GeoCentroidParser()); + registerAggregation(GeoBoundsAggregatorBuilder::new, new GeoBoundsParser(), GeoBoundsAggregatorBuilder.AGGREGATION_NAME_FIED); + registerAggregation(GeoCentroidAggregatorBuilder::new, new GeoCentroidParser(), + GeoCentroidAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(ScriptedMetricAggregatorBuilder::new, ScriptedMetricAggregatorBuilder::parse, ScriptedMetricAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(ChildrenAggregatorBuilder::new, ChildrenAggregatorBuilder::parse, diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorBuilder.java index e99887c6e08..621fbbfb833 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/geogrid/GeoGridAggregatorBuilder.java @@ -21,6 +21,7 @@ package org.elasticsearch.search.aggregations.bucket.geogrid; import org.apache.lucene.index.LeafReaderContext; import org.apache.lucene.index.SortedNumericDocValues; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.geo.GeoHashUtils; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.io.stream.StreamInput; @@ -45,8 +46,8 @@ import java.io.IOException; import java.util.Objects; public class GeoGridAggregatorBuilder extends ValuesSourceAggregatorBuilder { - - static final GeoGridAggregatorBuilder PROTOTYPE = new GeoGridAggregatorBuilder(""); + public static final String NAME = InternalGeoHashGrid.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); private int precision = GeoHashGridParser.DEFAULT_PRECISION; private int requiredSize = GeoHashGridParser.DEFAULT_MAX_NUM_CELLS; @@ -56,6 +57,28 @@ public class GeoGridAggregatorBuilder extends ValuesSourceAggregatorBuilder config, AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { int shardSize = this.shardSize; - if (shardSize == 0) { - shardSize = Integer.MAX_VALUE; - } + if (shardSize == 0) { + shardSize = Integer.MAX_VALUE; + } int requiredSize = this.requiredSize; - if (requiredSize == 0) { - requiredSize = Integer.MAX_VALUE; - } + if (requiredSize == 0) { + requiredSize = Integer.MAX_VALUE; + } - if (shardSize < 0) { + if (shardSize < 0) { // Use default heuristic to avoid any wrong-ranking caused by distributed counting shardSize = BucketUtils.suggestShardSideQueueSize(requiredSize, context.searchContext().numberOfShards()); - } + } - if (shardSize < requiredSize) { - shardSize = requiredSize; - } + if (shardSize < requiredSize) { + shardSize = requiredSize; + } return new GeoHashGridAggregatorFactory(name, type, config, precision, requiredSize, shardSize, context, parent, subFactoriesBuilder, metaData); } - @Override - protected GeoGridAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, ValueType targetValueType, - StreamInput in) throws IOException { - GeoGridAggregatorBuilder factory = new GeoGridAggregatorBuilder(name); - factory.precision = in.readVInt(); - factory.requiredSize = in.readVInt(); - factory.shardSize = in.readVInt(); - return factory; - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - out.writeVInt(precision); - out.writeVInt(requiredSize); - out.writeVInt(shardSize); - } - @Override protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { builder.field(GeoHashGridParams.FIELD_PRECISION.getPreferredName(), precision); @@ -162,6 +168,11 @@ public class GeoGridAggregatorBuilder extends ValuesSourceAggregatorBuilder { - - static final GeoDistanceAggregatorBuilder PROTOTYPE = new GeoDistanceAggregatorBuilder("", new GeoPoint()); + public static final String NAME = InternalGeoDistance.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); private final GeoPoint origin; private List ranges = new ArrayList<>(); @@ -66,6 +65,41 @@ public class GeoDistanceAggregatorBuilder extends ValuesSourceAggregatorBuilder< this.origin = origin; } + /** + * Read from a stream. + */ + public GeoDistanceAggregatorBuilder(StreamInput in) throws IOException { + super(in, InternalGeoDistance.FACTORY.type(), InternalGeoDistance.FACTORY.getValueSourceType(), + InternalGeoDistance.FACTORY.getValueType()); + origin = new GeoPoint(in.readDouble(), in.readDouble()); + int size = in.readVInt(); + ranges = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + ranges.add(Range.PROTOTYPE.readFrom(in)); + } + keyed = in.readBoolean(); + distanceType = GeoDistance.readFromStream(in); + unit = DistanceUnit.readFromStream(in); + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + out.writeDouble(origin.lat()); + out.writeDouble(origin.lon()); + out.writeVInt(ranges.size()); + for (Range range : ranges) { + range.writeTo(out); + } + out.writeBoolean(keyed); + distanceType.writeTo(out); + unit.writeTo(out); + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; + } + public GeoDistanceAggregatorBuilder addRange(Range range) { if (range == null) { throw new IllegalArgumentException("[range] must not be null: [" + name + "]"); @@ -146,7 +180,7 @@ public class GeoDistanceAggregatorBuilder extends ValuesSourceAggregatorBuilder< @Override public String getWriteableName() { - return InternalGeoDistance.TYPE.name(); + return NAME; } public GeoDistanceAggregatorBuilder unit(DistanceUnit unit) { @@ -200,34 +234,6 @@ public class GeoDistanceAggregatorBuilder extends ValuesSourceAggregatorBuilder< return builder; } - @Override - protected GeoDistanceAggregatorBuilder innerReadFrom( - String name, ValuesSourceType valuesSourceType, ValueType targetValueType, StreamInput in) throws IOException { - GeoPoint origin = new GeoPoint(in.readDouble(), in.readDouble()); - int size = in.readVInt(); - GeoDistanceAggregatorBuilder factory = new GeoDistanceAggregatorBuilder(name, origin); - for (int i = 0; i < size; i++) { - factory.addRange(Range.PROTOTYPE.readFrom(in)); - } - factory.keyed = in.readBoolean(); - factory.distanceType = GeoDistance.readFromStream(in); - factory.unit = DistanceUnit.readFromStream(in); - return factory; - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - out.writeDouble(origin.lat()); - out.writeDouble(origin.lon()); - out.writeVInt(ranges.size()); - for (Range range : ranges) { - range.writeTo(out); - } - out.writeBoolean(keyed); - distanceType.writeTo(out); - unit.writeTo(out); - } - @Override protected int innerHashCode() { return Objects.hash(origin, ranges, keyed, distanceType, unit); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/geodistance/GeoDistanceParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/geodistance/GeoDistanceParser.java index 670e4dda0d6..bc4353d18b4 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/geodistance/GeoDistanceParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/range/geodistance/GeoDistanceParser.java @@ -53,11 +53,6 @@ public class GeoDistanceParser extends GeoPointValuesSourceParser { super(true, false); } - @Override - public String type() { - return InternalGeoDistance.TYPE.name(); - } - public static class Range extends RangeAggregator.Range { static final Range PROTOTYPE = new Range(null, null, null); @@ -181,10 +176,4 @@ public class GeoDistanceParser extends GeoPointValuesSourceParser { } return false; } - - @Override - public GeoDistanceAggregatorBuilder getFactoryPrototypes() { - return GeoDistanceAggregatorBuilder.PROTOTYPE; - } - } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsAggregatorBuilder.java index 511f295af0c..a3ee2f43356 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geobounds/GeoBoundsAggregatorBuilder.java @@ -19,23 +19,25 @@ package org.elasticsearch.search.aggregations.metrics.geobounds; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceType; + import java.io.IOException; import java.util.Objects; public class GeoBoundsAggregatorBuilder extends ValuesSourceAggregatorBuilder { - - static final GeoBoundsAggregatorBuilder PROTOTYPE = new GeoBoundsAggregatorBuilder(""); + public static final String NAME = InternalGeoBounds.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIED = new ParseField(NAME); private boolean wrapLongitude = true; @@ -43,6 +45,24 @@ public class GeoBoundsAggregatorBuilder extends ValuesSourceAggregatorBuilder otherOptions) { @@ -63,10 +58,4 @@ public class GeoBoundsParser extends GeoPointValuesSourceParser { } return false; } - - @Override - public GeoBoundsAggregatorBuilder getFactoryPrototypes() { - return GeoBoundsAggregatorBuilder.PROTOTYPE; - } - } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidAggregatorBuilder.java index 634f1228fb4..82e924447e9 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidAggregatorBuilder.java @@ -19,48 +19,53 @@ package org.elasticsearch.search.aggregations.metrics.geocentroid; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.ToXContent.Params; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.support.AggregationContext; import org.elasticsearch.search.aggregations.support.ValueType; import org.elasticsearch.search.aggregations.support.ValuesSource; import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceType; -import org.elasticsearch.search.aggregations.support.ValuesSource.GeoPoint; import java.io.IOException; public class GeoCentroidAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly { - - static final GeoCentroidAggregatorBuilder PROTOTYPE = new GeoCentroidAggregatorBuilder(""); + public static final String NAME = InternalGeoCentroid.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); public GeoCentroidAggregatorBuilder(String name) { super(name, InternalGeoCentroid.TYPE, ValuesSourceType.GEOPOINT, ValueType.GEOPOINT); } + /** + * Read from a stream. + */ + public GeoCentroidAggregatorBuilder(StreamInput in) throws IOException { + super(in, InternalGeoCentroid.TYPE, ValuesSourceType.GEOPOINT, ValueType.GEOPOINT); + } + + @Override + protected void innerWriteTo(StreamOutput out) { + // Do nothing, no extra state to write to stream + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; + } + @Override protected GeoCentroidAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException { return new GeoCentroidAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData); } - @Override - protected GeoCentroidAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) throws IOException { - return new GeoCentroidAggregatorBuilder(name); - } - - @Override - protected void innerWriteTo(StreamOutput out) { - // Do nothing, no extra state to write to stream - } - @Override public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException { return builder; @@ -75,4 +80,9 @@ public class GeoCentroidAggregatorBuilder protected boolean innerEquals(Object obj) { return true; } + + @Override + public String getWriteableName() { + return NAME; + } } \ No newline at end of file diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidParser.java index d520b263012..b056920b141 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/GeoCentroidParser.java @@ -39,11 +39,6 @@ public class GeoCentroidParser extends GeoPointValuesSourceParser { super(true, false); } - @Override - public String type() { - return InternalGeoCentroid.TYPE.name(); - } - @Override protected boolean token(String aggregationName, String currentFieldName, Token token, XContentParser parser, ParseFieldMatcher parseFieldMatcher, Map otherOptions) throws IOException { @@ -55,9 +50,4 @@ public class GeoCentroidParser extends GeoPointValuesSourceParser { ValueType targetValueType, Map otherOptions) { return new GeoCentroidAggregatorBuilder(aggregationName); } - - @Override - public GeoCentroidAggregatorBuilder getFactoryPrototypes() { - return GeoCentroidAggregatorBuilder.PROTOTYPE; - } } From d223090d7d27464e9a0d43b4f57307713b96083c Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Fri, 15 Apr 2016 11:15:36 -0400 Subject: [PATCH 025/561] Cut top_hits aggregation to registerAggregation and remove its PROTOTYPE. Relates to #17085 --- .../elasticsearch/search/SearchModule.java | 5 +- .../tophits/TopHitsAggregatorBuilder.java | 307 +++++++++++++----- .../metrics/tophits/TopHitsParser.java | 178 ---------- 3 files changed, 225 insertions(+), 265 deletions(-) delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsParser.java diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index 044e2c18d61..f6497d3450d 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -182,7 +182,7 @@ import org.elasticsearch.search.aggregations.metrics.stats.extended.InternalExte import org.elasticsearch.search.aggregations.metrics.sum.InternalSum; import org.elasticsearch.search.aggregations.metrics.sum.SumParser; import org.elasticsearch.search.aggregations.metrics.tophits.InternalTopHits; -import org.elasticsearch.search.aggregations.metrics.tophits.TopHitsParser; +import org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregatorBuilder; import org.elasticsearch.search.aggregations.metrics.valuecount.InternalValueCount; import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountParser; import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue; @@ -482,7 +482,8 @@ public class SearchModule extends AbstractModule { registerAggregation(NestedAggregatorBuilder::new, NestedAggregatorBuilder::parse, NestedAggregatorBuilder.AGGREGATION_FIELD_NAME); registerAggregation(ReverseNestedAggregatorBuilder::new, ReverseNestedAggregatorBuilder::parse, ReverseNestedAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerAggregatorParser(new TopHitsParser()); + registerAggregation(TopHitsAggregatorBuilder::new, TopHitsAggregatorBuilder::parse, + TopHitsAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(GeoBoundsAggregatorBuilder::new, new GeoBoundsParser(), GeoBoundsAggregatorBuilder.AGGREGATION_NAME_FIED); registerAggregation(GeoCentroidAggregatorBuilder::new, new GeoCentroidParser(), GeoCentroidAggregatorBuilder.AGGREGATION_NAME_FIELD); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregatorBuilder.java index a0ea3c4f010..932303baa34 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/tophits/TopHitsAggregatorBuilder.java @@ -20,10 +20,14 @@ package org.elasticsearch.search.aggregations.metrics.tophits; import org.elasticsearch.common.Nullable; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.ParsingException; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.script.Script; import org.elasticsearch.search.aggregations.AggregationInitializationException; import org.elasticsearch.search.aggregations.AggregatorBuilder; @@ -48,8 +52,8 @@ import java.util.Objects; import java.util.Set; public class TopHitsAggregatorBuilder extends AggregatorBuilder { - - static final TopHitsAggregatorBuilder PROTOTYPE = new TopHitsAggregatorBuilder(""); + public static final String NAME = InternalTopHits.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); private int from = 0; private int size = 3; @@ -67,6 +71,96 @@ public class TopHitsAggregatorBuilder extends AggregatorBuilder(size); + for (int i = 0; i < size; i++) { + fieldDataFields.add(in.readString()); + } + } + if (in.readBoolean()) { + int size = in.readVInt(); + fieldNames = new ArrayList<>(size); + for (int i = 0; i < size; i++) { + fieldNames.add(in.readString()); + } + } + from = in.readVInt(); + highlightBuilder = in.readOptionalWriteable(HighlightBuilder::new); + if (in.readBoolean()) { + int size = in.readVInt(); + scriptFields = new HashSet<>(size); + for (int i = 0; i < size; i++) { + scriptFields.add(new ScriptField(in)); + } + } + size = in.readVInt(); + if (in.readBoolean()) { + int size = in.readVInt(); + sorts = new ArrayList<>(); + for (int i = 0; i < size; i++) { + sorts.add(in.readSortBuilder()); + } + } + trackScores = in.readBoolean(); + version = in.readBoolean(); + } + + @Override + protected void doWriteTo(StreamOutput out) throws IOException { + out.writeBoolean(explain); + out.writeOptionalStreamable(fetchSourceContext); + boolean hasFieldDataFields = fieldDataFields != null; + out.writeBoolean(hasFieldDataFields); + if (hasFieldDataFields) { + out.writeVInt(fieldDataFields.size()); + for (String fieldName : fieldDataFields) { + out.writeString(fieldName); + } + } + boolean hasFieldNames = fieldNames != null; + out.writeBoolean(hasFieldNames); + if (hasFieldNames) { + out.writeVInt(fieldNames.size()); + for (String fieldName : fieldNames) { + out.writeString(fieldName); + } + } + out.writeVInt(from); + out.writeOptionalWriteable(highlightBuilder); + boolean hasScriptFields = scriptFields != null; + out.writeBoolean(hasScriptFields); + if (hasScriptFields) { + out.writeVInt(scriptFields.size()); + for (ScriptField scriptField : scriptFields) { + scriptField.writeTo(out); + } + } + out.writeVInt(size); + boolean hasSorts = sorts != null; + out.writeBoolean(hasSorts); + if (hasSorts) { + out.writeVInt(sorts.size()); + for (SortBuilder sort : sorts) { + out.writeSortBuilder(sort); + } + } + out.writeBoolean(trackScores); + out.writeBoolean(version); + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; + } + /** * From index to start the search from. Defaults to 0. */ @@ -518,92 +612,130 @@ public class TopHitsAggregatorBuilder extends AggregatorBuilder fieldDataFields = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - fieldDataFields.add(in.readString()); - } - factory.fieldDataFields = fieldDataFields; - } - if (in.readBoolean()) { - int size = in.readVInt(); - List fieldNames = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - fieldNames.add(in.readString()); - } - factory.fieldNames = fieldNames; - } - factory.from = in.readVInt(); - factory.highlightBuilder = in.readOptionalWriteable(HighlightBuilder::new); - if (in.readBoolean()) { - int size = in.readVInt(); - Set scriptFields = new HashSet<>(size); - for (int i = 0; i < size; i++) { - scriptFields.add(new ScriptField(in)); - } - factory.scriptFields = scriptFields; - } - factory.size = in.readVInt(); - if (in.readBoolean()) { - int size = in.readVInt(); - List> sorts = new ArrayList<>(); - for (int i = 0; i < size; i++) { - sorts.add(in.readSortBuilder()); - } - factory.sorts = sorts; - } - factory.trackScores = in.readBoolean(); - factory.version = in.readBoolean(); - return factory; - } + public static TopHitsAggregatorBuilder parse(String aggregationName, QueryParseContext context) throws IOException { + TopHitsAggregatorBuilder factory = new TopHitsAggregatorBuilder(aggregationName); + XContentParser.Token token; + String currentFieldName = null; + XContentParser parser = context.parser(); + while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { + if (token == XContentParser.Token.FIELD_NAME) { + currentFieldName = parser.currentName(); + } else if (token.isValue()) { + if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FROM_FIELD)) { + factory.from(parser.intValue()); + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SIZE_FIELD)) { + factory.size(parser.intValue()); + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.VERSION_FIELD)) { + factory.version(parser.booleanValue()); + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.EXPLAIN_FIELD)) { + factory.explain(parser.booleanValue()); + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.TRACK_SCORES_FIELD)) { + factory.trackScores(parser.booleanValue()); + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) { + factory.fetchSource(FetchSourceContext.parse(context)); + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FIELDS_FIELD)) { + List fieldNames = new ArrayList<>(); + fieldNames.add(parser.text()); + factory.fields(fieldNames); + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { + factory.sort(parser.text()); + } else { + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", + parser.getTokenLocation()); + } + } else if (token == XContentParser.Token.START_OBJECT) { + if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) { + factory.fetchSource(FetchSourceContext.parse(context)); + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELDS_FIELD)) { + List scriptFields = new ArrayList<>(); + while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { + String scriptFieldName = parser.currentName(); + token = parser.nextToken(); + if (token == XContentParser.Token.START_OBJECT) { + Script script = null; + boolean ignoreFailure = false; + while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { + if (token == XContentParser.Token.FIELD_NAME) { + currentFieldName = parser.currentName(); + } else if (token.isValue()) { + if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELD)) { + script = Script.parse(parser, context.getParseFieldMatcher()); + } else if (context.getParseFieldMatcher().match(currentFieldName, + SearchSourceBuilder.IGNORE_FAILURE_FIELD)) { + ignoreFailure = parser.booleanValue(); + } else { + throw new ParsingException(parser.getTokenLocation(), + "Unknown key for a " + token + " in [" + currentFieldName + "].", + parser.getTokenLocation()); + } + } else if (token == XContentParser.Token.START_OBJECT) { + if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELD)) { + script = Script.parse(parser, context.getParseFieldMatcher()); + } else { + throw new ParsingException(parser.getTokenLocation(), + "Unknown key for a " + token + " in [" + currentFieldName + "].", + parser.getTokenLocation()); + } + } else { + throw new ParsingException(parser.getTokenLocation(), + "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); + } + } + scriptFields.add(new ScriptField(scriptFieldName, script, ignoreFailure)); + } else { + throw new ParsingException(parser.getTokenLocation(), "Expected [" + XContentParser.Token.START_OBJECT + + "] in [" + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); + } + } + factory.scriptFields(scriptFields); + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.HIGHLIGHT_FIELD)) { + factory.highlighter(HighlightBuilder.fromXContent(context)); + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { + List> sorts = SortBuilder.fromXContent(context); + factory.sorts(sorts); + } else { + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", + parser.getTokenLocation()); + } + } else if (token == XContentParser.Token.START_ARRAY) { - @Override - protected void doWriteTo(StreamOutput out) throws IOException { - out.writeBoolean(explain); - out.writeOptionalStreamable(fetchSourceContext); - boolean hasFieldDataFields = fieldDataFields != null; - out.writeBoolean(hasFieldDataFields); - if (hasFieldDataFields) { - out.writeVInt(fieldDataFields.size()); - for (String fieldName : fieldDataFields) { - out.writeString(fieldName); + if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FIELDS_FIELD)) { + List fieldNames = new ArrayList<>(); + while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { + if (token == XContentParser.Token.VALUE_STRING) { + fieldNames.add(parser.text()); + } else { + throw new ParsingException(parser.getTokenLocation(), "Expected [" + XContentParser.Token.VALUE_STRING + + "] in [" + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); + } + } + factory.fields(fieldNames); + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FIELDDATA_FIELDS_FIELD)) { + List fieldDataFields = new ArrayList<>(); + while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { + if (token == XContentParser.Token.VALUE_STRING) { + fieldDataFields.add(parser.text()); + } else { + throw new ParsingException(parser.getTokenLocation(), "Expected [" + XContentParser.Token.VALUE_STRING + + "] in [" + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); + } + } + factory.fieldDataFields(fieldDataFields); + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { + List> sorts = SortBuilder.fromXContent(context); + factory.sorts(sorts); + } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) { + factory.fetchSource(FetchSourceContext.parse(context)); + } else { + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", + parser.getTokenLocation()); + } + } else { + throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", + parser.getTokenLocation()); } } - boolean hasFieldNames = fieldNames != null; - out.writeBoolean(hasFieldNames); - if (hasFieldNames) { - out.writeVInt(fieldNames.size()); - for (String fieldName : fieldNames) { - out.writeString(fieldName); - } - } - out.writeVInt(from); - out.writeOptionalWriteable(highlightBuilder); - boolean hasScriptFields = scriptFields != null; - out.writeBoolean(hasScriptFields); - if (hasScriptFields) { - out.writeVInt(scriptFields.size()); - for (ScriptField scriptField : scriptFields) { - scriptField.writeTo(out); - } - } - out.writeVInt(size); - boolean hasSorts = sorts != null; - out.writeBoolean(hasSorts); - if (hasSorts) { - out.writeVInt(sorts.size()); - for (SortBuilder sort : sorts) { - out.writeSortBuilder(sort); - } - } - out.writeBoolean(trackScores); - out.writeBoolean(version); + return factory; } @Override @@ -627,4 +759,9 @@ public class TopHitsAggregatorBuilder extends AggregatorBuilder fieldNames = new ArrayList<>(); - fieldNames.add(parser.text()); - factory.fields(fieldNames); - } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { - factory.sort(parser.text()); - } else { - throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", - parser.getTokenLocation()); - } - } else if (token == XContentParser.Token.START_OBJECT) { - if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) { - factory.fetchSource(FetchSourceContext.parse(context)); - } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELDS_FIELD)) { - List scriptFields = new ArrayList<>(); - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - String scriptFieldName = parser.currentName(); - token = parser.nextToken(); - if (token == XContentParser.Token.START_OBJECT) { - Script script = null; - boolean ignoreFailure = false; - while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) { - if (token == XContentParser.Token.FIELD_NAME) { - currentFieldName = parser.currentName(); - } else if (token.isValue()) { - if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELD)) { - script = Script.parse(parser, context.getParseFieldMatcher()); - } else if (context.getParseFieldMatcher().match(currentFieldName, - SearchSourceBuilder.IGNORE_FAILURE_FIELD)) { - ignoreFailure = parser.booleanValue(); - } else { - throw new ParsingException(parser.getTokenLocation(), - "Unknown key for a " + token + " in [" + currentFieldName + "].", - parser.getTokenLocation()); - } - } else if (token == XContentParser.Token.START_OBJECT) { - if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SCRIPT_FIELD)) { - script = Script.parse(parser, context.getParseFieldMatcher()); - } else { - throw new ParsingException(parser.getTokenLocation(), - "Unknown key for a " + token + " in [" + currentFieldName + "].", - parser.getTokenLocation()); - } - } else { - throw new ParsingException(parser.getTokenLocation(), - "Unknown key for a " + token + " in [" + currentFieldName + "].", parser.getTokenLocation()); - } - } - scriptFields.add(new ScriptField(scriptFieldName, script, ignoreFailure)); - } else { - throw new ParsingException(parser.getTokenLocation(), "Expected [" + XContentParser.Token.START_OBJECT - + "] in [" + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); - } - } - factory.scriptFields(scriptFields); - } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.HIGHLIGHT_FIELD)) { - factory.highlighter(HighlightBuilder.fromXContent(context)); - } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { - List> sorts = SortBuilder.fromXContent(context); - factory.sorts(sorts); - } else { - throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", - parser.getTokenLocation()); - } - } else if (token == XContentParser.Token.START_ARRAY) { - - if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FIELDS_FIELD)) { - List fieldNames = new ArrayList<>(); - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - if (token == XContentParser.Token.VALUE_STRING) { - fieldNames.add(parser.text()); - } else { - throw new ParsingException(parser.getTokenLocation(), "Expected [" + XContentParser.Token.VALUE_STRING - + "] in [" + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); - } - } - factory.fields(fieldNames); - } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.FIELDDATA_FIELDS_FIELD)) { - List fieldDataFields = new ArrayList<>(); - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - if (token == XContentParser.Token.VALUE_STRING) { - fieldDataFields.add(parser.text()); - } else { - throw new ParsingException(parser.getTokenLocation(), "Expected [" + XContentParser.Token.VALUE_STRING - + "] in [" + currentFieldName + "] but found [" + token + "]", parser.getTokenLocation()); - } - } - factory.fieldDataFields(fieldDataFields); - } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder.SORT_FIELD)) { - List> sorts = SortBuilder.fromXContent(context); - factory.sorts(sorts); - } else if (context.getParseFieldMatcher().match(currentFieldName, SearchSourceBuilder._SOURCE_FIELD)) { - factory.fetchSource(FetchSourceContext.parse(context)); - } else { - throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", - parser.getTokenLocation()); - } - } else { - throw new ParsingException(parser.getTokenLocation(), "Unknown key for a " + token + " in [" + currentFieldName + "].", - parser.getTokenLocation()); - } - } - return factory; - } - - @Override - public TopHitsAggregatorBuilder getFactoryPrototypes() { - return TopHitsAggregatorBuilder.PROTOTYPE; - } - -} From 65803f8abdf00817746518677efaec3abe9fbc45 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Fri, 15 Apr 2016 11:25:11 -0400 Subject: [PATCH 026/561] Cut significant_terms to registerAggregation and remove its PROTOTYPE. Relates to #17085 --- .../elasticsearch/search/SearchModule.java | 5 +- .../SignificantTermsAggregatorBuilder.java | 102 ++++++++++-------- .../significant/SignificantTermsParser.java | 10 -- 3 files changed, 60 insertions(+), 57 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java index f6497d3450d..06b09e6e744 100644 --- a/core/src/main/java/org/elasticsearch/search/SearchModule.java +++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java @@ -142,6 +142,7 @@ import org.elasticsearch.search.aggregations.bucket.sampler.SamplerAggregatorBui import org.elasticsearch.search.aggregations.bucket.sampler.UnmappedSampler; import org.elasticsearch.search.aggregations.bucket.significant.SignificantLongTerms; import org.elasticsearch.search.aggregations.bucket.significant.SignificantStringTerms; +import org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregatorBuilder; import org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsParser; import org.elasticsearch.search.aggregations.bucket.significant.UnmappedSignificantTerms; import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicParser; @@ -469,7 +470,9 @@ public class SearchModule extends AbstractModule { registerAggregation(DiversifiedAggregatorBuilder::new, new DiversifiedSamplerParser(), DiversifiedAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(TermsAggregatorBuilder::new, new TermsParser(), TermsAggregatorBuilder.AGGREGATION_NAME_FIELD); - registerAggregatorParser(new SignificantTermsParser(significanceHeuristicParserMapper, queryParserRegistry)); + registerAggregation(SignificantTermsAggregatorBuilder::new, + new SignificantTermsParser(significanceHeuristicParserMapper, queryParserRegistry), + SignificantTermsAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(RangeAggregatorBuilder::new, new RangeParser(), RangeAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(DateRangeAggregatorBuilder::new, new DateRangeParser(), DateRangeAggregatorBuilder.AGGREGATION_NAME_FIELD); registerAggregation(IPv4RangeAggregatorBuilder::new, new IpRangeParser(), IPv4RangeAggregatorBuilder.AGGREGATION_NAME_FIELD); diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregatorBuilder.java index f5a167cb943..4019cd21b05 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregatorBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsAggregatorBuilder.java @@ -21,12 +21,10 @@ package org.elasticsearch.search.aggregations.bucket.significant; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.lucene.index.FilterableTermsEnum; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.AggregatorFactories.Builder; +import org.elasticsearch.search.aggregations.AggregatorFactory; import org.elasticsearch.search.aggregations.bucket.significant.heuristics.JLHScore; import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristic; import org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristicStreams; @@ -41,6 +39,7 @@ import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuild import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory; import org.elasticsearch.search.aggregations.support.ValuesSourceConfig; import org.elasticsearch.search.aggregations.support.ValuesSourceType; + import java.io.IOException; import java.util.Objects; @@ -48,6 +47,8 @@ import java.util.Objects; * */ public class SignificantTermsAggregatorBuilder extends ValuesSourceAggregatorBuilder { + public static final String NAME = SignificantStringTerms.TYPE.name(); + public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME); static final ParseField BACKGROUND_FILTER = new ParseField("background_filter"); static final ParseField HEURISTIC = new ParseField("significance_heuristic"); @@ -55,26 +56,63 @@ public class SignificantTermsAggregatorBuilder extends ValuesSourceAggregatorBui static final TermsAggregator.BucketCountThresholds DEFAULT_BUCKET_COUNT_THRESHOLDS = new TermsAggregator.BucketCountThresholds( 3, 0, 10, -1); - static final SignificantTermsAggregatorBuilder PROTOTYPE = new SignificantTermsAggregatorBuilder("", null); - private IncludeExclude includeExclude = null; private String executionHint = null; - private String indexedFieldName; - private MappedFieldType fieldType; - private FilterableTermsEnum termsEnum; - private int numberOfAggregatorsCreated = 0; private QueryBuilder filterBuilder = null; private TermsAggregator.BucketCountThresholds bucketCountThresholds = new BucketCountThresholds(DEFAULT_BUCKET_COUNT_THRESHOLDS); private SignificanceHeuristic significanceHeuristic = JLHScore.PROTOTYPE; - protected TermsAggregator.BucketCountThresholds getBucketCountThresholds() { - return new TermsAggregator.BucketCountThresholds(bucketCountThresholds); - } - public SignificantTermsAggregatorBuilder(String name, ValueType valueType) { super(name, SignificantStringTerms.TYPE, ValuesSourceType.ANY, valueType); } + /** + * Read from a Stream. + */ + public SignificantTermsAggregatorBuilder(StreamInput in) throws IOException { + super(in, SignificantStringTerms.TYPE, ValuesSourceType.ANY); + bucketCountThresholds = BucketCountThresholds.readFromStream(in); + executionHint = in.readOptionalString(); + if (in.readBoolean()) { + filterBuilder = in.readQuery(); + } + if (in.readBoolean()) { + includeExclude = IncludeExclude.readFromStream(in); + } + significanceHeuristic = SignificanceHeuristicStreams.read(in); + } + + @Override + protected void innerWriteTo(StreamOutput out) throws IOException { + bucketCountThresholds.writeTo(out); + out.writeOptionalString(executionHint); + boolean hasfilterBuilder = filterBuilder != null; + out.writeBoolean(hasfilterBuilder); + if (hasfilterBuilder) { + out.writeQuery(filterBuilder); + } + boolean hasIncExc = includeExclude != null; + out.writeBoolean(hasIncExc); + if (hasIncExc) { + includeExclude.writeTo(out); + } + SignificanceHeuristicStreams.writeTo(significanceHeuristic, out); + } + + @Override + protected boolean usesNewStyleSerialization() { + return true; + } + + @Override + protected boolean serializeTargetValueType() { + return true; + } + + protected TermsAggregator.BucketCountThresholds getBucketCountThresholds() { + return new TermsAggregator.BucketCountThresholds(bucketCountThresholds); + } + public TermsAggregator.BucketCountThresholds bucketCountThresholds() { return bucketCountThresholds; } @@ -217,39 +255,6 @@ public class SignificantTermsAggregatorBuilder extends ValuesSourceAggregatorBui return builder; } - @Override - protected SignificantTermsAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType, - ValueType targetValueType, StreamInput in) throws IOException { - SignificantTermsAggregatorBuilder factory = new SignificantTermsAggregatorBuilder(name, targetValueType); - factory.bucketCountThresholds = BucketCountThresholds.readFromStream(in); - factory.executionHint = in.readOptionalString(); - if (in.readBoolean()) { - factory.filterBuilder = in.readQuery(); - } - if (in.readBoolean()) { - factory.includeExclude = IncludeExclude.readFromStream(in); - } - factory.significanceHeuristic = SignificanceHeuristicStreams.read(in); - return factory; - } - - @Override - protected void innerWriteTo(StreamOutput out) throws IOException { - bucketCountThresholds.writeTo(out); - out.writeOptionalString(executionHint); - boolean hasfilterBuilder = filterBuilder != null; - out.writeBoolean(hasfilterBuilder); - if (hasfilterBuilder) { - out.writeQuery(filterBuilder); - } - boolean hasIncExc = includeExclude != null; - out.writeBoolean(hasIncExc); - if (hasIncExc) { - includeExclude.writeTo(out); - } - SignificanceHeuristicStreams.writeTo(significanceHeuristic, out); - } - @Override protected int innerHashCode() { return Objects.hash(bucketCountThresholds, executionHint, filterBuilder, includeExclude, significanceHeuristic); @@ -264,4 +269,9 @@ public class SignificantTermsAggregatorBuilder extends ValuesSourceAggregatorBui && Objects.equals(includeExclude, other.includeExclude) && Objects.equals(significanceHeuristic, other.significanceHeuristic); } + + @Override + public String getWriteableName() { + return NAME; + } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsParser.java index 6f761ab752a..5d809f0338d 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsParser.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/significant/SignificantTermsParser.java @@ -52,11 +52,6 @@ public class SignificantTermsParser extends AbstractTermsParser { this.queriesRegistry = queriesRegistry; } - @Override - public String type() { - return SignificantStringTerms.TYPE.name(); - } - @Override protected SignificantTermsAggregatorBuilder doCreateFactory(String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, BucketCountThresholds bucketCountThresholds, SubAggCollectionMode collectMode, String executionHint, @@ -103,11 +98,6 @@ public class SignificantTermsParser extends AbstractTermsParser { return false; } - @Override - public SignificantTermsAggregatorBuilder getFactoryPrototypes() { - return SignificantTermsAggregatorBuilder.PROTOTYPE; - } - @Override protected BucketCountThresholds getDefaultBucketCountThresholds() { return new TermsAggregator.BucketCountThresholds(SignificantTermsAggregatorBuilder.DEFAULT_BUCKET_COUNT_THRESHOLDS); From f7e79f4981ddeb1d14e0aaa0417b3ed378d8e298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Fri, 15 Apr 2016 18:18:15 +0200 Subject: [PATCH 027/561] Pass down parse context instead of just parser in completion context suggester. --- .../completion/CompletionSuggestionBuilder.java | 5 ++--- .../context/CategoryContextMapping.java | 5 +++-- .../context/CategoryQueryContext.java | 4 +++- .../completion/context/ContextMapping.java | 10 ++++++---- .../completion/context/GeoContextMapping.java | 5 +++-- .../completion/context/GeoQueryContext.java | 7 ++++--- .../completion/CategoryContextMappingTests.java | 17 ++++++++++++----- .../completion/CategoryQueryContextTests.java | 6 +++--- .../completion/GeoContextMappingTests.java | 17 ++++++++++++----- .../completion/GeoQueryContextTests.java | 6 +++--- .../completion/QueryContextTestCase.java | 7 +++++-- 11 files changed, 56 insertions(+), 33 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java index 4afad501cba..ce75351dfb5 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java @@ -20,7 +20,6 @@ package org.elasticsearch.search.suggest.completion; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; @@ -265,7 +264,7 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder ParseFieldMatcher.STRICT); + TLP_PARSER.parse(parseContext.parser(), builder, parseContext); String field = builder.field; // now we should have field name, check and copy fields over to the suggestion builder we return if (field == null) { @@ -301,7 +300,7 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder } @Override - protected CategoryQueryContext fromXContent(XContentParser parser) throws IOException { - return CategoryQueryContext.fromXContent(parser); + protected CategoryQueryContext fromXContent(QueryParseContext context) throws IOException { + return CategoryQueryContext.fromXContent(context); } /** diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java index 1384868f0dc..a17b7a87b43 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/CategoryQueryContext.java @@ -27,6 +27,7 @@ import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.query.QueryParseContext; import java.io.IOException; import java.util.Objects; @@ -104,7 +105,8 @@ public final class CategoryQueryContext implements ToXContent { CATEGORY_PARSER.declareBoolean(Builder::setPrefix, new ParseField(CONTEXT_PREFIX)); } - public static CategoryQueryContext fromXContent(XContentParser parser) throws IOException { + public static CategoryQueryContext fromXContent(QueryParseContext context) throws IOException { + XContentParser parser = context.parser(); XContentParser.Token token = parser.currentToken(); Builder builder = builder(); if (token == XContentParser.Token.START_OBJECT) { diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMapping.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMapping.java index cb445b17706..305a3b1afd3 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMapping.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/ContextMapping.java @@ -27,6 +27,7 @@ import org.elasticsearch.common.xcontent.XContentParser.Token; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.mapper.ParseContext; import org.elasticsearch.index.mapper.core.CompletionFieldMapper; +import org.elasticsearch.index.query.QueryParseContext; import java.io.IOException; import java.util.ArrayList; @@ -99,19 +100,20 @@ public abstract class ContextMapping implements ToXContent /** * Prototype for the query context */ - protected abstract T fromXContent(XContentParser parser) throws IOException; + protected abstract T fromXContent(QueryParseContext context) throws IOException; /** * Parses query contexts for this mapper */ - public final List parseQueryContext(XContentParser parser) throws IOException, ElasticsearchParseException { + public final List parseQueryContext(QueryParseContext context) throws IOException, ElasticsearchParseException { List queryContexts = new ArrayList<>(); + XContentParser parser = context.parser(); Token token = parser.nextToken(); if (token == Token.START_OBJECT || token == Token.VALUE_STRING) { - queryContexts.add(fromXContent(parser)); + queryContexts.add(fromXContent(context)); } else if (token == Token.START_ARRAY) { while (parser.nextToken() != Token.END_ARRAY) { - queryContexts.add(fromXContent(parser)); + queryContexts.add(fromXContent(context)); } } return toInternalQueryContexts(queryContexts); diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoContextMapping.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoContextMapping.java index 83345be24b1..a9aa9d340ca 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoContextMapping.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoContextMapping.java @@ -33,6 +33,7 @@ import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.ParseContext; import org.elasticsearch.index.mapper.ParseContext.Document; import org.elasticsearch.index.mapper.geo.GeoPointFieldMapper; +import org.elasticsearch.index.query.QueryParseContext; import java.io.IOException; import java.util.ArrayList; @@ -223,8 +224,8 @@ public class GeoContextMapping extends ContextMapping { } @Override - protected GeoQueryContext fromXContent(XContentParser parser) throws IOException { - return GeoQueryContext.fromXContent(parser); + protected GeoQueryContext fromXContent(QueryParseContext context) throws IOException { + return GeoQueryContext.fromXContent(context); } /** diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java index dd625f252de..6ed8754c978 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/context/GeoQueryContext.java @@ -21,7 +21,6 @@ package org.elasticsearch.search.suggest.completion.context; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.geo.GeoUtils; @@ -29,6 +28,7 @@ import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.query.QueryParseContext; import java.io.IOException; import java.util.Collections; @@ -125,11 +125,12 @@ public final class GeoQueryContext implements ToXContent { GEO_CONTEXT_PARSER.declareDouble(GeoQueryContext.Builder::setLon, new ParseField("lon")); } - public static GeoQueryContext fromXContent(XContentParser parser) throws IOException { + public static GeoQueryContext fromXContent(QueryParseContext context) throws IOException { + XContentParser parser = context.parser(); XContentParser.Token token = parser.currentToken(); GeoQueryContext.Builder builder = new Builder(); if (token == XContentParser.Token.START_OBJECT) { - GEO_CONTEXT_PARSER.parse(parser, builder, () -> ParseFieldMatcher.STRICT); + GEO_CONTEXT_PARSER.parse(parser, builder, context); } else if (token == XContentParser.Token.VALUE_STRING) { builder.setGeoPoint(GeoPoint.fromGeohash(parser.text())); } else { diff --git a/core/src/test/java/org/elasticsearch/search/suggest/completion/CategoryContextMappingTests.java b/core/src/test/java/org/elasticsearch/search/suggest/completion/CategoryContextMappingTests.java index e0aabe77302..de912bb9636 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/completion/CategoryContextMappingTests.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/completion/CategoryContextMappingTests.java @@ -23,6 +23,7 @@ import org.apache.lucene.document.Field; import org.apache.lucene.document.StringField; import org.apache.lucene.index.IndexableField; import org.apache.lucene.search.suggest.document.ContextSuggestField; +import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.compress.CompressedXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; @@ -33,6 +34,8 @@ import org.elasticsearch.index.mapper.FieldMapper; import org.elasticsearch.index.mapper.MappedFieldType; import org.elasticsearch.index.mapper.ParseContext; import org.elasticsearch.index.mapper.ParsedDocument; +import org.elasticsearch.index.query.QueryParseContext; +import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.search.suggest.completion.context.CategoryContextMapping; import org.elasticsearch.search.suggest.completion.context.ContextBuilder; import org.elasticsearch.search.suggest.completion.context.ContextMapping; @@ -190,7 +193,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase { XContentBuilder builder = jsonBuilder().value("context1"); XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes()); CategoryContextMapping mapping = ContextBuilder.category("cat").build(); - List internalQueryContexts = mapping.parseQueryContext(parser); + List internalQueryContexts = mapping.parseQueryContext(createParseContext(parser)); assertThat(internalQueryContexts.size(), equalTo(1)); assertThat(internalQueryContexts.get(0).context, equalTo("context1")); assertThat(internalQueryContexts.get(0).boost, equalTo(1)); @@ -204,7 +207,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase { .endArray(); XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes()); CategoryContextMapping mapping = ContextBuilder.category("cat").build(); - List internalQueryContexts = mapping.parseQueryContext(parser); + List internalQueryContexts = mapping.parseQueryContext(createParseContext(parser)); assertThat(internalQueryContexts.size(), equalTo(2)); assertThat(internalQueryContexts.get(0).context, equalTo("context1")); assertThat(internalQueryContexts.get(0).boost, equalTo(1)); @@ -222,7 +225,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase { .endObject(); XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes()); CategoryContextMapping mapping = ContextBuilder.category("cat").build(); - List internalQueryContexts = mapping.parseQueryContext(parser); + List internalQueryContexts = mapping.parseQueryContext(createParseContext(parser)); assertThat(internalQueryContexts.size(), equalTo(1)); assertThat(internalQueryContexts.get(0).context, equalTo("context1")); assertThat(internalQueryContexts.get(0).boost, equalTo(10)); @@ -245,7 +248,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase { .endArray(); XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes()); CategoryContextMapping mapping = ContextBuilder.category("cat").build(); - List internalQueryContexts = mapping.parseQueryContext(parser); + List internalQueryContexts = mapping.parseQueryContext(createParseContext(parser)); assertThat(internalQueryContexts.size(), equalTo(2)); assertThat(internalQueryContexts.get(0).context, equalTo("context1")); assertThat(internalQueryContexts.get(0).boost, equalTo(2)); @@ -255,6 +258,10 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase { assertThat(internalQueryContexts.get(1).isPrefix, equalTo(false)); } + private static QueryParseContext createParseContext(XContentParser parser) { + return new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT); + } + public void testQueryContextParsingMixed() throws Exception { XContentBuilder builder = jsonBuilder().startArray() .startObject() @@ -266,7 +273,7 @@ public class CategoryContextMappingTests extends ESSingleNodeTestCase { .endArray(); XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes()); CategoryContextMapping mapping = ContextBuilder.category("cat").build(); - List internalQueryContexts = mapping.parseQueryContext(parser); + List internalQueryContexts = mapping.parseQueryContext(createParseContext(parser)); assertThat(internalQueryContexts.size(), equalTo(2)); assertThat(internalQueryContexts.get(0).context, equalTo("context1")); assertThat(internalQueryContexts.get(0).boost, equalTo(2)); diff --git a/core/src/test/java/org/elasticsearch/search/suggest/completion/CategoryQueryContextTests.java b/core/src/test/java/org/elasticsearch/search/suggest/completion/CategoryQueryContextTests.java index 0197340d1a8..59d7bbd61b9 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/completion/CategoryQueryContextTests.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/completion/CategoryQueryContextTests.java @@ -19,7 +19,7 @@ package org.elasticsearch.search.suggest.completion; -import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.suggest.completion.context.CategoryQueryContext; import java.io.IOException; @@ -40,8 +40,8 @@ public class CategoryQueryContextTests extends QueryContextTestCase internalQueryContexts = mapping.parseQueryContext(parser); + List internalQueryContexts = mapping.parseQueryContext(createParseContext(parser)); assertThat(internalQueryContexts.size(), equalTo(1 + 8)); Collection locations = new ArrayList<>(); locations.add("ezs42e"); @@ -221,7 +224,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase { .endObject(); XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes()); GeoContextMapping mapping = ContextBuilder.geo("geo").build(); - List internalQueryContexts = mapping.parseQueryContext(parser); + List internalQueryContexts = mapping.parseQueryContext(createParseContext(parser)); assertThat(internalQueryContexts.size(), equalTo(1 + 8)); Collection locations = new ArrayList<>(); locations.add("wh0n94"); @@ -244,7 +247,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase { .endObject(); XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes()); GeoContextMapping mapping = ContextBuilder.geo("geo").build(); - List internalQueryContexts = mapping.parseQueryContext(parser); + List internalQueryContexts = mapping.parseQueryContext(createParseContext(parser)); assertThat(internalQueryContexts.size(), equalTo(1 + 1 + 8 + 1 + 8 + 1 + 8)); Collection locations = new ArrayList<>(); locations.add("wh0n94"); @@ -282,7 +285,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase { .endArray(); XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes()); GeoContextMapping mapping = ContextBuilder.geo("geo").build(); - List internalQueryContexts = mapping.parseQueryContext(parser); + List internalQueryContexts = mapping.parseQueryContext(createParseContext(parser)); assertThat(internalQueryContexts.size(), equalTo(1 + 1 + 8 + 1 + 8 + 1 + 8 + 1 + 1 + 8)); Collection firstLocations = new ArrayList<>(); firstLocations.add("wh0n94"); @@ -325,7 +328,7 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase { .endArray(); XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(builder.bytes()); GeoContextMapping mapping = ContextBuilder.geo("geo").build(); - List internalQueryContexts = mapping.parseQueryContext(parser); + List internalQueryContexts = mapping.parseQueryContext(createParseContext(parser)); assertThat(internalQueryContexts.size(), equalTo(1 + 1 + 8 + 1 + 8 + 1 + 8)); Collection firstLocations = new ArrayList<>(); firstLocations.add("wh0n94"); @@ -347,4 +350,8 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase { assertThat(internalQueryContext.isPrefix, equalTo(internalQueryContext.context.length() < GeoContextMapping.DEFAULT_PRECISION)); } } + + private static QueryParseContext createParseContext(XContentParser parser) { + return new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT); + }; } diff --git a/core/src/test/java/org/elasticsearch/search/suggest/completion/GeoQueryContextTests.java b/core/src/test/java/org/elasticsearch/search/suggest/completion/GeoQueryContextTests.java index 1d058350a98..3e22513ec11 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/completion/GeoQueryContextTests.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/completion/GeoQueryContextTests.java @@ -20,7 +20,7 @@ package org.elasticsearch.search.suggest.completion; import org.elasticsearch.common.geo.GeoPoint; -import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.search.suggest.completion.context.GeoQueryContext; import java.io.IOException; @@ -51,8 +51,8 @@ public class GeoQueryContextTests extends QueryContextTestCase } @Override - protected GeoQueryContext fromXContent(XContentParser parser) throws IOException { - return GeoQueryContext.fromXContent(parser); + protected GeoQueryContext fromXContent(QueryParseContext context) throws IOException { + return GeoQueryContext.fromXContent(context); } public void testNullGeoPointIsIllegal() { diff --git a/core/src/test/java/org/elasticsearch/search/suggest/completion/QueryContextTestCase.java b/core/src/test/java/org/elasticsearch/search/suggest/completion/QueryContextTestCase.java index 58e2409cdee..2960a6e23d8 100644 --- a/core/src/test/java/org/elasticsearch/search/suggest/completion/QueryContextTestCase.java +++ b/core/src/test/java/org/elasticsearch/search/suggest/completion/QueryContextTestCase.java @@ -19,11 +19,14 @@ package org.elasticsearch.search.suggest.completion; +import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.index.query.QueryParseContext; +import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.test.ESTestCase; import java.io.IOException; @@ -40,7 +43,7 @@ public abstract class QueryContextTestCase extends ESTest /** * read the context */ - protected abstract QC fromXContent(XContentParser parser) throws IOException; + protected abstract QC fromXContent(QueryParseContext context) throws IOException; public void testToXContext() throws IOException { for (int i = 0; i < NUMBER_OF_RUNS; i++) { @@ -50,7 +53,7 @@ public abstract class QueryContextTestCase extends ESTest BytesReference bytesReference = builder.bytes(); XContentParser parser = XContentFactory.xContent(bytesReference).createParser(bytesReference); parser.nextToken(); - QC fromXContext = fromXContent(parser); + QC fromXContext = fromXContent(new QueryParseContext(new IndicesQueriesRegistry(), parser, ParseFieldMatcher.STRICT)); assertEquals(toXContent, fromXContext); assertEquals(toXContent.hashCode(), fromXContext.hashCode()); } From 5e1f26c22aeceb03691d6b218eed3dac65369ebd Mon Sep 17 00:00:00 2001 From: David Pilato Date: Fri, 15 Apr 2016 12:24:54 +0200 Subject: [PATCH 028/561] Add support for documented byte/size units and for micros as a time unit in _cat API We advertise in our documentation that byte units are like `kb`, `mb`... But we actually only support the simple notation `k` or `m`. This commit adds support for the documented form and keeps the non documented options to avoid any breaking change. It also adds support for `micros`, `nanos` and `d` as a time unit in `_cat` API. Remove the support for `b` as a SizeValue unit. Actually, for numbers, when using raw numbers without unit, there is no text to add/parse after the number. For example, you don't write `10` as `10b`. We support option like `size=` in `_cat` API which means that we want to display raw data without unit (singles). Documentation updated accordingly. Add test for the empty size option. Fix missing TimeValues options for some cat APIs --- .../elasticsearch/common/unit/SizeValue.java | 6 ++--- .../rest/action/support/RestTable.java | 20 +++++++++------ docs/reference/api-conventions.asciidoc | 25 ++++++++++++++++--- docs/reference/cat.asciidoc | 10 ++++++-- .../rest-api-spec/api/cat.allocation.json | 2 +- .../rest-api-spec/api/cat.fielddata.json | 2 +- .../rest-api-spec/api/cat.recovery.json | 2 +- .../rest-api-spec/api/cat.thread_pool.json | 5 ++++ .../test/cat.allocation/10_basic.yaml | 2 +- .../test/cat.thread_pool/10_basic.yaml | 10 ++++++++ 10 files changed, 64 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/unit/SizeValue.java b/core/src/main/java/org/elasticsearch/common/unit/SizeValue.java index 3958b19309e..e04dfe51430 100644 --- a/core/src/main/java/org/elasticsearch/common/unit/SizeValue.java +++ b/core/src/main/java/org/elasticsearch/common/unit/SizeValue.java @@ -175,9 +175,7 @@ public class SizeValue implements Streamable { } long singles; try { - if (sValue.endsWith("b")) { - singles = Long.parseLong(sValue.substring(0, sValue.length() - 1)); - } else if (sValue.endsWith("k") || sValue.endsWith("K")) { + if (sValue.endsWith("k") || sValue.endsWith("K")) { singles = (long) (Double.parseDouble(sValue.substring(0, sValue.length() - 1)) * SizeUnit.C1); } else if (sValue.endsWith("m") || sValue.endsWith("M")) { singles = (long) (Double.parseDouble(sValue.substring(0, sValue.length() - 1)) * SizeUnit.C2); @@ -232,4 +230,4 @@ public class SizeValue implements Streamable { result = 31 * result + (sizeUnit != null ? sizeUnit.hashCode() : 0); return result; } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/elasticsearch/rest/action/support/RestTable.java b/core/src/main/java/org/elasticsearch/rest/action/support/RestTable.java index 4e06e5da2ef..4ba0483ca49 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/support/RestTable.java +++ b/core/src/main/java/org/elasticsearch/rest/action/support/RestTable.java @@ -303,15 +303,15 @@ public class RestTable { String resolution = request.param("bytes"); if ("b".equals(resolution)) { return Long.toString(v.bytes()); - } else if ("k".equals(resolution)) { + } else if ("k".equals(resolution) || "kb".equals(resolution)) { return Long.toString(v.kb()); - } else if ("m".equals(resolution)) { + } else if ("m".equals(resolution) || "mb".equals(resolution)) { return Long.toString(v.mb()); - } else if ("g".equals(resolution)) { + } else if ("g".equals(resolution) || "gb".equals(resolution)) { return Long.toString(v.gb()); - } else if ("t".equals(resolution)) { + } else if ("t".equals(resolution) || "tb".equals(resolution)) { return Long.toString(v.tb()); - } else if ("p".equals(resolution)) { + } else if ("p".equals(resolution) || "pb".equals(resolution)) { return Long.toString(v.pb()); } else { return v.toString(); @@ -320,7 +320,7 @@ public class RestTable { if (value instanceof SizeValue) { SizeValue v = (SizeValue) value; String resolution = request.param("size"); - if ("b".equals(resolution)) { + if ("".equals(resolution)) { return Long.toString(v.singles()); } else if ("k".equals(resolution)) { return Long.toString(v.kilo()); @@ -339,7 +339,11 @@ public class RestTable { if (value instanceof TimeValue) { TimeValue v = (TimeValue) value; String resolution = request.param("time"); - if ("ms".equals(resolution)) { + if ("nanos".equals(resolution)) { + return Long.toString(v.nanos()); + } else if ("micros".equals(resolution)) { + return Long.toString(v.micros()); + } else if ("ms".equals(resolution)) { return Long.toString(v.millis()); } else if ("s".equals(resolution)) { return Long.toString(v.seconds()); @@ -347,6 +351,8 @@ public class RestTable { return Long.toString(v.minutes()); } else if ("h".equals(resolution)) { return Long.toString(v.hours()); + } else if ("d".equals(resolution)) { + return Long.toString(v.days()); } else { return v.toString(); } diff --git a/docs/reference/api-conventions.asciidoc b/docs/reference/api-conventions.asciidoc index 07d40e4149a..87df2902f9c 100644 --- a/docs/reference/api-conventions.asciidoc +++ b/docs/reference/api-conventions.asciidoc @@ -361,12 +361,14 @@ are: `m`:: Minute `s`:: Second `ms`:: Milli-second +`micros`:: Micro-second +`nanos`:: Nano-second -[[size-units]] +[[byte-units]] [float] -=== Data size units +=== Byte size units -Whenever the size of data needs to be specified, eg when setting a buffer size +Whenever the byte size of data needs to be specified, eg when setting a buffer size parameter, the value must specify the unit, like `10kb` for 10 kilobytes. The supported units are: @@ -378,6 +380,23 @@ supported units are: `tb`:: Terabytes `pb`:: Petabytes +[[size-units]] +[float] +=== Unit-less quantities + +Unit-less quantities means that they don't have a "unit" like "bytes" or "Hertz" or "meter" or "long tonne". + +If one of these quantities is large we'll print it out like 10m for 10,000,000 or 7k for 7,000. We'll still print 87 +when we mean 87 though. These are the supported multipliers: + +[horizontal] +``:: Single +`k`:: Kilo +`m`:: Mega +`g`:: Giga +`t`:: Tera +`p`:: Peta + [[distance-units]] [float] === Distance Units diff --git a/docs/reference/cat.asciidoc b/docs/reference/cat.asciidoc index 7c4125a7f36..9a0bc0f5cc0 100644 --- a/docs/reference/cat.asciidoc +++ b/docs/reference/cat.asciidoc @@ -74,8 +74,8 @@ with `bulk.`. [[numeric-formats]] === Numeric formats -Many commands provide a few types of numeric output, either a byte -value or a time value. By default, these types are human-formatted, +Many commands provide a few types of numeric output, either a byte, size +or a time value. By default, these types are human-formatted, for example, `3.5mb` instead of `3763212`. The human values are not sortable numerically, so in order to operate on these values where order is important, you can change it. @@ -95,6 +95,12 @@ green wiki1 3 0 10000 413 103776272 103776272 green foo 1 0 227 0 2065131 2065131 -------------------------------------------------- +If you want to change the <>, use `time` parameter. + +If you want to change the <>, use `size` parameter. + +If you want to change the <>, use `bytes` parameter. + [float] === Response as text, json, smile, yaml or cbor diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/cat.allocation.json b/rest-api-spec/src/main/resources/rest-api-spec/api/cat.allocation.json index bca547ce6a7..6799a67bae8 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/cat.allocation.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/cat.allocation.json @@ -19,7 +19,7 @@ "bytes": { "type": "enum", "description" : "The unit in which to display byte values", - "options": [ "b", "k", "m", "g" ] + "options": [ "b", "k", "kb", "m", "mb", "g", "gb", "t", "tb", "p", "pb" ] }, "local": { "type" : "boolean", diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/cat.fielddata.json b/rest-api-spec/src/main/resources/rest-api-spec/api/cat.fielddata.json index d2b207d4a49..b9776ab5881 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/cat.fielddata.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/cat.fielddata.json @@ -19,7 +19,7 @@ "bytes": { "type": "enum", "description" : "The unit in which to display byte values", - "options": [ "b", "k", "m", "g" ] + "options": [ "b", "k", "kb", "m", "mb", "g", "gb", "t", "tb", "p", "pb" ] }, "local": { "type" : "boolean", diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/cat.recovery.json b/rest-api-spec/src/main/resources/rest-api-spec/api/cat.recovery.json index e6a80552492..b220a5eda74 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/cat.recovery.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/cat.recovery.json @@ -19,7 +19,7 @@ "bytes": { "type": "enum", "description" : "The unit in which to display byte values", - "options": [ "b", "k", "m", "g" ] + "options": [ "b", "k", "kb", "m", "mb", "g", "gb", "t", "tb", "p", "pb" ] }, "master_timeout": { "type" : "time", diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/cat.thread_pool.json b/rest-api-spec/src/main/resources/rest-api-spec/api/cat.thread_pool.json index a942cd0ca66..b291804bbfc 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/cat.thread_pool.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/cat.thread_pool.json @@ -12,6 +12,11 @@ "type" : "string", "description" : "a short version of the Accept header, e.g. json, yaml" }, + "size": { + "type": "enum", + "description" : "The multiplier in which to display values", + "options": [ "", "k", "m", "g", "t", "p" ] + }, "local": { "type" : "boolean", "description" : "Return local information, do not retrieve the state from master node (default: false)" diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.allocation/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.allocation/10_basic.yaml index 3537da73c81..c1e25c88b95 100755 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.allocation/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.allocation/10_basic.yaml @@ -215,7 +215,7 @@ - do: cat.allocation: - bytes: g + bytes: gb - match: $body: | diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.thread_pool/10_basic.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.thread_pool/10_basic.yaml index 233e21bf470..b79100664ab 100755 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/cat.thread_pool/10_basic.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/cat.thread_pool/10_basic.yaml @@ -147,3 +147,13 @@ $body: | /^ id \s+ warmer.type \s+ warmer.active \s+ warmer.size \s+ warmer.queue \s+ warmer.queueSize \s+ warmer.rejected \s+ warmer.largest \s+ warmer.completed \s+ warmer.min \s+ warmer.max \s+ warmer.keepAlive \n (\S+ \s+ (cached|fixed|scaling)? \s+ \d+ \s+ \d+ \s+ \d+ \s+ \d* \s+ \d+ \s+ \d+ \s+ \d+ \s+ \d* \s+ \d* \s+ \S* \n)+ $/ + + - do: + cat.thread_pool: + size: "" + + - match: + $body: | + / #host ip bulk.active bulk.queue bulk.rejected index.active index.queue index.rejected search.active search.queue search.rejected + ^ (\S+ \s+ (\d{1,3}\.){3}\d{1,3} \s+ \d+ \s+ \d+ \s+ \d+ \s+ \d+ \s+ \d+ \s+ \d+ \s+ \d+ \s+ \d+ \s+ \d+ \n)+ $/ + From 781c0abdc04be4aa43e33780353e042151dd1737 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Fri, 15 Apr 2016 12:44:58 +0200 Subject: [PATCH 029/561] Add MatchNoDocsQuery, a query that matches no documents and prints the reason why in the toString method. --- .../lucene/search/MatchNoDocsQuery.java | 69 ++++++++++++++++ .../lucene/search/MatchNoDocsQueryTests.java | 78 +++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 core/src/main/java/org/elasticsearch/common/lucene/search/MatchNoDocsQuery.java create mode 100644 core/src/test/java/org/elasticsearch/common/lucene/search/MatchNoDocsQueryTests.java diff --git a/core/src/main/java/org/elasticsearch/common/lucene/search/MatchNoDocsQuery.java b/core/src/main/java/org/elasticsearch/common/lucene/search/MatchNoDocsQuery.java new file mode 100644 index 00000000000..a25b4c0aa29 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/common/lucene/search/MatchNoDocsQuery.java @@ -0,0 +1,69 @@ +/* + * 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.common.lucene.search; + +import org.apache.lucene.index.LeafReaderContext; +import org.apache.lucene.index.Term; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.Weight; +import org.apache.lucene.search.ConstantScoreWeight; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.Explanation; +import org.apache.lucene.search.Scorer; + +import java.io.IOException; +import java.util.Set; + +/** + * A query that matches no documents and prints the reason why in the toString method. + */ +public class MatchNoDocsQuery extends Query { + /** + * The reason why the query does not match any document. + */ + private final String reason; + + public MatchNoDocsQuery(String reason) { + this.reason = reason; + } + + public Weight createWeight(IndexSearcher searcher, boolean needsScores) throws IOException { + return new ConstantScoreWeight(this) { + @Override + public void extractTerms(Set terms) { + } + + @Override + public Explanation explain(LeafReaderContext context, int doc) throws IOException { + return Explanation.noMatch(reason); + } + + @Override + public Scorer scorer(LeafReaderContext context) throws IOException { + return null; + } + }; + } + + @Override + public String toString(String field) { + return "MatchNoDocsQuery[\"" + reason + "\"]"; + } +} diff --git a/core/src/test/java/org/elasticsearch/common/lucene/search/MatchNoDocsQueryTests.java b/core/src/test/java/org/elasticsearch/common/lucene/search/MatchNoDocsQueryTests.java new file mode 100644 index 00000000000..b328fd2ee9b --- /dev/null +++ b/core/src/test/java/org/elasticsearch/common/lucene/search/MatchNoDocsQueryTests.java @@ -0,0 +1,78 @@ +/* + * 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.common.lucene.search; + +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.TextField; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.DirectoryReader; +import org.apache.lucene.index.IndexWriter; +import org.apache.lucene.index.IndexWriterConfig; +import org.apache.lucene.index.Term; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.TermQuery; +import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.search.BooleanClause; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.store.RAMDirectory; +import org.elasticsearch.common.lucene.Lucene; +import org.elasticsearch.test.ESTestCase; + +import static org.hamcrest.Matchers.equalTo; + +public class MatchNoDocsQueryTests extends ESTestCase { + public void testSimple() throws Exception { + MatchNoDocsQuery query = new MatchNoDocsQuery("field 'title' not found"); + assertThat(query.toString(), equalTo("MatchNoDocsQuery[\"field 'title' not found\"]")); + Query rewrite = query.rewrite(null); + assertTrue(rewrite instanceof MatchNoDocsQuery); + assertThat(rewrite.toString(), equalTo("MatchNoDocsQuery[\"field 'title' not found\"]")); + } + + public void testSearch() throws Exception { + IndexWriter writer = new IndexWriter(new RAMDirectory(), new IndexWriterConfig(Lucene.STANDARD_ANALYZER)); + Document doc = new Document(); + doc.add(new Field("field", "aaa bbb ccc ddd", TextField.TYPE_NOT_STORED)); + writer.addDocument(doc); + IndexReader reader = DirectoryReader.open(writer); + IndexSearcher searcher = new IndexSearcher(reader); + + Query query = new MatchNoDocsQuery("field not found"); + assertThat(searcher.count(query), equalTo(0)); + + BooleanQuery.Builder bq = new BooleanQuery.Builder(); + bq.add(new BooleanClause(new TermQuery(new Term("field", "aaa")), BooleanClause.Occur.SHOULD)); + bq.add(new BooleanClause(new MatchNoDocsQuery("field not found"), BooleanClause.Occur.MUST)); + query = bq.build(); + assertThat(searcher.count(query), equalTo(0)); + assertThat(query.toString(), equalTo("field:aaa +MatchNoDocsQuery[\"field not found\"]")); + + + bq = new BooleanQuery.Builder(); + bq.add(new BooleanClause(new TermQuery(new Term("field", "aaa")), BooleanClause.Occur.SHOULD)); + bq.add(new BooleanClause(new MatchNoDocsQuery("field not found"), BooleanClause.Occur.SHOULD)); + query = bq.build(); + assertThat(query.toString(), equalTo("field:aaa MatchNoDocsQuery[\"field not found\"]")); + assertThat(searcher.count(query), equalTo(1)); + Query rewrite = query.rewrite(reader); + assertThat(rewrite.toString(), equalTo("field:aaa MatchNoDocsQuery[\"field not found\"]")); + } +} From b4e6b6308833d49c0c46157e3f63bc3fc9635e0e Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Fri, 15 Apr 2016 10:43:23 +0200 Subject: [PATCH 030/561] Apply the default operator on analyzed wildcard in simple_query_string builder: * This is a followup from https://github.com/elastic/elasticsearch/pull/17711 where we now apply the default operator on analyzed wildcard query in query_string builder. --- .../resources/checkstyle_suppressions.xml | 1 - .../classic/MapperQueryParser.java | 67 +++++----- .../index/query/SimpleQueryParser.java | 114 ++++++++++-------- .../index/query/AbstractQueryTestCase.java | 7 -- .../index/query/MockRepeatAnalyzer.java | 68 +++++++++++ .../query/QueryStringQueryBuilderTests.java | 93 ++++++++++---- .../index/query/SimpleQueryParserTests.java | 109 +++++++++++++++++ 7 files changed, 348 insertions(+), 111 deletions(-) create mode 100644 core/src/test/java/org/elasticsearch/index/query/MockRepeatAnalyzer.java create mode 100644 core/src/test/java/org/elasticsearch/index/query/SimpleQueryParserTests.java diff --git a/buildSrc/src/main/resources/checkstyle_suppressions.xml b/buildSrc/src/main/resources/checkstyle_suppressions.xml index cafdacad5cd..3b4655796da 100644 --- a/buildSrc/src/main/resources/checkstyle_suppressions.xml +++ b/buildSrc/src/main/resources/checkstyle_suppressions.xml @@ -502,7 +502,6 @@ - diff --git a/core/src/main/java/org/apache/lucene/queryparser/classic/MapperQueryParser.java b/core/src/main/java/org/apache/lucene/queryparser/classic/MapperQueryParser.java index 9dc5071839c..72222d56702 100644 --- a/core/src/main/java/org/apache/lucene/queryparser/classic/MapperQueryParser.java +++ b/core/src/main/java/org/apache/lucene/queryparser/classic/MapperQueryParser.java @@ -530,42 +530,45 @@ public class MapperQueryParser extends QueryParser { } } + if (tlist.size() == 0) { + return null; + } if (tlist.size() == 1 && tlist.get(0).size() == 1) { return super.getPrefixQuery(field, tlist.get(0).get(0)); - } else { - // build a boolean query with prefix on the last position only. - List clauses = new ArrayList<>(); - for (int pos = 0; pos < tlist.size(); pos++) { - List plist = tlist.get(pos); - boolean isLastPos = (pos == tlist.size()-1); - Query posQuery; - if (plist.size() == 1) { - if (isLastPos) { - posQuery = getPrefixQuery(field, plist.get(0)); - } else { - posQuery = newTermQuery(new Term(field, plist.get(0))); - } - } else if (isLastPos == false) { - // build a synonym query for terms in the same position. - Term[] terms = new Term[plist.size()]; - for (int i = 0; i < plist.size(); i++) { - terms[i] = new Term(field, plist.get(i)); - } - posQuery = new SynonymQuery(terms); - } else { - List innerClauses = new ArrayList<>(); - for (String token : plist) { - innerClauses.add(new BooleanClause(getPrefixQuery(field, token), - BooleanClause.Occur.SHOULD)); - } - posQuery = getBooleanQueryCoordDisabled(innerClauses); - } - clauses.add(new BooleanClause(posQuery, - getDefaultOperator() == Operator.AND ? BooleanClause.Occur.MUST : BooleanClause.Occur.SHOULD)); - } - return getBooleanQuery(clauses); } + + // build a boolean query with prefix on the last position only. + List clauses = new ArrayList<>(); + for (int pos = 0; pos < tlist.size(); pos++) { + List plist = tlist.get(pos); + boolean isLastPos = (pos == tlist.size() - 1); + Query posQuery; + if (plist.size() == 1) { + if (isLastPos) { + posQuery = super.getPrefixQuery(field, plist.get(0)); + } else { + posQuery = newTermQuery(new Term(field, plist.get(0))); + } + } else if (isLastPos == false) { + // build a synonym query for terms in the same position. + Term[] terms = new Term[plist.size()]; + for (int i = 0; i < plist.size(); i++) { + terms[i] = new Term(field, plist.get(i)); + } + posQuery = new SynonymQuery(terms); + } else { + List innerClauses = new ArrayList<>(); + for (String token : plist) { + innerClauses.add(new BooleanClause(super.getPrefixQuery(field, token), + BooleanClause.Occur.SHOULD)); + } + posQuery = getBooleanQueryCoordDisabled(innerClauses); + } + clauses.add(new BooleanClause(posQuery, + getDefaultOperator() == Operator.AND ? BooleanClause.Occur.MUST : BooleanClause.Occur.SHOULD)); + } + return getBooleanQuery(clauses); } @Override diff --git a/core/src/main/java/org/elasticsearch/index/query/SimpleQueryParser.java b/core/src/main/java/org/elasticsearch/index/query/SimpleQueryParser.java index c191e1996b3..151e924ad16 100644 --- a/core/src/main/java/org/elasticsearch/index/query/SimpleQueryParser.java +++ b/core/src/main/java/org/elasticsearch/index/query/SimpleQueryParser.java @@ -19,9 +19,9 @@ package org.elasticsearch.index.query; import org.apache.lucene.analysis.Analyzer; -import org.apache.lucene.analysis.CachingTokenFilter; import org.apache.lucene.analysis.TokenStream; -import org.apache.lucene.analysis.tokenattributes.TermToBytesRefAttribute; +import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; +import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; import org.apache.lucene.index.Term; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; @@ -29,13 +29,15 @@ import org.apache.lucene.search.BoostQuery; import org.apache.lucene.search.FuzzyQuery; import org.apache.lucene.search.PrefixQuery; import org.apache.lucene.search.Query; -import org.apache.lucene.util.BytesRef; +import org.apache.lucene.search.SynonymQuery; import org.elasticsearch.index.mapper.MappedFieldType; import java.io.IOException; import java.util.Locale; import java.util.Map; import java.util.Objects; +import java.util.List; +import java.util.ArrayList; /** * Wrapper class for Lucene's SimpleQueryParser that allows us to redefine @@ -47,7 +49,8 @@ public class SimpleQueryParser extends org.apache.lucene.queryparser.simple.Simp private QueryShardContext context; /** Creates a new parser with custom flags used to enable/disable certain features. */ - public SimpleQueryParser(Analyzer analyzer, Map weights, int flags, Settings settings, QueryShardContext context) { + public SimpleQueryParser(Analyzer analyzer, Map weights, int flags, + Settings settings, QueryShardContext context) { super(analyzer, weights, flags); this.settings = settings; this.context = context; @@ -167,62 +170,79 @@ public class SimpleQueryParser extends org.apache.lucene.queryparser.simple.Simp /** * Analyze the given string using its analyzer, constructing either a * {@code PrefixQuery} or a {@code BooleanQuery} made up - * of {@code PrefixQuery}s + * of {@code TermQuery}s and {@code PrefixQuery}s */ private Query newPossiblyAnalyzedQuery(String field, String termStr) { + List> tlist = new ArrayList<> (); + // get Analyzer from superclass and tokenize the term try (TokenStream source = getAnalyzer().tokenStream(field, termStr)) { - // Use the analyzer to get all the tokens, and then build a TermQuery, - // PhraseQuery, or nothing based on the term count - CachingTokenFilter buffer = new CachingTokenFilter(source); - buffer.reset(); + source.reset(); + List currentPos = new ArrayList<>(); + CharTermAttribute termAtt = source.addAttribute(CharTermAttribute.class); + PositionIncrementAttribute posAtt = source.addAttribute(PositionIncrementAttribute.class); - TermToBytesRefAttribute termAtt = null; - int numTokens = 0; - boolean hasMoreTokens = false; - termAtt = buffer.getAttribute(TermToBytesRefAttribute.class); - if (termAtt != null) { - try { - hasMoreTokens = buffer.incrementToken(); - while (hasMoreTokens) { - numTokens++; - hasMoreTokens = buffer.incrementToken(); + try { + boolean hasMoreTokens = source.incrementToken(); + while (hasMoreTokens) { + if (currentPos.isEmpty() == false && posAtt.getPositionIncrement() > 0) { + tlist.add(currentPos); + currentPos = new ArrayList<>(); } - } catch (IOException e) { - // ignore + currentPos.add(termAtt.toString()); + hasMoreTokens = source.incrementToken(); } - } - - // rewind buffer - buffer.reset(); - - if (numTokens == 0) { - return null; - } else if (numTokens == 1) { - try { - boolean hasNext = buffer.incrementToken(); - assert hasNext == true; - } catch (IOException e) { - // safe to ignore, because we know the number of tokens + if (currentPos.isEmpty() == false) { + tlist.add(currentPos); } - return new PrefixQuery(new Term(field, BytesRef.deepCopyOf(termAtt.getBytesRef()))); - } else { - BooleanQuery.Builder bq = new BooleanQuery.Builder(); - for (int i = 0; i < numTokens; i++) { - try { - boolean hasNext = buffer.incrementToken(); - assert hasNext == true; - } catch (IOException e) { - // safe to ignore, because we know the number of tokens - } - bq.add(new BooleanClause(new PrefixQuery(new Term(field, BytesRef.deepCopyOf(termAtt.getBytesRef()))), BooleanClause.Occur.SHOULD)); - } - return bq.build(); + } catch (IOException e) { + // ignore + // TODO: we should not ignore the exception and return a prefix query with the original term ? } } catch (IOException e) { // Bail on any exceptions, going with a regular prefix query return new PrefixQuery(new Term(field, termStr)); } + + if (tlist.size() == 0) { + return null; + } + + if (tlist.size() == 1 && tlist.get(0).size() == 1) { + return new PrefixQuery(new Term(field, tlist.get(0).get(0))); + } + + // build a boolean query with prefix on the last position only. + BooleanQuery.Builder builder = new BooleanQuery.Builder(); + for (int pos = 0; pos < tlist.size(); pos++) { + List plist = tlist.get(pos); + boolean isLastPos = (pos == tlist.size()-1); + Query posQuery; + if (plist.size() == 1) { + if (isLastPos) { + posQuery = new PrefixQuery(new Term(field, plist.get(0))); + } else { + posQuery = newTermQuery(new Term(field, plist.get(0))); + } + } else if (isLastPos == false) { + // build a synonym query for terms in the same position. + Term[] terms = new Term[plist.size()]; + for (int i = 0; i < plist.size(); i++) { + terms[i] = new Term(field, plist.get(i)); + } + posQuery = new SynonymQuery(terms); + } else { + BooleanQuery.Builder innerBuilder = new BooleanQuery.Builder(); + for (String token : plist) { + innerBuilder.add(new BooleanClause(new PrefixQuery(new Term(field, token)), + BooleanClause.Occur.SHOULD)); + } + posQuery = innerBuilder.setDisableCoord(true).build(); + } + builder.add(new BooleanClause(posQuery, getDefaultOperator())); + } + return builder.build(); } + /** * Class encapsulating the settings for the SimpleQueryString query, with * their default values diff --git a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java index aa6aa51982f..4a8d2ddc1ab 100644 --- a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java +++ b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java @@ -645,13 +645,6 @@ public abstract class AbstractQueryTestCase> assertThat(termQuery.getTerm().text().toLowerCase(Locale.ROOT), equalTo(value.toLowerCase(Locale.ROOT))); } - protected static void assertPrefixQuery(Query query, String field, String value) { - assertThat(query, instanceOf(PrefixQuery.class)); - PrefixQuery prefixQuery = (PrefixQuery) query; - assertThat(prefixQuery.getPrefix().field(), equalTo(field)); - assertThat(prefixQuery.getPrefix().text(), equalTo(value)); - } - /** * Test serialization and deserialization of the test query. */ diff --git a/core/src/test/java/org/elasticsearch/index/query/MockRepeatAnalyzer.java b/core/src/test/java/org/elasticsearch/index/query/MockRepeatAnalyzer.java new file mode 100644 index 00000000000..fc76a0d464c --- /dev/null +++ b/core/src/test/java/org/elasticsearch/index/query/MockRepeatAnalyzer.java @@ -0,0 +1,68 @@ +/* + * 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.index.query; + +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.TokenFilter; +import org.apache.lucene.analysis.TokenStream; +import org.apache.lucene.analysis.Tokenizer; +import org.apache.lucene.analysis.standard.StandardTokenizer; +import org.apache.lucene.analysis.tokenattributes.CharTermAttribute; +import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute; + +import java.io.IOException; + +public class MockRepeatAnalyzer extends Analyzer { + private static class MockRepeatFilter extends TokenFilter { + CharTermAttribute termAtt = addAttribute(CharTermAttribute.class); + PositionIncrementAttribute posIncAtt = addAttribute(PositionIncrementAttribute.class); + String repeat; + + public MockRepeatFilter(TokenStream input) { + super(input); + } + + @Override + public final boolean incrementToken() throws IOException { + if (repeat != null) { + // add repeat token + clearAttributes(); + termAtt.setEmpty().append(repeat); + posIncAtt.setPositionIncrement(0); + repeat = null; + return true; + } + + if (input.incrementToken()) { + repeat = termAtt.toString(); + return true; + } else { + return false; + } + } + } + + @Override + protected TokenStreamComponents createComponents(String fieldName) { + Tokenizer tokenizer = new StandardTokenizer(); + TokenStream repeatFilter = new MockRepeatFilter(tokenizer); + return new TokenStreamComponents(tokenizer, repeatFilter); + } +} diff --git a/core/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java index 2738d14ef02..67f1d75fd63 100644 --- a/core/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/QueryStringQueryBuilderTests.java @@ -21,6 +21,8 @@ package org.elasticsearch.index.query; import org.apache.lucene.document.IntPoint; import org.apache.lucene.index.Term; +import org.apache.lucene.queryparser.classic.MapperQueryParser; +import org.apache.lucene.queryparser.classic.QueryParserSettings; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.BoostQuery; @@ -32,13 +34,18 @@ import org.apache.lucene.search.PhraseQuery; import org.apache.lucene.search.Query; import org.apache.lucene.search.RegexpQuery; import org.apache.lucene.search.TermQuery; +import org.apache.lucene.search.SynonymQuery; +import org.apache.lucene.search.PrefixQuery; +import org.apache.lucene.search.MultiTermQuery; import org.apache.lucene.util.automaton.TooComplexToDeterminizeException; import org.elasticsearch.Version; import org.elasticsearch.common.lucene.all.AllTermQuery; +import org.elasticsearch.common.unit.Fuzziness; import org.hamcrest.Matchers; import org.joda.time.DateTimeZone; import java.io.IOException; +import java.util.Collections; import java.util.List; import static org.elasticsearch.index.query.QueryBuilders.queryStringQuery; @@ -298,32 +305,70 @@ public class QueryStringQueryBuilderTests extends AbstractQueryTestCase 0); for (Operator op : Operator.values()) { - Query query = queryStringQuery("foo-bar-foobar*") - .defaultField(STRING_FIELD_NAME) - .analyzeWildcard(true) - .analyzer("standard") - .defaultOperator(op) - .toQuery(createShardContext()); - assertThat(query, instanceOf(BooleanQuery.class)); - BooleanQuery bq = (BooleanQuery) query; - assertThat(bq.clauses().size(), equalTo(3)); - String[] expectedTerms = new String[]{"foo", "bar", "foobar"}; - for (int i = 0; i < bq.clauses().size(); i++) { - BooleanClause clause = bq.clauses().get(i); - if (i != bq.clauses().size() - 1) { - assertTermQuery(clause.getQuery(), STRING_FIELD_NAME, expectedTerms[i]); - } else { - assertPrefixQuery(clause.getQuery(), STRING_FIELD_NAME, expectedTerms[i]); - } - if (op == Operator.AND) { - assertThat(clause.getOccur(), equalTo(BooleanClause.Occur.MUST)); - } else { - assertThat(clause.getOccur(), equalTo(BooleanClause.Occur.SHOULD)); - } - } + BooleanClause.Occur defaultOp = op.toBooleanClauseOccur(); + MapperQueryParser queryParser = new MapperQueryParser(createShardContext()); + QueryParserSettings settings = new QueryParserSettings("first foo-bar-foobar* last"); + settings.defaultField(STRING_FIELD_NAME); + settings.fieldsAndWeights(Collections.emptyMap()); + settings.analyzeWildcard(true); + settings.fuzziness(Fuzziness.AUTO); + settings.rewriteMethod(MultiTermQuery.CONSTANT_SCORE_REWRITE); + settings.defaultOperator(op.toQueryParserOperator()); + queryParser.reset(settings); + Query query = queryParser.parse("first foo-bar-foobar* last"); + Query expectedQuery = + new BooleanQuery.Builder() + .add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "first")), defaultOp)) + .add(new BooleanQuery.Builder() + .add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "foo")), defaultOp)) + .add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "bar")), defaultOp)) + .add(new BooleanClause(new PrefixQuery(new Term(STRING_FIELD_NAME, "foobar")), defaultOp)) + .build(), defaultOp) + .add(new BooleanClause(new TermQuery(new Term(STRING_FIELD_NAME, "last")), defaultOp)) + .build(); + assertThat(query, Matchers.equalTo(expectedQuery)); + } + } + + public void testToQueryWilcardQueryWithSynonyms() throws Exception { + assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0); + for (Operator op : Operator.values()) { + BooleanClause.Occur defaultOp = op.toBooleanClauseOccur(); + MapperQueryParser queryParser = new MapperQueryParser(createShardContext()); + QueryParserSettings settings = new QueryParserSettings("first foo-bar-foobar* last"); + settings.defaultField(STRING_FIELD_NAME); + settings.fieldsAndWeights(Collections.emptyMap()); + settings.analyzeWildcard(true); + settings.fuzziness(Fuzziness.AUTO); + settings.rewriteMethod(MultiTermQuery.CONSTANT_SCORE_REWRITE); + settings.defaultOperator(op.toQueryParserOperator()); + settings.forceAnalyzer(new MockRepeatAnalyzer()); + queryParser.reset(settings); + Query query = queryParser.parse("first foo-bar-foobar* last"); + + Query expectedQuery = new BooleanQuery.Builder() + .add(new BooleanClause(new SynonymQuery(new Term(STRING_FIELD_NAME, "first"), + new Term(STRING_FIELD_NAME, "first")), defaultOp)) + .add(new BooleanQuery.Builder() + .add(new BooleanClause(new SynonymQuery(new Term(STRING_FIELD_NAME, "foo"), + new Term(STRING_FIELD_NAME, "foo")), defaultOp)) + .add(new BooleanClause(new SynonymQuery(new Term(STRING_FIELD_NAME, "bar"), + new Term(STRING_FIELD_NAME, "bar")), defaultOp)) + .add(new BooleanQuery.Builder() + .add(new BooleanClause(new PrefixQuery(new Term(STRING_FIELD_NAME, "foobar")), + BooleanClause.Occur.SHOULD)) + .add(new BooleanClause(new PrefixQuery(new Term(STRING_FIELD_NAME, "foobar")), + BooleanClause.Occur.SHOULD)) + .setDisableCoord(true) + .build(), defaultOp) + .build(), defaultOp) + .add(new BooleanClause(new SynonymQuery(new Term(STRING_FIELD_NAME, "last"), + new Term(STRING_FIELD_NAME, "last")), defaultOp)) + .build(); + assertThat(query, Matchers.equalTo(expectedQuery)); } } diff --git a/core/src/test/java/org/elasticsearch/index/query/SimpleQueryParserTests.java b/core/src/test/java/org/elasticsearch/index/query/SimpleQueryParserTests.java new file mode 100644 index 00000000000..8511ad6d9c7 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/index/query/SimpleQueryParserTests.java @@ -0,0 +1,109 @@ +/* + * 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.index.query; + +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.standard.StandardAnalyzer; +import org.apache.lucene.index.Term; +import org.apache.lucene.search.Query; +import org.apache.lucene.search.TermQuery; +import org.apache.lucene.search.SynonymQuery; +import org.apache.lucene.search.PrefixQuery; +import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.search.BooleanClause; +import org.elasticsearch.test.ESTestCase; + +import java.util.HashMap; +import java.util.Map; + +import static org.hamcrest.Matchers.equalTo; + +public class SimpleQueryParserTests extends ESTestCase { + private static class MockSimpleQueryParser extends SimpleQueryParser { + public MockSimpleQueryParser(Analyzer analyzer, Map weights, int flags, Settings settings) { + super(analyzer, weights, flags, settings, null); + } + + @Override + protected Query newTermQuery(Term term) { + return new TermQuery(term); + } + } + + public void testAnalyzeWildcard() { + SimpleQueryParser.Settings settings = new SimpleQueryParser.Settings(); + settings.analyzeWildcard(true); + Map weights = new HashMap<>(); + weights.put("field1", 1.0f); + SimpleQueryParser parser = new MockSimpleQueryParser(new StandardAnalyzer(), weights, -1, settings); + for (Operator op : Operator.values()) { + BooleanClause.Occur defaultOp = op.toBooleanClauseOccur(); + parser.setDefaultOperator(defaultOp); + Query query = parser.parse("first foo-bar-foobar* last"); + Query expectedQuery = + new BooleanQuery.Builder() + .add(new BooleanClause(new TermQuery(new Term("field1", "first")), defaultOp)) + .add(new BooleanQuery.Builder() + .add(new BooleanClause(new TermQuery(new Term("field1", "foo")), defaultOp)) + .add(new BooleanClause(new TermQuery(new Term("field1", "bar")), defaultOp)) + .add(new BooleanClause(new PrefixQuery(new Term("field1", "foobar")), defaultOp)) + .build(), defaultOp) + .add(new BooleanClause(new TermQuery(new Term("field1", "last")), defaultOp)) + .build(); + assertThat(query, equalTo(expectedQuery)); + } + } + + public void testAnalyzerWildcardWithSynonyms() { + SimpleQueryParser.Settings settings = new SimpleQueryParser.Settings(); + settings.analyzeWildcard(true); + Map weights = new HashMap<>(); + weights.put("field1", 1.0f); + SimpleQueryParser parser = new MockSimpleQueryParser(new MockRepeatAnalyzer(), weights, -1, settings); + + for (Operator op : Operator.values()) { + BooleanClause.Occur defaultOp = op.toBooleanClauseOccur(); + parser.setDefaultOperator(defaultOp); + Query query = parser.parse("first foo-bar-foobar* last"); + + Query expectedQuery = new BooleanQuery.Builder() + .add(new BooleanClause(new SynonymQuery(new Term("field1", "first"), + new Term("field1", "first")), defaultOp)) + .add(new BooleanQuery.Builder() + .add(new BooleanClause(new SynonymQuery(new Term("field1", "foo"), + new Term("field1", "foo")), defaultOp)) + .add(new BooleanClause(new SynonymQuery(new Term("field1", "bar"), + new Term("field1", "bar")), defaultOp)) + .add(new BooleanQuery.Builder() + .add(new BooleanClause(new PrefixQuery(new Term("field1", "foobar")), + BooleanClause.Occur.SHOULD)) + .add(new BooleanClause(new PrefixQuery(new Term("field1", "foobar")), + BooleanClause.Occur.SHOULD)) + .setDisableCoord(true) + .build(), defaultOp) + .build(), defaultOp) + .add(new BooleanClause(new SynonymQuery(new Term("field1", "last"), + new Term("field1", "last")), defaultOp)) + .build(); + assertThat(query, equalTo(expectedQuery)); + } + } + +} From d3b130606932f8664e928f67c032c2fb796547e7 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Fri, 15 Apr 2016 16:51:50 -0400 Subject: [PATCH 031/561] Reindex: never report negative throttled_until Just clamp the value at 0. It isn't useful to tell the user "this thread should have woken 5ms ago". Closes #17783 --- .../index/reindex/BulkByScrollTask.java | 3 +- .../index/reindex/BulkByScrollTaskTests.java | 63 +++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollTask.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollTask.java index 7149dbb2094..42798d5a34d 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollTask.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/BulkByScrollTask.java @@ -38,6 +38,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; +import static java.lang.Math.max; import static java.lang.Math.round; import static org.elasticsearch.common.unit.TimeValue.timeValueNanos; @@ -93,7 +94,7 @@ public class BulkByScrollTask extends CancellableTask { if (delayed.future == null) { return timeValueNanos(0); } - return timeValueNanos(delayed.future.getDelay(TimeUnit.NANOSECONDS)); + return timeValueNanos(max(0, delayed.future.getDelay(TimeUnit.NANOSECONDS))); } /** diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/BulkByScrollTaskTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/BulkByScrollTaskTests.java index 77472906b4a..e30c55b8096 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/BulkByScrollTaskTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/BulkByScrollTaskTests.java @@ -29,8 +29,11 @@ import java.io.IOException; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.Delayed; +import java.util.concurrent.ExecutionException; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import static org.elasticsearch.common.unit.TimeValue.parseTimeValue; @@ -206,4 +209,64 @@ public class BulkByScrollTaskTests extends ESTestCase { } assertThat(errors, empty()); } + + public void testDelayNeverNegative() throws IOException { + // Thread pool that returns a ScheduledFuture that claims to have a negative delay + ThreadPool threadPool = new ThreadPool("test") { + public ScheduledFuture schedule(TimeValue delay, String name, Runnable command) { + return new ScheduledFuture() { + @Override + public long getDelay(TimeUnit unit) { + return -1; + } + + @Override + public int compareTo(Delayed o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean cancel(boolean mayInterruptIfRunning) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isCancelled() { + throw new UnsupportedOperationException(); + } + + @Override + public boolean isDone() { + throw new UnsupportedOperationException(); + } + + @Override + public Void get() throws InterruptedException, ExecutionException { + throw new UnsupportedOperationException(); + } + + @Override + public Void get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + throw new UnsupportedOperationException(); + } + }; + } + }; + try { + // Have the task use the thread pool to delay a task that does nothing + task.delayPrepareBulkRequest(threadPool, timeValueSeconds(0), new AbstractRunnable() { + @Override + protected void doRun() throws Exception { + } + @Override + public void onFailure(Throwable t) { + throw new UnsupportedOperationException(); + } + }); + // Even though the future returns a negative delay we just return 0 because the time is up. + assertEquals(timeValueSeconds(0), task.getStatus().getThrottledUntil()); + } finally { + threadPool.shutdown(); + } + } } From 5ce3eb96b09bda134556d9148a3036a9d2a8de4a Mon Sep 17 00:00:00 2001 From: Sergii Golubev Date: Fri, 15 Apr 2016 20:44:01 +0300 Subject: [PATCH 032/561] tophits-aggregation.asciidoc: fix a typo --- .../aggregations/metrics/tophits-aggregation.asciidoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc b/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc index 30f403d3f7f..afbb40b5b1a 100644 --- a/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc +++ b/docs/reference/aggregations/metrics/tophits-aggregation.asciidoc @@ -155,7 +155,7 @@ Elasticsearch this can be implemented via a bucket aggregator that wraps a `top_ In the example below we search across crawled webpages. For each webpage we store the body and the domain the webpage belong to. By defining a `terms` aggregator on the `domain` field we group the result set of webpages by domain. The -`top_docs` aggregator is then defined as sub-aggregator, so that the top matching hits are collected per bucket. +`top_hits` aggregator is then defined as sub-aggregator, so that the top matching hits are collected per bucket. Also a `max` aggregator is defined which is used by the `terms` aggregator's order feature the return the buckets by relevancy order of the most relevant document in a bucket. @@ -272,4 +272,4 @@ the second slow of the `nested_child_field` field: ] } ... --------------------------------------------------- \ No newline at end of file +-------------------------------------------------- From b9faa13274a23c810acbc4fb58593f969db5ef4a Mon Sep 17 00:00:00 2001 From: Daniel Mitterdorfer Date: Mon, 18 Apr 2016 09:31:48 +0200 Subject: [PATCH 033/561] Balance request sizes in NettyHttpRequestSizeLimitIT This test should demonstrate that a single (larger) request is processed but on of multiple large concurrent requests is rejected. This test broke too early under some circumstances in network mode as the limit is quite low. With this commit we reduce the size of the individual large requests but issue more concurrent ones thus increasing stability of this test. --- .../http/netty/NettyHttpRequestSizeLimitIT.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/elasticsearch/http/netty/NettyHttpRequestSizeLimitIT.java b/core/src/test/java/org/elasticsearch/http/netty/NettyHttpRequestSizeLimitIT.java index bf65ec4ff8b..e9787677f4b 100644 --- a/core/src/test/java/org/elasticsearch/http/netty/NettyHttpRequestSizeLimitIT.java +++ b/core/src/test/java/org/elasticsearch/http/netty/NettyHttpRequestSizeLimitIT.java @@ -57,7 +57,7 @@ public class NettyHttpRequestSizeLimitIT extends ESIntegTestCase { ensureGreen(); // we use the limit size as a (very) rough indication on how many requests we should sent to hit the limit - int numRequests = LIMIT.bytesAsInt() / 50; + int numRequests = LIMIT.bytesAsInt() / 100; StringBuilder bulkRequest = new StringBuilder(); for (int i = 0; i < numRequests; i++) { @@ -69,6 +69,11 @@ public class NettyHttpRequestSizeLimitIT extends ESIntegTestCase { @SuppressWarnings("unchecked") Tuple[] requests = new Tuple[] { + Tuple.tuple("/index/type/_bulk", bulkRequest), + Tuple.tuple("/index/type/_bulk", bulkRequest), + Tuple.tuple("/index/type/_bulk", bulkRequest), + Tuple.tuple("/index/type/_bulk", bulkRequest), + Tuple.tuple("/index/type/_bulk", bulkRequest), Tuple.tuple("/index/type/_bulk", bulkRequest), Tuple.tuple("/index/type/_bulk", bulkRequest), Tuple.tuple("/index/type/_bulk", bulkRequest), From b84a192884b6f168f9e1d4c36c12d328b25e6f2f Mon Sep 17 00:00:00 2001 From: Daniel Mitterdorfer Date: Mon, 18 Apr 2016 10:18:23 +0200 Subject: [PATCH 034/561] Honor invariant Suggest.suggestions != null --- .../src/main/java/org/elasticsearch/search/suggest/Suggest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/src/main/java/org/elasticsearch/search/suggest/Suggest.java b/core/src/main/java/org/elasticsearch/search/suggest/Suggest.java index f9c7092fbf1..926ebaf35b0 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/Suggest.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/Suggest.java @@ -35,6 +35,7 @@ import org.elasticsearch.search.suggest.term.TermSuggestion; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.Iterator; @@ -64,6 +65,7 @@ public class Suggest implements Iterable>> suggestMap; public Suggest() { + this(Collections.emptyList()); } public Suggest(List>> suggestions) { From 3dc21e780b397304a2ce7bf587cbfddf1c736c08 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Mon, 18 Apr 2016 12:13:10 +0200 Subject: [PATCH 035/561] Add missing index name to search slow log. This commits adds the index name as part of the logging message. Closes #17025 --- .../elasticsearch/index/SearchSlowLog.java | 27 ++-- .../index/SearchSlowLogTests.java | 117 +++++++++++++++++- 2 files changed, 131 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/SearchSlowLog.java b/core/src/main/java/org/elasticsearch/index/SearchSlowLog.java index 57d879ab584..b4a6430b69e 100644 --- a/core/src/main/java/org/elasticsearch/index/SearchSlowLog.java +++ b/core/src/main/java/org/elasticsearch/index/SearchSlowLog.java @@ -33,7 +33,7 @@ import java.util.concurrent.TimeUnit; /** */ public final class SearchSlowLog implements SearchOperationListener { - + private final Index index; private boolean reformat; private long queryWarnThreshold; @@ -87,6 +87,8 @@ public final class SearchSlowLog implements SearchOperationListener { this.queryLogger = Loggers.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".query"); this.fetchLogger = Loggers.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".fetch"); + this.index = indexSettings.getIndex(); + indexSettings.getScopedSettings().addSettingsUpdateConsumer(INDEX_SEARCH_SLOWLOG_REFORMAT, this::setReformat); this.reformat = indexSettings.getValue(INDEX_SEARCH_SLOWLOG_REFORMAT); @@ -120,36 +122,38 @@ public final class SearchSlowLog implements SearchOperationListener { @Override public void onQueryPhase(SearchContext context, long tookInNanos) { if (queryWarnThreshold >= 0 && tookInNanos > queryWarnThreshold) { - queryLogger.warn("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat)); + queryLogger.warn("{}", new SlowLogSearchContextPrinter(index, context, tookInNanos, reformat)); } else if (queryInfoThreshold >= 0 && tookInNanos > queryInfoThreshold) { - queryLogger.info("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat)); + queryLogger.info("{}", new SlowLogSearchContextPrinter(index, context, tookInNanos, reformat)); } else if (queryDebugThreshold >= 0 && tookInNanos > queryDebugThreshold) { - queryLogger.debug("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat)); + queryLogger.debug("{}", new SlowLogSearchContextPrinter(index, context, tookInNanos, reformat)); } else if (queryTraceThreshold >= 0 && tookInNanos > queryTraceThreshold) { - queryLogger.trace("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat)); + queryLogger.trace("{}", new SlowLogSearchContextPrinter(index, context, tookInNanos, reformat)); } } @Override public void onFetchPhase(SearchContext context, long tookInNanos) { if (fetchWarnThreshold >= 0 && tookInNanos > fetchWarnThreshold) { - fetchLogger.warn("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat)); + fetchLogger.warn("{}", new SlowLogSearchContextPrinter(index, context, tookInNanos, reformat)); } else if (fetchInfoThreshold >= 0 && tookInNanos > fetchInfoThreshold) { - fetchLogger.info("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat)); + fetchLogger.info("{}", new SlowLogSearchContextPrinter(index, context, tookInNanos, reformat)); } else if (fetchDebugThreshold >= 0 && tookInNanos > fetchDebugThreshold) { - fetchLogger.debug("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat)); + fetchLogger.debug("{}", new SlowLogSearchContextPrinter(index, context, tookInNanos, reformat)); } else if (fetchTraceThreshold >= 0 && tookInNanos > fetchTraceThreshold) { - fetchLogger.trace("{}", new SlowLogSearchContextPrinter(context, tookInNanos, reformat)); + fetchLogger.trace("{}", new SlowLogSearchContextPrinter(index, context, tookInNanos, reformat)); } } - private static class SlowLogSearchContextPrinter { + static final class SlowLogSearchContextPrinter { private final SearchContext context; + private final Index index; private final long tookInNanos; private final boolean reformat; - public SlowLogSearchContextPrinter(SearchContext context, long tookInNanos, boolean reformat) { + public SlowLogSearchContextPrinter(Index index, SearchContext context, long tookInNanos, boolean reformat) { this.context = context; + this.index = index; this.tookInNanos = tookInNanos; this.reformat = reformat; } @@ -157,6 +161,7 @@ public final class SearchSlowLog implements SearchOperationListener { @Override public String toString() { StringBuilder sb = new StringBuilder(); + sb.append(index).append(" "); sb.append("took[").append(TimeValue.timeValueNanos(tookInNanos)).append("], took_millis[").append(TimeUnit.NANOSECONDS.toMillis(tookInNanos)).append("], "); if (context.getQueryShardContext().getTypes() == null) { sb.append("types[], "); diff --git a/core/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java b/core/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java index 855291ace6c..49283d7b73a 100644 --- a/core/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java +++ b/core/src/test/java/org/elasticsearch/index/SearchSlowLogTests.java @@ -20,13 +20,126 @@ package org.elasticsearch.index; import org.elasticsearch.Version; +import org.elasticsearch.action.search.SearchType; +import org.elasticsearch.cache.recycler.PageCacheRecycler; import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.common.util.BigArrays; +import org.elasticsearch.index.query.QueryShardContext; +import org.elasticsearch.index.shard.ShardId; +import org.elasticsearch.script.ScriptService; +import org.elasticsearch.script.Template; +import org.elasticsearch.search.Scroll; +import org.elasticsearch.search.builder.SearchSourceBuilder; +import org.elasticsearch.search.internal.SearchContext; +import org.elasticsearch.search.internal.ShardSearchRequest; +import org.elasticsearch.test.ESSingleNodeTestCase; +import org.elasticsearch.test.TestSearchContext; +import org.elasticsearch.threadpool.ThreadPool; + +import java.io.IOException; + +import static org.hamcrest.Matchers.startsWith; -public class SearchSlowLogTests extends ESTestCase { +public class SearchSlowLogTests extends ESSingleNodeTestCase { + @Override + protected SearchContext createSearchContext(IndexService indexService) { + BigArrays bigArrays = indexService.getBigArrays(); + ThreadPool threadPool = indexService.getThreadPool(); + PageCacheRecycler pageCacheRecycler = node().injector().getInstance(PageCacheRecycler.class); + ScriptService scriptService = node().injector().getInstance(ScriptService.class); + return new TestSearchContext(threadPool, pageCacheRecycler, bigArrays, scriptService, indexService) { + @Override + public ShardSearchRequest request() { + return new ShardSearchRequest() { + @Override + public ShardId shardId() { + return null; + } + + @Override + public String[] types() { + return new String[0]; + } + + @Override + public SearchSourceBuilder source() { + return null; + } + + @Override + public void source(SearchSourceBuilder source) { + + } + + @Override + public int numberOfShards() { + return 0; + } + + @Override + public SearchType searchType() { + return null; + } + + @Override + public String[] filteringAliases() { + return new String[0]; + } + + @Override + public long nowInMillis() { + return 0; + } + + @Override + public Template template() { + return null; + } + + @Override + public Boolean requestCache() { + return null; + } + + @Override + public Scroll scroll() { + return null; + } + + @Override + public void setProfile(boolean profile) { + + } + + @Override + public boolean isProfile() { + return false; + } + + @Override + public BytesReference cacheKey() throws IOException { + return null; + } + + @Override + public void rewrite(QueryShardContext context) throws IOException { + } + }; + } + }; + } + + public void testSlowLogSearchContextPrinterToLog() throws IOException { + IndexService index = createIndex("foo"); + // Turning off document logging doesn't log source[] + SearchContext searchContext = createSearchContext(index); + SearchSlowLog.SlowLogSearchContextPrinter p = new SearchSlowLog.SlowLogSearchContextPrinter(index.index(), searchContext, 10, true); + assertThat(p.toString(), startsWith(index.index().toString())); + } public void testReformatSetting() { IndexMetaData metaData = newIndexMeta("index", Settings.builder() From 478b5024f239dad342800fdb1c75bb327e5cbfc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Mon, 18 Apr 2016 12:30:57 +0200 Subject: [PATCH 036/561] Wrap parser creation in try-with-resources --- .../percolate/TransportPercolateAction.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/percolate/TransportPercolateAction.java b/core/src/main/java/org/elasticsearch/action/percolate/TransportPercolateAction.java index a1b4a883e48..c9bb0c73fdc 100644 --- a/core/src/main/java/org/elasticsearch/action/percolate/TransportPercolateAction.java +++ b/core/src/main/java/org/elasticsearch/action/percolate/TransportPercolateAction.java @@ -18,9 +18,6 @@ */ package org.elasticsearch.action.percolate; -import java.io.IOException; -import java.util.Arrays; - import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.get.GetResponse; @@ -55,6 +52,9 @@ import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; +import java.io.IOException; +import java.util.Arrays; + public class TransportPercolateAction extends HandledTransportAction { private final Client client; @@ -196,13 +196,14 @@ public class TransportPercolateAction extends HandledTransportAction queryBuilder = queryParseContext.parseInnerQueryBuilder(); - BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); - boolQueryBuilder.must(queryBuilder); - boolQueryBuilder.filter(percolatorQueryBuilder); - searchSource.field("query", boolQueryBuilder); + try (XContentParser parser = XContentHelper.createParser(querySource)) { + QueryParseContext queryParseContext = new QueryParseContext(queryRegistry, parser, parseFieldMatcher); + QueryBuilder queryBuilder = queryParseContext.parseInnerQueryBuilder(); + BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); + boolQueryBuilder.must(queryBuilder); + boolQueryBuilder.filter(percolatorQueryBuilder); + searchSource.field("query", boolQueryBuilder); + } } else { // wrapping in a constant score query with boost 0 for bwc reason. // percolator api didn't emit scores before and never included scores From 2e2d8c1442bc47151fca711f910f0f88a15b9f84 Mon Sep 17 00:00:00 2001 From: Danilo Vaz Date: Mon, 18 Apr 2016 07:39:23 -0300 Subject: [PATCH 037/561] Updated copyright years to include 2016 (#17808) --- NOTICE.txt | 2 +- README.textile | 2 +- core/README.textile | 2 +- distribution/deb/src/main/packaging/copyright | 2 +- distribution/src/main/resources/NOTICE.txt | 2 +- distribution/src/main/resources/README.textile | 2 +- docs/perl/index.asciidoc | 2 +- docs/python/index.asciidoc | 4 ++-- docs/ruby/copyright.asciidoc | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/NOTICE.txt b/NOTICE.txt index 23cae9e2063..c99b9581931 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -1,5 +1,5 @@ Elasticsearch -Copyright 2009-2015 Elasticsearch +Copyright 2009-2016 Elasticsearch This product includes software developed by The Apache Software Foundation (http://www.apache.org/). diff --git a/README.textile b/README.textile index 1f532f7359d..5c75844b108 100644 --- a/README.textile +++ b/README.textile @@ -222,7 +222,7 @@ h1. License
 This software is licensed under the Apache License, version 2 ("ALv2"), quoted below.
 
-Copyright 2009-2015 Elasticsearch 
+Copyright 2009-2016 Elasticsearch 
 
 Licensed 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
diff --git a/core/README.textile b/core/README.textile
index 720f357406b..daaf5ecb70e 100644
--- a/core/README.textile
+++ b/core/README.textile
@@ -219,7 +219,7 @@ h1. License
 
 This software is licensed under the Apache License, version 2 ("ALv2"), quoted below.
 
-Copyright 2009-2015 Elasticsearch 
+Copyright 2009-2016 Elasticsearch 
 
 Licensed 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
diff --git a/distribution/deb/src/main/packaging/copyright b/distribution/deb/src/main/packaging/copyright
index d93b550af95..1e647bbac54 100644
--- a/distribution/deb/src/main/packaging/copyright
+++ b/distribution/deb/src/main/packaging/copyright
@@ -1,4 +1,4 @@
-Copyright 2013-2015 Elasticsearch 
+Copyright 2013-2016 Elasticsearch 
 
 License: Apache-2.0
  Licensed under the Apache License, Version 2.0 (the "License");
diff --git a/distribution/src/main/resources/NOTICE.txt b/distribution/src/main/resources/NOTICE.txt
index 23cae9e2063..c99b9581931 100644
--- a/distribution/src/main/resources/NOTICE.txt
+++ b/distribution/src/main/resources/NOTICE.txt
@@ -1,5 +1,5 @@
 Elasticsearch
-Copyright 2009-2015 Elasticsearch
+Copyright 2009-2016 Elasticsearch
 
 This product includes software developed by The Apache Software
 Foundation (http://www.apache.org/).
diff --git a/distribution/src/main/resources/README.textile b/distribution/src/main/resources/README.textile
index b2873e8b56e..c19041cec22 100644
--- a/distribution/src/main/resources/README.textile
+++ b/distribution/src/main/resources/README.textile
@@ -219,7 +219,7 @@ h1. License
 
 This software is licensed under the Apache License, version 2 ("ALv2"), quoted below.
 
-Copyright 2009-2015 Elasticsearch 
+Copyright 2009-2016 Elasticsearch 
 
 Licensed 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
diff --git a/docs/perl/index.asciidoc b/docs/perl/index.asciidoc
index 0e3e9002eb1..734447d0dd1 100644
--- a/docs/perl/index.asciidoc
+++ b/docs/perl/index.asciidoc
@@ -115,7 +115,7 @@ https://github.com/elastic/elasticsearch-perl/blob/master/CONTRIBUTING.asciidoc[
 
 == Copyright and License
 
-This software is Copyright (c) 2013-2015 by Elasticsearch BV.
+This software is Copyright (c) 2013-2016 by Elasticsearch BV.
 
 This is free software, licensed under:
 https://github.com/elastic/elasticsearch-perl/blob/master/LICENSE.txt[The Apache License Version 2.0].
diff --git a/docs/python/index.asciidoc b/docs/python/index.asciidoc
index 64756adc444..2ec7579ef12 100644
--- a/docs/python/index.asciidoc
+++ b/docs/python/index.asciidoc
@@ -77,7 +77,7 @@ Simple use-case:
 {u'any': u'data', u'timestamp': u'2013-05-12T19:45:31.804229'}
 ------------------------------------
 
-[NOTE] 
+[NOTE]
 All the API calls map the raw REST api as closely as possible, including
 the distinction between required and optional arguments to the calls. This
 means that the code makes distinction between positional and keyword arguments;
@@ -111,7 +111,7 @@ some of the more engaging tasks like bulk indexing and reindexing.
 
 === License
 
-Copyright 2013-2015 Elasticsearch
+Copyright 2013-2016 Elasticsearch
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
diff --git a/docs/ruby/copyright.asciidoc b/docs/ruby/copyright.asciidoc
index dbfae04b481..cf5c19c9fee 100644
--- a/docs/ruby/copyright.asciidoc
+++ b/docs/ruby/copyright.asciidoc
@@ -1,5 +1,5 @@
 == Copyright and License
 
-This software is Copyright (c) 2013-2015 by Elasticsearch BV.
+This software is Copyright (c) 2013-2016 by Elasticsearch BV.
 
 This is free software, licensed under The Apache License Version 2.0.

From 070b78517e4edd60d06c8f14c27a9644bd008a0a Mon Sep 17 00:00:00 2001
From: Nik Everett 
Date: Fri, 15 Apr 2016 13:59:20 -0400
Subject: [PATCH 038/561] Cut stats_bucket and extended_stats_bucket to
 registerPipelineAggregation

and remove their PROTOTYPE.

Relates to #17085
---
 .../elasticsearch/search/SearchModule.java    |  9 ++-
 .../pipeline/PipelineAggregatorBuilder.java   |  1 +
 ...ucketMetricsPipelineAggregatorBuilder.java | 59 ++++++++++++-------
 .../stats/StatsBucketParser.java              | 42 -------------
 .../StatsBucketPipelineAggregatorBuilder.java | 52 ++++++++++------
 .../extended/ExtendedStatsBucketParser.java   | 10 ----
 ...dStatsBucketPipelineAggregatorBuilder.java | 44 ++++++++------
 .../DerivativePipelineAggregatorBuilder.java  |  4 ++
 8 files changed, 108 insertions(+), 113 deletions(-)
 delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketParser.java

diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java
index 06b09e6e744..0f9e55a4ae6 100644
--- a/core/src/main/java/org/elasticsearch/search/SearchModule.java
+++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java
@@ -198,10 +198,11 @@ import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucke
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketParser;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregator;
-import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketParser;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregator;
+import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketParser;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregator;
+import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketParser;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptParser;
@@ -501,8 +502,10 @@ public class SearchModule extends AbstractModule {
         registerPipelineParser(new MinBucketParser());
         registerPipelineParser(new AvgBucketParser());
         registerPipelineParser(new SumBucketParser());
-        registerPipelineParser(new StatsBucketParser());
-        registerPipelineParser(new ExtendedStatsBucketParser());
+        registerPipelineAggregation(StatsBucketPipelineAggregatorBuilder::new, StatsBucketPipelineAggregatorBuilder.PARSER,
+                StatsBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
+        registerPipelineAggregation(ExtendedStatsBucketPipelineAggregatorBuilder::new, new ExtendedStatsBucketParser(),
+                ExtendedStatsBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
         registerPipelineParser(new PercentilesBucketParser());
         registerPipelineParser(new MovAvgParser(movAvgModelParserMapper));
         registerPipelineParser(new CumulativeSumParser());
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregatorBuilder.java
index 9e943412232..08e1b19ca07 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/PipelineAggregatorBuilder.java
@@ -163,6 +163,7 @@ public abstract class PipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException {
+        BucketMetricsPipelineAggregatorBuilder factory = innerReadFrom(name, bucketsPaths, in);
+        factory.format = in.readOptionalString();
+        factory.gapPolicy = GapPolicy.readFrom(in);
+        return factory;
+    }
+
+    protected BucketMetricsPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in)
+            throws IOException {
+        throw new UnsupportedOperationException(); // NORELEASE remove before 5.0.0 GA
+    }
+
+
     /**
      * Sets the format to use on the output of this aggregation.
      */
@@ -109,26 +146,6 @@ public abstract class BucketMetricsPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException {
-        BucketMetricsPipelineAggregatorBuilder factory = innerReadFrom(name, bucketsPaths, in);
-        factory.format = in.readOptionalString();
-        factory.gapPolicy = GapPolicy.readFrom(in);
-        return factory;
-    }
-
-    protected abstract BucketMetricsPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in)
-            throws IOException;
-
-    @Override
-    protected final void doWriteTo(StreamOutput out) throws IOException {
-        innerWriteTo(out);
-        out.writeOptionalString(format);
-        gapPolicy.writeTo(out);
-    }
-
-    protected abstract void innerWriteTo(StreamOutput out) throws IOException;
-
     @Override
     protected final int doHashCode() {
         return Objects.hash(format, gapPolicy, innerHashCode());
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketParser.java
deleted file mode 100644
index dd4215618d8..00000000000
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketParser.java
+++ /dev/null
@@ -1,42 +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.aggregations.pipeline.bucketmetrics.stats;
-
-import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
-
-import java.util.Map;
-
-public class StatsBucketParser extends BucketMetricsParser {
-    @Override
-    public String type() {
-        return StatsBucketPipelineAggregator.TYPE.name();
-    }
-
-    @Override
-    protected StatsBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName,
-            String bucketsPath, Map unparsedParams) {
-        return new StatsBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath);
-    }
-
-    @Override
-    public StatsBucketPipelineAggregatorBuilder getFactoryPrototype() {
-        return StatsBucketPipelineAggregatorBuilder.PROTOTYPE;
-    }
-}
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregatorBuilder.java
index 91fe885f93e..37ba5e3c1f0 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/StatsBucketPipelineAggregatorBuilder.java
@@ -19,30 +19,45 @@
 
 package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats;
 
+import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
-import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser;
+import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
+import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder;
 
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 
-public class StatsBucketPipelineAggregatorBuilder
-        extends BucketMetricsPipelineAggregatorBuilder {
-
-    static final StatsBucketPipelineAggregatorBuilder PROTOTYPE = new StatsBucketPipelineAggregatorBuilder("", "");
+public class StatsBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder {
+    public static final String NAME = StatsBucketPipelineAggregator.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     public StatsBucketPipelineAggregatorBuilder(String name, String bucketsPath) {
-        this(name, new String[] { bucketsPath });
+        super(name, StatsBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath });
     }
 
-    private StatsBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) {
-        super(name, StatsBucketPipelineAggregator.TYPE.name(), bucketsPaths);
+    /**
+     * Read from a stream.
+     */
+    public StatsBucketPipelineAggregatorBuilder(StreamInput in)
+            throws IOException {
+        super(in, StatsBucketPipelineAggregator.TYPE.name());
+    }
+
+    @Override
+    protected void innerWriteTo(StreamOutput out) throws IOException {
+        // Do nothing, no extra state to write to stream
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
     }
 
     @Override
@@ -64,16 +79,13 @@ public class StatsBucketPipelineAggregatorBuilder
         return builder;
     }
 
-    @Override
-    protected StatsBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in)
-            throws IOException {
-        return new StatsBucketPipelineAggregatorBuilder(name, bucketsPaths);
-    }
-
-    @Override
-    protected void innerWriteTo(StreamOutput out) throws IOException {
-        // Do nothing, no extra state to write to stream
-    }
+    public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() {
+        @Override
+        protected StatsBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName,
+                String bucketsPath, Map unparsedParams) {
+            return new StatsBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath);
+        }
+    };
 
     @Override
     protected int innerHashCode() {
@@ -85,4 +97,8 @@ public class StatsBucketPipelineAggregatorBuilder
         return true;
     }
 
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketParser.java
index 996adfd6492..698af21387f 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketParser.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketParser.java
@@ -28,11 +28,6 @@ import java.util.Map;
 public class ExtendedStatsBucketParser extends BucketMetricsParser {
     static final ParseField SIGMA = new ParseField("sigma");
 
-    @Override
-    public String type() {
-        return ExtendedStatsBucketPipelineAggregator.TYPE.name();
-    }
-
     @Override
     protected ExtendedStatsBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName,
             String bucketsPath, Map unparsedParams) throws ParseException {
@@ -56,9 +51,4 @@ public class ExtendedStatsBucketParser extends BucketMetricsParser {
         }
         return factory;
     }
-
-    @Override
-    public ExtendedStatsBucketPipelineAggregatorBuilder getFactoryPrototype() {
-        return ExtendedStatsBucketPipelineAggregatorBuilder.PROTOTYPE;
-    }
 }
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregatorBuilder.java
index 6121a49d133..8856def6741 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/stats/extended/ExtendedStatsBucketPipelineAggregatorBuilder.java
@@ -19,13 +19,14 @@
 
 package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended;
 
+import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
-import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser;
+import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder;
 
 import java.io.IOException;
@@ -35,17 +36,31 @@ import java.util.Objects;
 
 public class ExtendedStatsBucketPipelineAggregatorBuilder
         extends BucketMetricsPipelineAggregatorBuilder {
-
-    static final ExtendedStatsBucketPipelineAggregatorBuilder PROTOTYPE = new ExtendedStatsBucketPipelineAggregatorBuilder("", "");
+    public static final String NAME = ExtendedStatsBucketPipelineAggregator.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     private double sigma = 2.0;
 
     public ExtendedStatsBucketPipelineAggregatorBuilder(String name, String bucketsPath) {
-        this(name, new String[] { bucketsPath });
+        super(name, ExtendedStatsBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath });
     }
 
-    private ExtendedStatsBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) {
-        super(name, ExtendedStatsBucketPipelineAggregator.TYPE.name(), bucketsPaths);
+    /**
+     * Read from a stream.
+     */
+    public ExtendedStatsBucketPipelineAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, ExtendedStatsBucketPipelineAggregator.TYPE.name());
+        sigma = in.readDouble();
+    }
+
+    @Override
+    protected void innerWriteTo(StreamOutput out) throws IOException {
+        out.writeDouble(sigma);
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
     }
 
     /**
@@ -93,19 +108,6 @@ public class ExtendedStatsBucketPipelineAggregatorBuilder
         return builder;
     }
 
-    @Override
-    protected ExtendedStatsBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in)
-            throws IOException {
-        ExtendedStatsBucketPipelineAggregatorBuilder factory = new ExtendedStatsBucketPipelineAggregatorBuilder(name, bucketsPaths);
-        factory.sigma = in.readDouble();
-        return factory;
-    }
-
-    @Override
-    protected void innerWriteTo(StreamOutput out) throws IOException {
-        out.writeDouble(sigma);
-    }
-
     @Override
     protected int innerHashCode() {
         return Objects.hash(sigma);
@@ -117,4 +119,8 @@ public class ExtendedStatsBucketPipelineAggregatorBuilder
         return Objects.equals(sigma, other.sigma);
     }
 
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java
index 01238b48d53..65d11681077 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/derivative/DerivativePipelineAggregatorBuilder.java
@@ -273,4 +273,8 @@ public class DerivativePipelineAggregatorBuilder extends PipelineAggregatorBuild
         return Objects.hash(format, gapPolicy, units);
     }
 
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file

From e7cbc5559229113acb81623ac341f0b0df1a059a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=BCscher?= 
Date: Mon, 18 Apr 2016 14:27:50 +0200
Subject: [PATCH 039/561] Cleaning up query shard context creation in
 AbstractQueryTestCase

---
 .../index/query/AbstractQueryTestCase.java    | 55 +++++++++++++------
 .../query/HasChildQueryBuilderTests.java      | 22 --------
 .../query/HasParentQueryBuilderTests.java     | 22 --------
 .../index/query/NestedQueryBuilderTests.java  | 22 --------
 .../query/ParentIdQueryBuilderTests.java      | 23 --------
 5 files changed, 37 insertions(+), 107 deletions(-)

diff --git a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java
index 471d1d7baca..5c45456f7fe 100644
--- a/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java
+++ b/core/src/test/java/org/elasticsearch/index/query/AbstractQueryTestCase.java
@@ -152,7 +152,6 @@ public abstract class AbstractQueryTestCase>
 
     private static Injector injector;
     private static IndicesQueriesRegistry indicesQueriesRegistry;
-    private static QueryShardContext queryShardContext;
     private static IndexFieldDataService indexFieldDataService;
     private static int queryNameId = 0;
     private static SearchModule searchModule;
@@ -187,6 +186,12 @@ public abstract class AbstractQueryTestCase>
 
     private static String[] randomTypes;
     private static ClientInvocationHandler clientInvocationHandler = new ClientInvocationHandler();
+    private static IndexSettings idxSettings;
+    private static SimilarityService similarityService;
+    private static MapperService mapperService;
+    private static PercolatorQueryCache percolatorQueryCache;
+    private static BitsetFilterCache bitsetFilterCache;
+    private static ScriptService scriptService;
 
     /**
      * Setup for the whole base test class.
@@ -206,7 +211,7 @@ public abstract class AbstractQueryTestCase>
                 .put(IndexMetaData.SETTING_VERSION_CREATED, indexVersionCreated).build();
         final ThreadPool threadPool = new ThreadPool(settings);
         index = new Index(randomAsciiOfLengthBetween(1, 10), "_na_");
-        IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(index, indexSettings);
+        idxSettings = IndexSettingsModule.newIndexSettings(index, indexSettings);
         ClusterService clusterService = createClusterService(threadPool);
         setState(clusterService, new ClusterState.Builder(clusterService.state()).metaData(new MetaData.Builder().put(
                 new IndexMetaData.Builder(index.getName()).settings(indexSettings).numberOfShards(1).numberOfReplicas(0))));
@@ -280,16 +285,16 @@ public abstract class AbstractQueryTestCase>
                 }
         ).createInjector();
         AnalysisService analysisService = new AnalysisRegistry(null, new Environment(settings)).build(idxSettings);
-        ScriptService scriptService = injector.getInstance(ScriptService.class);
-        SimilarityService similarityService = new SimilarityService(idxSettings, Collections.emptyMap());
+        scriptService = injector.getInstance(ScriptService.class);
+        similarityService = new SimilarityService(idxSettings, Collections.emptyMap());
         MapperRegistry mapperRegistry = injector.getInstance(MapperRegistry.class);
-        MapperService mapperService = new MapperService(idxSettings, analysisService, similarityService, mapperRegistry,
-                () -> queryShardContext);
+        mapperService = new MapperService(idxSettings, analysisService, similarityService, mapperRegistry,
+                () -> createShardContext());
         IndicesFieldDataCache indicesFieldDataCache = new IndicesFieldDataCache(settings, new IndexFieldDataCache.Listener() {
         });
         indexFieldDataService = new IndexFieldDataService(idxSettings, indicesFieldDataCache,
                 injector.getInstance(CircuitBreakerService.class), mapperService);
-        BitsetFilterCache bitsetFilterCache = new BitsetFilterCache(idxSettings, new BitsetFilterCache.Listener() {
+        bitsetFilterCache = new BitsetFilterCache(idxSettings, new BitsetFilterCache.Listener() {
             @Override
             public void onCache(ShardId shardId, Accountable accountable) {
 
@@ -300,10 +305,8 @@ public abstract class AbstractQueryTestCase>
 
             }
         });
-        PercolatorQueryCache percolatorQueryCache = new PercolatorQueryCache(idxSettings, () -> queryShardContext);
+        percolatorQueryCache = new PercolatorQueryCache(idxSettings, () -> createShardContext());
         indicesQueriesRegistry = injector.getInstance(IndicesQueriesRegistry.class);
-        queryShardContext = new QueryShardContext(idxSettings, bitsetFilterCache, indexFieldDataService, mapperService, similarityService,
-                scriptService, indicesQueriesRegistry, percolatorQueryCache, null);
         //create some random type with some default field, those types will stick around for all of the subclasses
         currentTypes = new String[randomIntBetween(0, 5)];
         for (int i = 0; i < currentTypes.length; i++) {
@@ -334,13 +337,18 @@ public abstract class AbstractQueryTestCase>
         terminate(injector.getInstance(ThreadPool.class));
         injector = null;
         index = null;
-        queryShardContext = null;
         currentTypes = null;
         namedWriteableRegistry = null;
         randomTypes = null;
         indicesQueriesRegistry = null;
         indexFieldDataService = null;
         searchModule = null;
+        idxSettings = null;
+        similarityService = null;
+        mapperService = null;
+        percolatorQueryCache = null;
+        bitsetFilterCache = null;
+        scriptService = null;
     }
 
     @Before
@@ -350,8 +358,18 @@ public abstract class AbstractQueryTestCase>
         randomTypes = getRandomTypes();
     }
 
-    protected void setSearchContext(String[] types) {
-        TestSearchContext testSearchContext = new TestSearchContext(queryShardContext);
+    private static void setSearchContext(String[] types, QueryShardContext context) {
+        TestSearchContext testSearchContext = new TestSearchContext(context) {
+            @Override
+            public MapperService mapperService() {
+                return mapperService; // need to build / parse inner hits sort fields
+            }
+
+            @Override
+            public IndexFieldDataService fieldData() {
+                return indexFieldDataService(); // need to build / parse inner hits sort fields
+            }
+        };
         testSearchContext.getQueryShardContext().setTypes(types);
         SearchContext.setCurrent(testSearchContext);
     }
@@ -541,7 +559,7 @@ public abstract class AbstractQueryTestCase>
             context.setAllowUnmappedFields(true);
             QB firstQuery = createTestQueryBuilder();
             QB controlQuery = copyQuery(firstQuery);
-            setSearchContext(randomTypes); // only set search context for toQuery to be more realistic
+            setSearchContext(randomTypes, context); // only set search context for toQuery to be more realistic
             Query firstLuceneQuery = rewriteQuery(firstQuery, context).toQuery(context);
             assertLuceneQuery(firstQuery, firstLuceneQuery, context);
             SearchContext.removeCurrent(); // remove after assertLuceneQuery since the assertLuceneQuery impl might access the context as well
@@ -559,7 +577,7 @@ public abstract class AbstractQueryTestCase>
                 secondQuery.queryName(secondQuery.queryName() == null ? randomAsciiOfLengthBetween(1, 30) : secondQuery.queryName()
                         + randomAsciiOfLengthBetween(1, 10));
             }
-            setSearchContext(randomTypes);
+            setSearchContext(randomTypes, context);
             Query secondLuceneQuery = rewriteQuery(secondQuery, context).toQuery(context);
             assertLuceneQuery(secondQuery, secondLuceneQuery, context);
             SearchContext.removeCurrent();
@@ -569,7 +587,7 @@ public abstract class AbstractQueryTestCase>
             // if the initial lucene query is null, changing its boost won't have any effect, we shouldn't test that
             if (firstLuceneQuery != null && supportsBoostAndQueryName()) {
                 secondQuery.boost(firstQuery.boost() + 1f + randomFloat());
-                setSearchContext(randomTypes);
+                setSearchContext(randomTypes, context);
                 Query thirdLuceneQuery = rewriteQuery(secondQuery, context).toQuery(context);
                 SearchContext.removeCurrent();
                 assertNotEquals("modifying the boost doesn't affect the corresponding lucene query", rewrite(firstLuceneQuery),
@@ -727,7 +745,8 @@ public abstract class AbstractQueryTestCase>
      * @return a new {@link QueryShardContext} based on the base test index and queryParserService
      */
     protected static QueryShardContext createShardContext() {
-        return new QueryShardContext(queryShardContext);
+        return new QueryShardContext(idxSettings, bitsetFilterCache, indexFieldDataService, mapperService, similarityService,
+                scriptService, indicesQueriesRegistry, percolatorQueryCache, null);
     }
 
     /**
@@ -986,7 +1005,7 @@ public abstract class AbstractQueryTestCase>
         QueryShardContext context = createShardContext();
         context.setAllowUnmappedFields(true);
         QB queryBuilder = createTestQueryBuilder();
-        setSearchContext(randomTypes); // only set search context for toQuery to be more realistic
+        setSearchContext(randomTypes, context); // only set search context for toQuery to be more realistic
         queryBuilder.toQuery(context);
     }
 
diff --git a/core/src/test/java/org/elasticsearch/index/query/HasChildQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/HasChildQueryBuilderTests.java
index 1b8238a8cac..538f39ac44c 100644
--- a/core/src/test/java/org/elasticsearch/index/query/HasChildQueryBuilderTests.java
+++ b/core/src/test/java/org/elasticsearch/index/query/HasChildQueryBuilderTests.java
@@ -38,7 +38,6 @@ import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
 import org.elasticsearch.common.ParsingException;
 import org.elasticsearch.common.compress.CompressedXContent;
 import org.elasticsearch.common.settings.Settings;
-import org.elasticsearch.index.fielddata.IndexFieldDataService;
 import org.elasticsearch.index.mapper.MapperService;
 import org.elasticsearch.index.mapper.Uid;
 import org.elasticsearch.index.mapper.internal.TypeFieldMapper;
@@ -50,7 +49,6 @@ import org.elasticsearch.search.fetch.innerhits.InnerHitsContext;
 import org.elasticsearch.search.internal.SearchContext;
 import org.elasticsearch.search.sort.FieldSortBuilder;
 import org.elasticsearch.search.sort.SortOrder;
-import org.elasticsearch.test.TestSearchContext;
 import org.junit.BeforeClass;
 
 import java.io.IOException;
@@ -93,26 +91,6 @@ public class HasChildQueryBuilderTests extends AbstractQueryTestCase
Date: Fri, 15 Apr 2016 13:14:24 -0400
Subject: [PATCH 040/561] Cut global, missing, cardinality, and value_count to
 registerAggregation

and remove their PROTOTYPEs.

Related to #17085
---
 .../elasticsearch/search/SearchModule.java    | 14 +++--
 .../global/GlobalAggregatorBuilder.java       | 44 ++++++++++----
 .../bucket/global/GlobalParser.java           | 47 ---------------
 .../missing/MissingAggregatorBuilder.java     | 45 +++++++++-----
 .../bucket/missing/MissingParser.java         | 10 ----
 .../CardinalityAggregatorBuilder.java         | 59 ++++++++++++-------
 .../cardinality/CardinalityParser.java        | 10 ----
 .../ValueCountAggregatorBuilder.java          | 45 +++++++++-----
 .../metrics/valuecount/ValueCountParser.java  | 10 ----
 .../ValuesSourceAggregatorBuilder.java        | 10 +++-
 10 files changed, 147 insertions(+), 147 deletions(-)
 delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalParser.java

diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java
index 0f9e55a4ae6..1acbb41ebff 100644
--- a/core/src/main/java/org/elasticsearch/search/SearchModule.java
+++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java
@@ -110,7 +110,7 @@ import org.elasticsearch.search.aggregations.bucket.filters.InternalFilters;
 import org.elasticsearch.search.aggregations.bucket.geogrid.GeoGridAggregatorBuilder;
 import org.elasticsearch.search.aggregations.bucket.geogrid.GeoHashGridParser;
 import org.elasticsearch.search.aggregations.bucket.geogrid.InternalGeoHashGrid;
-import org.elasticsearch.search.aggregations.bucket.global.GlobalParser;
+import org.elasticsearch.search.aggregations.bucket.global.GlobalAggregatorBuilder;
 import org.elasticsearch.search.aggregations.bucket.global.InternalGlobal;
 import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregatorBuilder;
 import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramParser;
@@ -118,6 +118,7 @@ import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregato
 import org.elasticsearch.search.aggregations.bucket.histogram.HistogramParser;
 import org.elasticsearch.search.aggregations.bucket.histogram.InternalHistogram;
 import org.elasticsearch.search.aggregations.bucket.missing.InternalMissing;
+import org.elasticsearch.search.aggregations.bucket.missing.MissingAggregatorBuilder;
 import org.elasticsearch.search.aggregations.bucket.missing.MissingParser;
 import org.elasticsearch.search.aggregations.bucket.nested.InternalNested;
 import org.elasticsearch.search.aggregations.bucket.nested.InternalReverseNested;
@@ -156,6 +157,7 @@ import org.elasticsearch.search.aggregations.bucket.terms.UnmappedTerms;
 import org.elasticsearch.search.aggregations.metrics.avg.AvgAggregatorBuilder;
 import org.elasticsearch.search.aggregations.metrics.avg.AvgParser;
 import org.elasticsearch.search.aggregations.metrics.avg.InternalAvg;
+import org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityAggregatorBuilder;
 import org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityParser;
 import org.elasticsearch.search.aggregations.metrics.cardinality.InternalCardinality;
 import org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsAggregatorBuilder;
@@ -185,6 +187,7 @@ import org.elasticsearch.search.aggregations.metrics.sum.SumParser;
 import org.elasticsearch.search.aggregations.metrics.tophits.InternalTopHits;
 import org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregatorBuilder;
 import org.elasticsearch.search.aggregations.metrics.valuecount.InternalValueCount;
+import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountAggregatorBuilder;
 import org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountParser;
 import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
@@ -457,12 +460,13 @@ public class SearchModule extends AbstractModule {
         registerAggregatorParser(new MaxParser());
         registerAggregatorParser(new StatsParser());
         registerAggregatorParser(new ExtendedStatsParser());
-        registerAggregatorParser(new ValueCountParser());
+        registerAggregation(ValueCountAggregatorBuilder::new, new ValueCountParser(), ValueCountAggregatorBuilder.AGGREGATION_NAME_FIELD);
         registerAggregatorParser(new PercentilesParser());
         registerAggregatorParser(new PercentileRanksParser());
-        registerAggregatorParser(new CardinalityParser());
-        registerAggregatorParser(new GlobalParser());
-        registerAggregatorParser(new MissingParser());
+        registerAggregation(CardinalityAggregatorBuilder::new, new CardinalityParser(),
+                CardinalityAggregatorBuilder.AGGREGATION_NAME_FIELD);
+        registerAggregation(GlobalAggregatorBuilder::new, GlobalAggregatorBuilder::parse, GlobalAggregatorBuilder.AGGREGATION_NAME_FIELD);
+        registerAggregation(MissingAggregatorBuilder::new, new MissingParser(), MissingAggregatorBuilder.AGGREGATION_NAME_FIELD);
         registerAggregation(FilterAggregatorBuilder::new, FilterAggregatorBuilder::parse, FilterAggregatorBuilder.AGGREGATION_NAME_FIELD);
         registerAggregation(FiltersAggregatorBuilder::new, (n, c) -> FiltersAggregatorBuilder.parse(queryParserRegistry, n, c),
                 FiltersAggregatorBuilder.AGGREGATION_NAME_FIELD);
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregatorBuilder.java
index 14921b358cd..833199abb37 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/bucket/global/GlobalAggregatorBuilder.java
@@ -19,40 +19,49 @@
 
 package org.elasticsearch.search.aggregations.bucket.global;
 
+import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.index.query.QueryParseContext;
 import org.elasticsearch.search.aggregations.AggregatorBuilder;
-import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
+import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.support.AggregationContext;
 
 import java.io.IOException;
 
 public class GlobalAggregatorBuilder extends AggregatorBuilder {
-
-    static final GlobalAggregatorBuilder PROTOTYPE = new GlobalAggregatorBuilder("");
+    public static final String NAME = InternalGlobal.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     public GlobalAggregatorBuilder(String name) {
         super(name, InternalGlobal.TYPE);
     }
 
+    /**
+     * Read from a stream.
+     */
+    public GlobalAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, InternalGlobal.TYPE);
+    }
+
+    @Override
+    protected void doWriteTo(StreamOutput out) throws IOException {
+        // Nothing to write
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
+    }
+
     @Override
     protected AggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, Builder subFactoriesBuilder)
             throws IOException {
         return new GlobalAggregatorFactory(name, type, context, parent, subFactoriesBuilder, metaData);
     }
 
-    @Override
-    protected GlobalAggregatorBuilder doReadFrom(String name, StreamInput in) throws IOException {
-        return new GlobalAggregatorBuilder(name);
-    }
-
-    @Override
-    protected void doWriteTo(StreamOutput out) throws IOException {
-        // Nothing to write
-    }
-
     @Override
     protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {
         builder.startObject();
@@ -60,6 +69,11 @@ public class GlobalAggregatorBuilder extends AggregatorBuilder {
-
-    static final MissingAggregatorBuilder PROTOTYPE = new MissingAggregatorBuilder("", null);
+    public static final String NAME = InternalMissing.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     public MissingAggregatorBuilder(String name, ValueType targetValueType) {
         super(name, InternalMissing.TYPE, ValuesSourceType.ANY, targetValueType);
     }
 
+    /**
+     * Read from a stream.
+     */
+    public MissingAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, InternalMissing.TYPE, ValuesSourceType.ANY);
+    }
+
+    @Override
+    protected void innerWriteTo(StreamOutput out) {
+        // Do nothing, no extra state to write to stream
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
+    }
+
+    @Override
+    protected boolean serializeTargetValueType() {
+        return true;
+    }
+
     @Override
     protected ValuesSourceAggregatorFactory innerBuild(AggregationContext context,
             ValuesSourceConfig config, AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException {
         return new MissingAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData);
     }
 
-    @Override
-    protected MissingAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType,
-            ValueType targetValueType, StreamInput in) {
-        return new MissingAggregatorBuilder(name, targetValueType);
-    }
-
-    @Override
-    protected void innerWriteTo(StreamOutput out) {
-        // Do nothing, no extra state to write to stream
-    }
-
     @Override
     public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
         return builder;
@@ -73,4 +85,9 @@ public class MissingAggregatorBuilder extends ValuesSourceAggregatorBuilder otherOptions) throws IOException {
@@ -50,9 +45,4 @@ public class MissingParser extends AnyValuesSourceParser {
             ValueType targetValueType, Map otherOptions) {
         return new MissingAggregatorBuilder(aggregationName, targetValueType);
     }
-
-    @Override
-    public MissingAggregatorBuilder getFactoryPrototypes() {
-        return MissingAggregatorBuilder.PROTOTYPE;
-    }
 }
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/CardinalityAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/CardinalityAggregatorBuilder.java
index dcdedf39688..7def3af402a 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/CardinalityAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/CardinalityAggregatorBuilder.java
@@ -23,20 +23,21 @@ import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
+import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.support.AggregationContext;
 import org.elasticsearch.search.aggregations.support.ValueType;
 import org.elasticsearch.search.aggregations.support.ValuesSource;
 import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder;
 import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
 import org.elasticsearch.search.aggregations.support.ValuesSourceType;
+
 import java.io.IOException;
 import java.util.Objects;
 
 public final class CardinalityAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly {
-
-    static final CardinalityAggregatorBuilder PROTOTYPE = new CardinalityAggregatorBuilder("", null);
+    public static final String NAME = InternalCardinality.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     public static final ParseField PRECISION_THRESHOLD_FIELD = new ParseField("precision_threshold");
 
@@ -46,6 +47,35 @@ public final class CardinalityAggregatorBuilder extends ValuesSourceAggregatorBu
         super(name, InternalCardinality.TYPE, ValuesSourceType.ANY, targetValueType);
     }
 
+    /**
+     * Read from a stream.
+     */
+    public CardinalityAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, InternalCardinality.TYPE, ValuesSourceType.ANY);
+        if (in.readBoolean()) {
+            precisionThreshold = in.readLong();
+        }
+    }
+
+    @Override
+    protected void innerWriteTo(StreamOutput out) throws IOException {
+        boolean hasPrecisionThreshold = precisionThreshold != null;
+        out.writeBoolean(hasPrecisionThreshold);
+        if (hasPrecisionThreshold) {
+            out.writeLong(precisionThreshold);
+        }
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
+    }
+
+    @Override
+    protected boolean serializeTargetValueType() {
+        return true;
+    }
+
     /**
      * Set a precision threshold. Higher values improve accuracy but also
      * increase memory usage.
@@ -82,25 +112,6 @@ public final class CardinalityAggregatorBuilder extends ValuesSourceAggregatorBu
         return new CardinalityAggregatorFactory(name, type, config, precisionThreshold, context, parent, subFactoriesBuilder, metaData);
     }
 
-    @Override
-    protected CardinalityAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType,
-            ValueType targetValueType, StreamInput in) throws IOException {
-        CardinalityAggregatorBuilder factory = new CardinalityAggregatorBuilder(name, targetValueType);
-        if (in.readBoolean()) {
-            factory.precisionThreshold = in.readLong();
-        }
-        return factory;
-    }
-
-    @Override
-    protected void innerWriteTo(StreamOutput out) throws IOException {
-        boolean hasPrecisionThreshold = precisionThreshold != null;
-        out.writeBoolean(hasPrecisionThreshold);
-        if (hasPrecisionThreshold) {
-            out.writeLong(precisionThreshold);
-        }
-    }
-
     @Override
     public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
         if (precisionThreshold != null) {
@@ -120,4 +131,8 @@ public final class CardinalityAggregatorBuilder extends ValuesSourceAggregatorBu
         return Objects.equals(precisionThreshold, other.precisionThreshold);
     }
 
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/CardinalityParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/CardinalityParser.java
index d82bb5faf4d..3272d90eede 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/CardinalityParser.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/cardinality/CardinalityParser.java
@@ -39,11 +39,6 @@ public class CardinalityParser extends AnyValuesSourceParser {
         super(true, false);
     }
 
-    @Override
-    public String type() {
-        return InternalCardinality.TYPE.name();
-    }
-
     @Override
     protected CardinalityAggregatorBuilder createFactory(String aggregationName, ValuesSourceType valuesSourceType,
             ValueType targetValueType, Map otherOptions) {
@@ -69,9 +64,4 @@ public class CardinalityParser extends AnyValuesSourceParser {
         }
         return false;
     }
-
-    @Override
-    public CardinalityAggregatorBuilder getFactoryPrototypes() {
-        return CardinalityAggregatorBuilder.PROTOTYPE;
-    }
 }
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregatorBuilder.java
index d062b45380f..823683e1a89 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountAggregatorBuilder.java
@@ -19,6 +19,7 @@
 
 package org.elasticsearch.search.aggregations.metrics.valuecount;
 
+import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
@@ -33,32 +34,42 @@ import org.elasticsearch.search.aggregations.support.ValuesSourceType;
 
 import java.io.IOException;
 
-public class ValueCountAggregatorBuilder
-        extends ValuesSourceAggregatorBuilder.LeafOnly {
-
-    static final ValueCountAggregatorBuilder PROTOTYPE = new ValueCountAggregatorBuilder("", null);
+public class ValueCountAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly {
+    public static final String NAME = InternalValueCount.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     public ValueCountAggregatorBuilder(String name, ValueType targetValueType) {
         super(name, InternalValueCount.TYPE, ValuesSourceType.ANY, targetValueType);
     }
 
+    /**
+     * Read from a stream.
+     */
+    public ValueCountAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, InternalValueCount.TYPE, ValuesSourceType.ANY);
+    }
+
+    @Override
+    protected void innerWriteTo(StreamOutput out) {
+        // Do nothing, no extra state to write to stream
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
+    }
+
+    @Override
+    protected boolean serializeTargetValueType() {
+        return true;
+    }
+
     @Override
     protected ValueCountAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config,
             AggregatorFactory parent, AggregatorFactories.Builder subFactoriesBuilder) throws IOException {
         return new ValueCountAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData);
     }
 
-    @Override
-    protected ValuesSourceAggregatorBuilder innerReadFrom(String name,
-            ValuesSourceType valuesSourceType, ValueType targetValueType, StreamInput in) {
-        return new ValueCountAggregatorBuilder(name, targetValueType);
-    }
-
-    @Override
-    protected void innerWriteTo(StreamOutput out) {
-        // Do nothing, no extra state to write to stream
-    }
-
     @Override
     public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
         return builder;
@@ -74,4 +85,8 @@ public class ValueCountAggregatorBuilder
         return true;
     }
 
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountParser.java
index 52d37d1be8c..2f0e7e6f263 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountParser.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/valuecount/ValueCountParser.java
@@ -39,11 +39,6 @@ public class ValueCountParser extends AnyValuesSourceParser {
         super(true, true);
     }
 
-    @Override
-    public String type() {
-        return InternalValueCount.TYPE.name();
-    }
-
     @Override
     protected boolean token(String aggregationName, String currentFieldName, XContentParser.Token token, XContentParser parser,
             ParseFieldMatcher parseFieldMatcher, Map otherOptions) throws IOException {
@@ -55,9 +50,4 @@ public class ValueCountParser extends AnyValuesSourceParser {
             String aggregationName, ValuesSourceType valuesSourceType, ValueType targetValueType, Map otherOptions) {
         return new ValueCountAggregatorBuilder(aggregationName, targetValueType);
     }
-
-    @Override
-    public ValueCountAggregatorBuilder getFactoryPrototypes() {
-        return ValueCountAggregatorBuilder.PROTOTYPE;
-    }
 }
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorBuilder.java
index 840befe1b23..eb1ced0b91b 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/support/ValuesSourceAggregatorBuilder.java
@@ -57,12 +57,20 @@ public abstract class ValuesSourceAggregatorBuilder
Date: Fri, 15 Apr 2016 14:47:15 -0400
Subject: [PATCH 041/561] Cut serial_diff and cumulative_sum to
 registerPipelineAggregation

and remove their PROTOTYPEs.

Relates to #17085
---
 .../elasticsearch/search/SearchModule.java    |  10 +-
 .../cumulativesum/CumulativeSumParser.java    |  99 -------------
 ...umulativeSumPipelineAggregatorBuilder.java |  95 ++++++++++--
 .../pipeline/serialdiff/SerialDiffParser.java | 123 ----------------
 .../SerialDiffPipelineAggregatorBuilder.java  | 137 +++++++++++++++---
 5 files changed, 200 insertions(+), 264 deletions(-)
 delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumParser.java
 delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffParser.java

diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java
index 1acbb41ebff..1cb75bf07fe 100644
--- a/core/src/main/java/org/elasticsearch/search/SearchModule.java
+++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java
@@ -212,8 +212,8 @@ import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptP
 import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorParser;
 import org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregator;
-import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumParser;
 import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregator;
+import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.derivative.InternalDerivative;
@@ -221,8 +221,8 @@ import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgParser;
 import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel;
 import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelParserMapper;
-import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffParser;
 import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregator;
+import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregatorBuilder;
 import org.elasticsearch.search.controller.SearchPhaseController;
 import org.elasticsearch.search.dfs.DfsPhase;
 import org.elasticsearch.search.fetch.FetchPhase;
@@ -512,10 +512,12 @@ public class SearchModule extends AbstractModule {
                 ExtendedStatsBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
         registerPipelineParser(new PercentilesBucketParser());
         registerPipelineParser(new MovAvgParser(movAvgModelParserMapper));
-        registerPipelineParser(new CumulativeSumParser());
+        registerPipelineAggregation(CumulativeSumPipelineAggregatorBuilder::new, CumulativeSumPipelineAggregatorBuilder::parse,
+                CumulativeSumPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
         registerPipelineParser(new BucketScriptParser());
         registerPipelineParser(new BucketSelectorParser());
-        registerPipelineParser(new SerialDiffParser());
+        registerPipelineAggregation(SerialDiffPipelineAggregatorBuilder::new, SerialDiffPipelineAggregatorBuilder::parse,
+                SerialDiffPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
 
         AggregationParseElement aggParseElement = new AggregationParseElement(aggregatorParsers, queryParserRegistry);
         AggregationBinaryParseElement aggBinaryParseElement = new AggregationBinaryParseElement(aggregatorParsers, queryParserRegistry);
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumParser.java
deleted file mode 100644
index 1ae71c0f017..00000000000
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumParser.java
+++ /dev/null
@@ -1,99 +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.aggregations.pipeline.cumulativesum;
-
-import org.elasticsearch.common.ParseField;
-import org.elasticsearch.common.ParsingException;
-import org.elasticsearch.common.xcontent.XContentParser;
-import org.elasticsearch.index.query.QueryParseContext;
-import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-public class CumulativeSumParser implements PipelineAggregator.Parser {
-
-    public static final ParseField FORMAT = new ParseField("format");
-    public static final ParseField GAP_POLICY = new ParseField("gap_policy");
-    public static final ParseField UNIT = new ParseField("unit");
-
-    @Override
-    public String type() {
-        return CumulativeSumPipelineAggregator.TYPE.name();
-    }
-
-    @Override
-    public CumulativeSumPipelineAggregatorBuilder parse(String pipelineAggregatorName, QueryParseContext context) throws IOException {
-        XContentParser parser = context.parser();
-        XContentParser.Token token;
-        String currentFieldName = null;
-        String[] bucketsPaths = null;
-        String format = null;
-
-        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
-            if (token == XContentParser.Token.FIELD_NAME) {
-                currentFieldName = parser.currentName();
-            } else if (token == XContentParser.Token.VALUE_STRING) {
-                if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) {
-                    format = parser.text();
-                } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
-                    bucketsPaths = new String[] { parser.text() };
-                } else {
-                    throw new ParsingException(parser.getTokenLocation(),
-                            "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
-                }
-            } else if (token == XContentParser.Token.START_ARRAY) {
-                if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
-                    List paths = new ArrayList<>();
-                    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
-                        String path = parser.text();
-                        paths.add(path);
-                    }
-                    bucketsPaths = paths.toArray(new String[paths.size()]);
-                } else {
-                    throw new ParsingException(parser.getTokenLocation(),
-                            "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
-                }
-            } else {
-                throw new ParsingException(parser.getTokenLocation(),
-                        "Unexpected token " + token + " in [" + pipelineAggregatorName + "].");
-            }
-        }
-
-        if (bucketsPaths == null) {
-            throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + BUCKETS_PATH.getPreferredName()
-                    + "] for derivative aggregation [" + pipelineAggregatorName + "]");
-        }
-
-        CumulativeSumPipelineAggregatorBuilder factory =
-                new CumulativeSumPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]);
-        if (format != null) {
-            factory.format(format);
-        }
-        return factory;
-    }
-
-    @Override
-    public CumulativeSumPipelineAggregatorBuilder getFactoryPrototype() {
-        return CumulativeSumPipelineAggregatorBuilder.PROTOTYPE;
-    }
-
-}
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregatorBuilder.java
index af772cc943a..23195401f9c 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/cumulativesum/CumulativeSumPipelineAggregatorBuilder.java
@@ -19,9 +19,13 @@
 
 package org.elasticsearch.search.aggregations.pipeline.cumulativesum;
 
+import org.elasticsearch.common.ParseField;
+import org.elasticsearch.common.ParsingException;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.index.query.QueryParseContext;
 import org.elasticsearch.search.DocValueFormat;
 import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.bucket.histogram.AbstractHistogramAggregatorFactory;
@@ -30,22 +34,40 @@ import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 
-public class CumulativeSumPipelineAggregatorBuilder extends PipelineAggregatorBuilder {
+import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.BUCKETS_PATH;
+import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.FORMAT;
 
-    static final CumulativeSumPipelineAggregatorBuilder PROTOTYPE = new CumulativeSumPipelineAggregatorBuilder("", "");
+public class CumulativeSumPipelineAggregatorBuilder extends PipelineAggregatorBuilder {
+    public static final String NAME = CumulativeSumPipelineAggregator.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     private String format;
 
     public CumulativeSumPipelineAggregatorBuilder(String name, String bucketsPath) {
-        this(name, new String[] { bucketsPath });
+        super(name, CumulativeSumPipelineAggregator.TYPE.name(), new String[] { bucketsPath });
     }
 
-    private CumulativeSumPipelineAggregatorBuilder(String name, String[] bucketsPaths) {
-        super(name, CumulativeSumPipelineAggregator.TYPE.name(), bucketsPaths);
+    /**
+     * Read from a stream.
+     */
+    public CumulativeSumPipelineAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, CumulativeSumPipelineAggregator.TYPE.name());
+        format = in.readOptionalString();
+    }
+
+    @Override
+    protected final void doWriteTo(StreamOutput out) throws IOException {
+        out.writeOptionalString(format);
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
     }
 
     /**
@@ -83,7 +105,7 @@ public class CumulativeSumPipelineAggregatorBuilder extends PipelineAggregatorBu
     public void doValidate(AggregatorFactory parent, AggregatorFactory[] aggFactories,
             List> pipelineAggregatorFactories) {
         if (bucketsPaths.length != 1) {
-            throw new IllegalStateException(PipelineAggregator.Parser.BUCKETS_PATH.getPreferredName()
+            throw new IllegalStateException(BUCKETS_PATH.getPreferredName()
                     + " must contain a single entry for aggregation [" + name + "]");
         }
         if (!(parent instanceof AbstractHistogramAggregatorFactory)) {
@@ -106,17 +128,55 @@ public class CumulativeSumPipelineAggregatorBuilder extends PipelineAggregatorBu
         return builder;
     }
 
-    @Override
-    protected final CumulativeSumPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in)
+    public static CumulativeSumPipelineAggregatorBuilder parse(String pipelineAggregatorName, QueryParseContext context)
             throws IOException {
-        CumulativeSumPipelineAggregatorBuilder factory = new CumulativeSumPipelineAggregatorBuilder(name, bucketsPaths);
-        factory.format = in.readOptionalString();
-        return factory;
-    }
+        XContentParser parser = context.parser();
+        XContentParser.Token token;
+        String currentFieldName = null;
+        String[] bucketsPaths = null;
+        String format = null;
 
-    @Override
-    protected final void doWriteTo(StreamOutput out) throws IOException {
-        out.writeOptionalString(format);
+        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
+            if (token == XContentParser.Token.FIELD_NAME) {
+                currentFieldName = parser.currentName();
+            } else if (token == XContentParser.Token.VALUE_STRING) {
+                if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) {
+                    format = parser.text();
+                } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
+                    bucketsPaths = new String[] { parser.text() };
+                } else {
+                    throw new ParsingException(parser.getTokenLocation(),
+                            "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
+                }
+            } else if (token == XContentParser.Token.START_ARRAY) {
+                if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
+                    List paths = new ArrayList<>();
+                    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
+                        String path = parser.text();
+                        paths.add(path);
+                    }
+                    bucketsPaths = paths.toArray(new String[paths.size()]);
+                } else {
+                    throw new ParsingException(parser.getTokenLocation(),
+                            "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
+                }
+            } else {
+                throw new ParsingException(parser.getTokenLocation(),
+                        "Unexpected token " + token + " in [" + pipelineAggregatorName + "].");
+            }
+        }
+
+        if (bucketsPaths == null) {
+            throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + BUCKETS_PATH.getPreferredName()
+                    + "] for derivative aggregation [" + pipelineAggregatorName + "]");
+        }
+
+        CumulativeSumPipelineAggregatorBuilder factory =
+                new CumulativeSumPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]);
+        if (format != null) {
+            factory.format(format);
+        }
+        return factory;
     }
 
     @Override
@@ -129,4 +189,9 @@ public class CumulativeSumPipelineAggregatorBuilder extends PipelineAggregatorBu
         CumulativeSumPipelineAggregatorBuilder other = (CumulativeSumPipelineAggregatorBuilder) obj;
         return Objects.equals(format, other.format);
     }
+
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffParser.java
deleted file mode 100644
index 5eb9858a6dc..00000000000
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffParser.java
+++ /dev/null
@@ -1,123 +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.aggregations.pipeline.serialdiff;
-
-import org.elasticsearch.common.ParseField;
-import org.elasticsearch.common.ParsingException;
-import org.elasticsearch.common.xcontent.XContentParser;
-import org.elasticsearch.index.query.QueryParseContext;
-import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
-import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-public class SerialDiffParser implements PipelineAggregator.Parser {
-
-    public static final ParseField FORMAT = new ParseField("format");
-    public static final ParseField GAP_POLICY = new ParseField("gap_policy");
-    public static final ParseField LAG = new ParseField("lag");
-
-    @Override
-    public String type() {
-        return SerialDiffPipelineAggregator.TYPE.name();
-    }
-
-    @Override
-    public SerialDiffPipelineAggregatorBuilder parse(String reducerName, QueryParseContext context) throws IOException {
-        XContentParser parser = context.parser();
-        XContentParser.Token token;
-        String currentFieldName = null;
-        String[] bucketsPaths = null;
-        String format = null;
-        GapPolicy gapPolicy = null;
-        Integer lag = null;
-
-        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
-            if (token == XContentParser.Token.FIELD_NAME) {
-                currentFieldName = parser.currentName();
-            } else if (token == XContentParser.Token.VALUE_STRING) {
-                if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) {
-                    format = parser.text();
-                } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
-                    bucketsPaths = new String[] { parser.text() };
-                } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) {
-                    gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
-                } else {
-                    throw new ParsingException(parser.getTokenLocation(),
-                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
-                }
-            } else if (token == XContentParser.Token.VALUE_NUMBER) {
-                if (context.getParseFieldMatcher().match(currentFieldName, LAG)) {
-                    lag = parser.intValue(true);
-                    if (lag <= 0) {
-                        throw new ParsingException(parser.getTokenLocation(),
-                                "Lag must be a positive, non-zero integer.  Value supplied was" +
-                                lag + " in [" + reducerName + "]: ["
-                                        + currentFieldName + "].");
-                    }
-                }  else {
-                    throw new ParsingException(parser.getTokenLocation(),
-                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
-                }
-            } else if (token == XContentParser.Token.START_ARRAY) {
-                if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
-                    List paths = new ArrayList<>();
-                    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
-                        String path = parser.text();
-                        paths.add(path);
-                    }
-                    bucketsPaths = paths.toArray(new String[paths.size()]);
-                } else {
-                    throw new ParsingException(parser.getTokenLocation(),
-                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
-                }
-            } else {
-                throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + reducerName + "].",
-                        parser.getTokenLocation());
-            }
-        }
-
-        if (bucketsPaths == null) {
-            throw new ParsingException(parser.getTokenLocation(),
-                    "Missing required field [" + BUCKETS_PATH.getPreferredName() + "] for derivative aggregation [" + reducerName + "]");
-        }
-
-        SerialDiffPipelineAggregatorBuilder factory =
-                new SerialDiffPipelineAggregatorBuilder(reducerName, bucketsPaths[0]);
-        if (lag != null) {
-            factory.lag(lag);
-        }
-        if (format != null) {
-            factory.format(format);
-        }
-        if (gapPolicy != null) {
-            factory.gapPolicy(gapPolicy);
-        }
-        return factory;
-    }
-
-    @Override
-    public SerialDiffPipelineAggregatorBuilder getFactoryPrototype() {
-        return SerialDiffPipelineAggregatorBuilder.PROTOTYPE;
-    }
-
-}
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregatorBuilder.java
index 5e154921b75..1bab3ddd098 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/serialdiff/SerialDiffPipelineAggregatorBuilder.java
@@ -19,32 +19,62 @@
 
 package org.elasticsearch.search.aggregations.pipeline.serialdiff;
 
+import org.elasticsearch.common.ParseField;
+import org.elasticsearch.common.ParsingException;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
-import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
+import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.index.query.QueryParseContext;
 import org.elasticsearch.search.DocValueFormat;
 import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
+import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
+import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 
-public class SerialDiffPipelineAggregatorBuilder extends PipelineAggregatorBuilder {
+import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.BUCKETS_PATH;
+import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.FORMAT;
 
-    static final SerialDiffPipelineAggregatorBuilder PROTOTYPE = new SerialDiffPipelineAggregatorBuilder("", "");
+public class SerialDiffPipelineAggregatorBuilder extends PipelineAggregatorBuilder {
+    public static final String NAME = SerialDiffPipelineAggregator.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
+
+    private static final ParseField GAP_POLICY = new ParseField("gap_policy");
+    private static final ParseField LAG = new ParseField("lag");
 
     private String format;
     private GapPolicy gapPolicy = GapPolicy.SKIP;
     private int lag = 1;
 
     public SerialDiffPipelineAggregatorBuilder(String name, String bucketsPath) {
-        this(name, new String[] { bucketsPath });
+        super(name, SerialDiffPipelineAggregator.TYPE.name(), new String[] { bucketsPath });
     }
 
-    private SerialDiffPipelineAggregatorBuilder(String name, String[] bucketsPaths) {
-        super(name, SerialDiffPipelineAggregator.TYPE.name(), bucketsPaths);
+    /**
+     * Read from a stream.
+     */
+    public SerialDiffPipelineAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, SerialDiffPipelineAggregator.TYPE.name());
+        format = in.readOptionalString();
+        gapPolicy = GapPolicy.readFrom(in);
+        lag = in.readVInt();
+    }
+
+    @Override
+    protected void doWriteTo(StreamOutput out) throws IOException {
+        out.writeOptionalString(format);
+        gapPolicy.writeTo(out);
+        out.writeVInt(lag);
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
     }
 
     /**
@@ -117,27 +147,84 @@ public class SerialDiffPipelineAggregatorBuilder extends PipelineAggregatorBuild
     @Override
     protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {
         if (format != null) {
-            builder.field(SerialDiffParser.FORMAT.getPreferredName(), format);
+            builder.field(FORMAT.getPreferredName(), format);
         }
-        builder.field(SerialDiffParser.GAP_POLICY.getPreferredName(), gapPolicy.getName());
-        builder.field(SerialDiffParser.LAG.getPreferredName(), lag);
+        builder.field(GAP_POLICY.getPreferredName(), gapPolicy.getName());
+        builder.field(LAG.getPreferredName(), lag);
         return builder;
     }
 
-    @Override
-    protected SerialDiffPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException {
-        SerialDiffPipelineAggregatorBuilder factory = new SerialDiffPipelineAggregatorBuilder(name, bucketsPaths);
-        factory.format = in.readOptionalString();
-        factory.gapPolicy = GapPolicy.readFrom(in);
-        factory.lag = in.readVInt();
-        return factory;
-    }
+    public static SerialDiffPipelineAggregatorBuilder parse(String reducerName, QueryParseContext context) throws IOException {
+        XContentParser parser = context.parser();
+        XContentParser.Token token;
+        String currentFieldName = null;
+        String[] bucketsPaths = null;
+        String format = null;
+        GapPolicy gapPolicy = null;
+        Integer lag = null;
 
-    @Override
-    protected void doWriteTo(StreamOutput out) throws IOException {
-        out.writeOptionalString(format);
-        gapPolicy.writeTo(out);
-        out.writeVInt(lag);
+        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
+            if (token == XContentParser.Token.FIELD_NAME) {
+                currentFieldName = parser.currentName();
+            } else if (token == XContentParser.Token.VALUE_STRING) {
+                if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) {
+                    format = parser.text();
+                } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
+                    bucketsPaths = new String[] { parser.text() };
+                } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) {
+                    gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
+                } else {
+                    throw new ParsingException(parser.getTokenLocation(),
+                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
+                }
+            } else if (token == XContentParser.Token.VALUE_NUMBER) {
+                if (context.getParseFieldMatcher().match(currentFieldName, LAG)) {
+                    lag = parser.intValue(true);
+                    if (lag <= 0) {
+                        throw new ParsingException(parser.getTokenLocation(),
+                                "Lag must be a positive, non-zero integer.  Value supplied was" +
+                                lag + " in [" + reducerName + "]: ["
+                                        + currentFieldName + "].");
+                    }
+                }  else {
+                    throw new ParsingException(parser.getTokenLocation(),
+                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
+                }
+            } else if (token == XContentParser.Token.START_ARRAY) {
+                if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
+                    List paths = new ArrayList<>();
+                    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
+                        String path = parser.text();
+                        paths.add(path);
+                    }
+                    bucketsPaths = paths.toArray(new String[paths.size()]);
+                } else {
+                    throw new ParsingException(parser.getTokenLocation(),
+                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
+                }
+            } else {
+                throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + reducerName + "].",
+                        parser.getTokenLocation());
+            }
+        }
+
+        if (bucketsPaths == null) {
+            throw new ParsingException(parser.getTokenLocation(),
+                    "Missing required field [" + BUCKETS_PATH.getPreferredName() + "] for derivative aggregation [" + reducerName + "]");
+        }
+
+        SerialDiffPipelineAggregatorBuilder factory =
+                new SerialDiffPipelineAggregatorBuilder(reducerName, bucketsPaths[0]);
+        if (lag != null) {
+            factory.lag(lag);
+        }
+        if (format != null) {
+            factory.format(format);
+        }
+        if (gapPolicy != null) {
+            factory.gapPolicy(gapPolicy);
+        }
+        return factory;
     }
 
     @Override
@@ -152,4 +239,8 @@ public class SerialDiffPipelineAggregatorBuilder extends PipelineAggregatorBuild
                 && Objects.equals(lag, other.lag);
     }
 
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file

From b8003de4097f58de5f12fa2e9e476476d0156e1c Mon Sep 17 00:00:00 2001
From: Nik Everett 
Date: Fri, 15 Apr 2016 15:49:07 -0400
Subject: [PATCH 042/561] Cut bucket_script and bucket_selector to
 registerPipelineAggregation

and remove their PROTOTYPEs.

Relates to #17085
---
 .../elasticsearch/search/SearchModule.java    |  10 +-
 .../bucketscript/BucketScriptParser.java      | 134 --------------
 ...BucketScriptPipelineAggregatorBuilder.java | 168 ++++++++++++++----
 .../bucketselector/BucketSelectorParser.java  | 129 --------------
 ...cketSelectorPipelineAggregatorBuilder.java | 155 ++++++++++++----
 5 files changed, 262 insertions(+), 334 deletions(-)
 delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptParser.java
 delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorParser.java

diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java
index 1cb75bf07fe..4ea307580b6 100644
--- a/core/src/main/java/org/elasticsearch/search/SearchModule.java
+++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java
@@ -208,10 +208,10 @@ import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extend
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketParser;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregator;
-import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptParser;
 import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregator;
-import org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorParser;
+import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregator;
+import org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSumPipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregator;
@@ -514,8 +514,10 @@ public class SearchModule extends AbstractModule {
         registerPipelineParser(new MovAvgParser(movAvgModelParserMapper));
         registerPipelineAggregation(CumulativeSumPipelineAggregatorBuilder::new, CumulativeSumPipelineAggregatorBuilder::parse,
                 CumulativeSumPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
-        registerPipelineParser(new BucketScriptParser());
-        registerPipelineParser(new BucketSelectorParser());
+        registerPipelineAggregation(BucketScriptPipelineAggregatorBuilder::new, BucketScriptPipelineAggregatorBuilder::parse,
+                BucketScriptPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
+        registerPipelineAggregation(BucketSelectorPipelineAggregatorBuilder::new, BucketSelectorPipelineAggregatorBuilder::parse,
+                BucketSelectorPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
         registerPipelineAggregation(SerialDiffPipelineAggregatorBuilder::new, SerialDiffPipelineAggregatorBuilder::parse,
                 SerialDiffPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
 
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptParser.java
deleted file mode 100644
index 9ec7cd40527..00000000000
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptParser.java
+++ /dev/null
@@ -1,134 +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.aggregations.pipeline.bucketscript;
-
-import org.elasticsearch.common.ParseField;
-import org.elasticsearch.common.ParsingException;
-import org.elasticsearch.common.xcontent.XContentParser;
-import org.elasticsearch.index.query.QueryParseContext;
-import org.elasticsearch.script.Script;
-import org.elasticsearch.script.Script.ScriptField;
-import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
-import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class BucketScriptParser implements PipelineAggregator.Parser {
-
-    public static final ParseField FORMAT = new ParseField("format");
-    public static final ParseField GAP_POLICY = new ParseField("gap_policy");
-    public static final ParseField PARAMS_FIELD = new ParseField("params");
-
-    @Override
-    public String type() {
-        return BucketScriptPipelineAggregator.TYPE.name();
-    }
-
-    @Override
-    public BucketScriptPipelineAggregatorBuilder parse(String reducerName, QueryParseContext context) throws IOException {
-        XContentParser parser = context.parser();
-        XContentParser.Token token;
-        Script script = null;
-        String currentFieldName = null;
-        Map bucketsPathsMap = null;
-        String format = null;
-        GapPolicy gapPolicy = null;
-
-        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
-            if (token == XContentParser.Token.FIELD_NAME) {
-                currentFieldName = parser.currentName();
-            } else if (token == XContentParser.Token.VALUE_STRING) {
-                if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) {
-                    format = parser.text();
-                } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
-                    bucketsPathsMap = new HashMap<>();
-                    bucketsPathsMap.put("_value", parser.text());
-                } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) {
-                    gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
-                } else if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
-                    script = Script.parse(parser, context.getParseFieldMatcher());
-                } else {
-                    throw new ParsingException(parser.getTokenLocation(),
-                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
-                }
-            } else if (token == XContentParser.Token.START_ARRAY) {
-                if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
-                    List paths = new ArrayList<>();
-                    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
-                        String path = parser.text();
-                        paths.add(path);
-                    }
-                    bucketsPathsMap = new HashMap<>();
-                    for (int i = 0; i < paths.size(); i++) {
-                        bucketsPathsMap.put("_value" + i, paths.get(i));
-                    }
-                } else {
-                    throw new ParsingException(parser.getTokenLocation(),
-                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
-                }
-            } else if (token == XContentParser.Token.START_OBJECT) {
-                if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
-                    script = Script.parse(parser, context.getParseFieldMatcher());
-                } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
-                    Map map = parser.map();
-                    bucketsPathsMap = new HashMap<>();
-                    for (Map.Entry entry : map.entrySet()) {
-                        bucketsPathsMap.put(entry.getKey(), String.valueOf(entry.getValue()));
-                    }
-                } else {
-                    throw new ParsingException(parser.getTokenLocation(),
-                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
-                }
-            } else {
-                throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + reducerName + "].");
-            }
-        }
-
-        if (bucketsPathsMap == null) {
-            throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + BUCKETS_PATH.getPreferredName()
-                    + "] for series_arithmetic aggregation [" + reducerName + "]");
-        }
-
-        if (script == null) {
-            throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + ScriptField.SCRIPT.getPreferredName()
-                    + "] for series_arithmetic aggregation [" + reducerName + "]");
-        }
-
-        BucketScriptPipelineAggregatorBuilder factory =
-                new BucketScriptPipelineAggregatorBuilder(reducerName, bucketsPathsMap, script);
-        if (format != null) {
-            factory.format(format);
-        }
-        if (gapPolicy != null) {
-            factory.gapPolicy(gapPolicy);
-        }
-        return factory;
-    }
-
-    @Override
-    public BucketScriptPipelineAggregatorBuilder getFactoryPrototype() {
-        return BucketScriptPipelineAggregatorBuilder.PROTOTYPE;
-    }
-
-}
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregatorBuilder.java
index cdc17f19bb1..ee0e915d7d6 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketscript/BucketScriptPipelineAggregatorBuilder.java
@@ -19,28 +19,36 @@
 
 package org.elasticsearch.search.aggregations.pipeline.bucketscript;
 
+import org.elasticsearch.common.ParseField;
+import org.elasticsearch.common.ParsingException;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.index.query.QueryParseContext;
 import org.elasticsearch.script.Script;
 import org.elasticsearch.script.Script.ScriptField;
+import org.elasticsearch.search.DocValueFormat;
 import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
-import org.elasticsearch.search.DocValueFormat;
 
 import java.io.IOException;
-import java.util.Collections;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Objects;
 import java.util.TreeMap;
 
-public class BucketScriptPipelineAggregatorBuilder extends PipelineAggregatorBuilder {
+import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.BUCKETS_PATH;
+import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.FORMAT;
+import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.GAP_POLICY;
 
-    static final BucketScriptPipelineAggregatorBuilder PROTOTYPE = new BucketScriptPipelineAggregatorBuilder("", Collections.emptyMap(),
-            new Script(""));
+public class BucketScriptPipelineAggregatorBuilder extends PipelineAggregatorBuilder {
+    public static final String NAME = BucketScriptPipelineAggregator.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     private final Script script;
     private final Map bucketsPathsMap;
@@ -58,6 +66,38 @@ public class BucketScriptPipelineAggregatorBuilder extends PipelineAggregatorBui
         this(name, convertToBucketsPathMap(bucketsPaths), script);
     }
 
+    /**
+     * Read from a stream.
+     */
+    public BucketScriptPipelineAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, BucketScriptPipelineAggregator.TYPE.name());
+        int mapSize = in.readVInt();
+        bucketsPathsMap = new HashMap(mapSize);
+        for (int i = 0; i < mapSize; i++) {
+            bucketsPathsMap.put(in.readString(), in.readString());
+        }
+        script = Script.readScript(in);
+        format = in.readOptionalString();
+        gapPolicy = GapPolicy.readFrom(in);
+    }
+
+    @Override
+    protected void doWriteTo(StreamOutput out) throws IOException {
+        out.writeVInt(bucketsPathsMap.size());
+        for (Entry e : bucketsPathsMap.entrySet()) {
+            out.writeString(e.getKey());
+            out.writeString(e.getValue());
+        }
+        script.writeTo(out);
+        out.writeOptionalString(format);
+        gapPolicy.writeTo(out);
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
+    }
+
     private static Map convertToBucketsPathMap(String[] bucketsPaths) {
         Map bucketsPathsMap = new HashMap<>();
         for (int i = 0; i < bucketsPaths.length; i++) {
@@ -117,46 +157,101 @@ public class BucketScriptPipelineAggregatorBuilder extends PipelineAggregatorBui
 
     @Override
     protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {
-        builder.field(BucketScriptParser.BUCKETS_PATH.getPreferredName(), bucketsPathsMap);
+        builder.field(BUCKETS_PATH.getPreferredName(), bucketsPathsMap);
         builder.field(ScriptField.SCRIPT.getPreferredName(), script);
         if (format != null) {
-            builder.field(BucketScriptParser.FORMAT.getPreferredName(), format);
+            builder.field(FORMAT.getPreferredName(), format);
         }
-        builder.field(BucketScriptParser.GAP_POLICY.getPreferredName(), gapPolicy.getName());
+        builder.field(GAP_POLICY.getPreferredName(), gapPolicy.getName());
         return builder;
     }
 
+    public static BucketScriptPipelineAggregatorBuilder parse(String reducerName, QueryParseContext context) throws IOException {
+        XContentParser parser = context.parser();
+        XContentParser.Token token;
+        Script script = null;
+        String currentFieldName = null;
+        Map bucketsPathsMap = null;
+        String format = null;
+        GapPolicy gapPolicy = null;
+
+        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
+            if (token == XContentParser.Token.FIELD_NAME) {
+                currentFieldName = parser.currentName();
+            } else if (token == XContentParser.Token.VALUE_STRING) {
+                if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) {
+                    format = parser.text();
+                } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
+                    bucketsPathsMap = new HashMap<>();
+                    bucketsPathsMap.put("_value", parser.text());
+                } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) {
+                    gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
+                } else if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
+                    script = Script.parse(parser, context.getParseFieldMatcher());
+                } else {
+                    throw new ParsingException(parser.getTokenLocation(),
+                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
+                }
+            } else if (token == XContentParser.Token.START_ARRAY) {
+                if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
+                    List paths = new ArrayList<>();
+                    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
+                        String path = parser.text();
+                        paths.add(path);
+                    }
+                    bucketsPathsMap = new HashMap<>();
+                    for (int i = 0; i < paths.size(); i++) {
+                        bucketsPathsMap.put("_value" + i, paths.get(i));
+                    }
+                } else {
+                    throw new ParsingException(parser.getTokenLocation(),
+                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
+                }
+            } else if (token == XContentParser.Token.START_OBJECT) {
+                if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
+                    script = Script.parse(parser, context.getParseFieldMatcher());
+                } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
+                    Map map = parser.map();
+                    bucketsPathsMap = new HashMap<>();
+                    for (Map.Entry entry : map.entrySet()) {
+                        bucketsPathsMap.put(entry.getKey(), String.valueOf(entry.getValue()));
+                    }
+                } else {
+                    throw new ParsingException(parser.getTokenLocation(),
+                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
+                }
+            } else {
+                throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + reducerName + "].");
+            }
+        }
+
+        if (bucketsPathsMap == null) {
+            throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + BUCKETS_PATH.getPreferredName()
+                    + "] for series_arithmetic aggregation [" + reducerName + "]");
+        }
+
+        if (script == null) {
+            throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + ScriptField.SCRIPT.getPreferredName()
+                    + "] for series_arithmetic aggregation [" + reducerName + "]");
+        }
+
+        BucketScriptPipelineAggregatorBuilder factory =
+                new BucketScriptPipelineAggregatorBuilder(reducerName, bucketsPathsMap, script);
+        if (format != null) {
+            factory.format(format);
+        }
+        if (gapPolicy != null) {
+            factory.gapPolicy(gapPolicy);
+        }
+        return factory;
+    }
+
+
     @Override
     protected boolean overrideBucketsPath() {
         return true;
     }
 
-    @Override
-    protected BucketScriptPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException {
-        Map bucketsPathsMap = new HashMap();
-        int mapSize = in.readVInt();
-        for (int i = 0; i < mapSize; i++) {
-            bucketsPathsMap.put(in.readString(), in.readString());
-        }
-        Script script = Script.readScript(in);
-        BucketScriptPipelineAggregatorBuilder factory = new BucketScriptPipelineAggregatorBuilder(name, bucketsPathsMap, script);
-        factory.format = in.readOptionalString();
-        factory.gapPolicy = GapPolicy.readFrom(in);
-        return factory;
-    }
-
-    @Override
-    protected void doWriteTo(StreamOutput out) throws IOException {
-        out.writeVInt(bucketsPathsMap.size());
-        for (Entry e : bucketsPathsMap.entrySet()) {
-            out.writeString(e.getKey());
-            out.writeString(e.getValue());
-        }
-        script.writeTo(out);
-        out.writeOptionalString(format);
-        gapPolicy.writeTo(out);
-    }
-
     @Override
     protected int doHashCode() {
         return Objects.hash(bucketsPathsMap, script, format, gapPolicy);
@@ -168,4 +263,9 @@ public class BucketScriptPipelineAggregatorBuilder extends PipelineAggregatorBui
         return Objects.equals(bucketsPathsMap, other.bucketsPathsMap) && Objects.equals(script, other.script)
                 && Objects.equals(format, other.format) && Objects.equals(gapPolicy, other.gapPolicy);
     }
+
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorParser.java
deleted file mode 100644
index 320331afac4..00000000000
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorParser.java
+++ /dev/null
@@ -1,129 +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.aggregations.pipeline.bucketselector;
-
-import org.elasticsearch.common.ParseField;
-import org.elasticsearch.common.ParsingException;
-import org.elasticsearch.common.xcontent.XContentParser;
-import org.elasticsearch.index.query.QueryParseContext;
-import org.elasticsearch.script.Script;
-import org.elasticsearch.script.Script.ScriptField;
-import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
-import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-public class BucketSelectorParser implements PipelineAggregator.Parser {
-
-    public static final ParseField FORMAT = new ParseField("format");
-    public static final ParseField GAP_POLICY = new ParseField("gap_policy");
-    public static final ParseField PARAMS_FIELD = new ParseField("params");
-
-    @Override
-    public String type() {
-        return BucketSelectorPipelineAggregator.TYPE.name();
-    }
-
-    @Override
-    public BucketSelectorPipelineAggregatorBuilder parse(String reducerName, QueryParseContext context) throws IOException {
-        XContentParser parser = context.parser();
-        XContentParser.Token token;
-        Script script = null;
-        String currentFieldName = null;
-        Map bucketsPathsMap = null;
-        GapPolicy gapPolicy = null;
-
-        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
-            if (token == XContentParser.Token.FIELD_NAME) {
-                currentFieldName = parser.currentName();
-            } else if (token == XContentParser.Token.VALUE_STRING) {
-                if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
-                    bucketsPathsMap = new HashMap<>();
-                    bucketsPathsMap.put("_value", parser.text());
-                } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) {
-                    gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
-                } else if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
-                    script = Script.parse(parser, context.getParseFieldMatcher());
-                } else {
-                    throw new ParsingException(parser.getTokenLocation(),
-                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
-                }
-            } else if (token == XContentParser.Token.START_ARRAY) {
-                if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
-                    List paths = new ArrayList<>();
-                    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
-                        String path = parser.text();
-                        paths.add(path);
-                    }
-                    bucketsPathsMap = new HashMap<>();
-                    for (int i = 0; i < paths.size(); i++) {
-                        bucketsPathsMap.put("_value" + i, paths.get(i));
-                    }
-                } else {
-                    throw new ParsingException(parser.getTokenLocation(),
-                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
-                }
-            } else if (token == XContentParser.Token.START_OBJECT) {
-                if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
-                    script = Script.parse(parser, context.getParseFieldMatcher());
-                } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
-                    Map map = parser.map();
-                    bucketsPathsMap = new HashMap<>();
-                    for (Map.Entry entry : map.entrySet()) {
-                        bucketsPathsMap.put(entry.getKey(), String.valueOf(entry.getValue()));
-                    }
-                } else {
-                    throw new ParsingException(parser.getTokenLocation(),
-                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
-                }
-            } else {
-                throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + reducerName + "].");
-            }
-        }
-
-        if (bucketsPathsMap == null) {
-            throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + BUCKETS_PATH.getPreferredName()
-                    + "] for bucket_selector aggregation [" + reducerName + "]");
-        }
-
-        if (script == null) {
-            throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + ScriptField.SCRIPT.getPreferredName()
-                    + "] for bucket_selector aggregation [" + reducerName + "]");
-        }
-
-        BucketSelectorPipelineAggregatorBuilder factory =
-                new BucketSelectorPipelineAggregatorBuilder(reducerName, bucketsPathsMap, script);
-        if (gapPolicy != null) {
-            factory.gapPolicy(gapPolicy);
-        }
-        return factory;
-
-    }
-
-    @Override
-    public BucketSelectorPipelineAggregatorBuilder getFactoryPrototype() {
-        return BucketSelectorPipelineAggregatorBuilder.PROTOTYPE;
-    }
-
-}
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregatorBuilder.java
index 0e2ca8e6928..b45e28b9d23 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketselector/BucketSelectorPipelineAggregatorBuilder.java
@@ -19,32 +19,38 @@
 
 package org.elasticsearch.search.aggregations.pipeline.bucketselector;
 
+import org.elasticsearch.common.ParseField;
+import org.elasticsearch.common.ParsingException;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.index.query.QueryParseContext;
 import org.elasticsearch.script.Script;
 import org.elasticsearch.script.Script.ScriptField;
 import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
-import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptParser;
 
 import java.io.IOException;
-import java.util.Collections;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Objects;
 import java.util.TreeMap;
 
+import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.BUCKETS_PATH;
+import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.GAP_POLICY;
+
 public class BucketSelectorPipelineAggregatorBuilder extends PipelineAggregatorBuilder {
+    public static final String NAME = BucketSelectorPipelineAggregator.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
-    static final BucketSelectorPipelineAggregatorBuilder PROTOTYPE = new BucketSelectorPipelineAggregatorBuilder("",
-            Collections.emptyMap(), new Script(""));
-
+    private final Map bucketsPathsMap;
     private Script script;
     private GapPolicy gapPolicy = GapPolicy.SKIP;
-    private final Map bucketsPathsMap;
 
     public BucketSelectorPipelineAggregatorBuilder(String name, Map bucketsPathsMap, Script script) {
         super(name, BucketSelectorPipelineAggregator.TYPE.name(), new TreeMap<>(bucketsPathsMap).values()
@@ -57,6 +63,36 @@ public class BucketSelectorPipelineAggregatorBuilder extends PipelineAggregatorB
         this(name, convertToBucketsPathMap(bucketsPaths), script);
     }
 
+    /**
+     * Read from a stream.
+     */
+    public BucketSelectorPipelineAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, BucketSelectorPipelineAggregator.TYPE.name());
+        int mapSize = in.readVInt();
+        bucketsPathsMap = new HashMap(mapSize);
+        for (int i = 0; i < mapSize; i++) {
+            bucketsPathsMap.put(in.readString(), in.readString());
+        }
+        script = Script.readScript(in);
+        gapPolicy = GapPolicy.readFrom(in);
+    }
+
+    @Override
+    protected void doWriteTo(StreamOutput out) throws IOException {
+        out.writeVInt(bucketsPathsMap.size());
+        for (Entry e : bucketsPathsMap.entrySet()) {
+            out.writeString(e.getKey());
+            out.writeString(e.getValue());
+        }
+        script.writeTo(out);
+        gapPolicy.writeTo(out);
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
+    }
+
     private static Map convertToBucketsPathMap(String[] bucketsPaths) {
         Map bucketsPathsMap = new HashMap<>();
         for (int i = 0; i < bucketsPaths.length; i++) {
@@ -90,42 +126,91 @@ public class BucketSelectorPipelineAggregatorBuilder extends PipelineAggregatorB
 
     @Override
     protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {
-        builder.field(BucketScriptParser.BUCKETS_PATH.getPreferredName(), bucketsPathsMap);
+        builder.field(BUCKETS_PATH.getPreferredName(), bucketsPathsMap);
         builder.field(ScriptField.SCRIPT.getPreferredName(), script);
-        builder.field(BucketScriptParser.GAP_POLICY.getPreferredName(), gapPolicy.getName());
+        builder.field(GAP_POLICY.getPreferredName(), gapPolicy.getName());
         return builder;
     }
 
+    public static BucketSelectorPipelineAggregatorBuilder parse(String reducerName, QueryParseContext context) throws IOException {
+        XContentParser parser = context.parser();
+        XContentParser.Token token;
+        Script script = null;
+        String currentFieldName = null;
+        Map bucketsPathsMap = null;
+        GapPolicy gapPolicy = null;
+
+        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
+            if (token == XContentParser.Token.FIELD_NAME) {
+                currentFieldName = parser.currentName();
+            } else if (token == XContentParser.Token.VALUE_STRING) {
+                if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
+                    bucketsPathsMap = new HashMap<>();
+                    bucketsPathsMap.put("_value", parser.text());
+                } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) {
+                    gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
+                } else if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
+                    script = Script.parse(parser, context.getParseFieldMatcher());
+                } else {
+                    throw new ParsingException(parser.getTokenLocation(),
+                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
+                }
+            } else if (token == XContentParser.Token.START_ARRAY) {
+                if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
+                    List paths = new ArrayList<>();
+                    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
+                        String path = parser.text();
+                        paths.add(path);
+                    }
+                    bucketsPathsMap = new HashMap<>();
+                    for (int i = 0; i < paths.size(); i++) {
+                        bucketsPathsMap.put("_value" + i, paths.get(i));
+                    }
+                } else {
+                    throw new ParsingException(parser.getTokenLocation(),
+                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
+                }
+            } else if (token == XContentParser.Token.START_OBJECT) {
+                if (context.getParseFieldMatcher().match(currentFieldName, ScriptField.SCRIPT)) {
+                    script = Script.parse(parser, context.getParseFieldMatcher());
+                } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
+                    Map map = parser.map();
+                    bucketsPathsMap = new HashMap<>();
+                    for (Map.Entry entry : map.entrySet()) {
+                        bucketsPathsMap.put(entry.getKey(), String.valueOf(entry.getValue()));
+                    }
+                } else {
+                    throw new ParsingException(parser.getTokenLocation(),
+                            "Unknown key for a " + token + " in [" + reducerName + "]: [" + currentFieldName + "].");
+                }
+            } else {
+                throw new ParsingException(parser.getTokenLocation(), "Unexpected token " + token + " in [" + reducerName + "].");
+            }
+        }
+
+        if (bucketsPathsMap == null) {
+            throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + BUCKETS_PATH.getPreferredName()
+                    + "] for bucket_selector aggregation [" + reducerName + "]");
+        }
+
+        if (script == null) {
+            throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + ScriptField.SCRIPT.getPreferredName()
+                    + "] for bucket_selector aggregation [" + reducerName + "]");
+        }
+
+        BucketSelectorPipelineAggregatorBuilder factory =
+                new BucketSelectorPipelineAggregatorBuilder(reducerName, bucketsPathsMap, script);
+        if (gapPolicy != null) {
+            factory.gapPolicy(gapPolicy);
+        }
+        return factory;
+    }
+
     @Override
     protected boolean overrideBucketsPath() {
         return true;
     }
 
-    @Override
-    protected BucketSelectorPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in)
-            throws IOException {
-        Map bucketsPathsMap = new HashMap();
-        int mapSize = in.readVInt();
-        for (int i = 0; i < mapSize; i++) {
-            bucketsPathsMap.put(in.readString(), in.readString());
-        }
-        Script script = Script.readScript(in);
-        BucketSelectorPipelineAggregatorBuilder factory = new BucketSelectorPipelineAggregatorBuilder(name, bucketsPathsMap, script);
-        factory.gapPolicy = GapPolicy.readFrom(in);
-        return factory;
-    }
-
-    @Override
-    protected void doWriteTo(StreamOutput out) throws IOException {
-        out.writeVInt(bucketsPathsMap.size());
-        for (Entry e : bucketsPathsMap.entrySet()) {
-            out.writeString(e.getKey());
-            out.writeString(e.getValue());
-        }
-        script.writeTo(out);
-        gapPolicy.writeTo(out);
-    }
-
     @Override
     protected int doHashCode() {
         return Objects.hash(bucketsPathsMap, script, gapPolicy);
@@ -138,4 +223,8 @@ public class BucketSelectorPipelineAggregatorBuilder extends PipelineAggregatorB
                 && Objects.equals(gapPolicy, other.gapPolicy);
     }
 
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file

From 08d3bf937df002a1d8278123588e41b565bc8014 Mon Sep 17 00:00:00 2001
From: Nik Everett 
Date: Fri, 15 Apr 2016 16:03:38 -0400
Subject: [PATCH 043/561] Cut moving_avg aggregation to
 registerPipelineAggregation

and remove its PROTOTYPE.

Relates to #17085
---
 .../elasticsearch/search/SearchModule.java    |   6 +-
 .../pipeline/movavg/MovAvgParser.java         | 183 ----------------
 .../MovAvgPipelineAggregatorBuilder.java      | 203 +++++++++++++++---
 .../pipeline/movavg/models/EwmaModel.java     |  10 +-
 .../movavg/models/HoltLinearModel.java        |  10 +-
 .../movavg/models/HoltWintersModel.java       |  10 +-
 .../pipeline/movavg/models/LinearModel.java   |   6 +-
 .../models/MovAvgModelParserMapper.java       |   2 -
 .../pipeline/movavg/models/SimpleModel.java   |   6 +-
 9 files changed, 198 insertions(+), 238 deletions(-)
 delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java

diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java
index 4ea307580b6..443e232bcd9 100644
--- a/core/src/main/java/org/elasticsearch/search/SearchModule.java
+++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java
@@ -217,8 +217,8 @@ import org.elasticsearch.search.aggregations.pipeline.cumulativesum.CumulativeSu
 import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.derivative.DerivativePipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.derivative.InternalDerivative;
-import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgParser;
 import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregator;
+import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel;
 import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelParserMapper;
 import org.elasticsearch.search.aggregations.pipeline.serialdiff.SerialDiffPipelineAggregator;
@@ -511,7 +511,9 @@ public class SearchModule extends AbstractModule {
         registerPipelineAggregation(ExtendedStatsBucketPipelineAggregatorBuilder::new, new ExtendedStatsBucketParser(),
                 ExtendedStatsBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
         registerPipelineParser(new PercentilesBucketParser());
-        registerPipelineParser(new MovAvgParser(movAvgModelParserMapper));
+        registerPipelineAggregation(MovAvgPipelineAggregatorBuilder::new,
+                (n, c) -> MovAvgPipelineAggregatorBuilder.parse(movAvgModelParserMapper, n, c),
+                MovAvgPipelineAggregatorBuilder.AGGREGATION_FIELD_NAME);
         registerPipelineAggregation(CumulativeSumPipelineAggregatorBuilder::new, CumulativeSumPipelineAggregatorBuilder::parse,
                 CumulativeSumPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
         registerPipelineAggregation(BucketScriptPipelineAggregatorBuilder::new, BucketScriptPipelineAggregatorBuilder::parse,
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java
deleted file mode 100644
index 1c63099c745..00000000000
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgParser.java
+++ /dev/null
@@ -1,183 +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.aggregations.pipeline.movavg;
-
-import org.elasticsearch.common.ParseField;
-import org.elasticsearch.common.ParsingException;
-import org.elasticsearch.common.inject.Inject;
-import org.elasticsearch.common.xcontent.XContentParser;
-import org.elasticsearch.index.query.QueryParseContext;
-import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
-import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
-import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel;
-import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelParserMapper;
-
-import java.io.IOException;
-import java.text.ParseException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-public class MovAvgParser implements PipelineAggregator.Parser {
-
-    public static final ParseField MODEL = new ParseField("model");
-    public static final ParseField WINDOW = new ParseField("window");
-    public static final ParseField SETTINGS = new ParseField("settings");
-    public static final ParseField PREDICT = new ParseField("predict");
-    public static final ParseField MINIMIZE = new ParseField("minimize");
-
-    private final MovAvgModelParserMapper movAvgModelParserMapper;
-
-    @Inject
-    public MovAvgParser(MovAvgModelParserMapper movAvgModelParserMapper) {
-        this.movAvgModelParserMapper = movAvgModelParserMapper;
-    }
-
-    @Override
-    public String type() {
-        return MovAvgPipelineAggregator.TYPE.name();
-    }
-
-    @Override
-    public MovAvgPipelineAggregatorBuilder parse(String pipelineAggregatorName, QueryParseContext context) throws IOException {
-        XContentParser parser = context.parser();
-        XContentParser.Token token;
-        String currentFieldName = null;
-        String[] bucketsPaths = null;
-        String format = null;
-
-        GapPolicy gapPolicy = null;
-        Integer window = null;
-        Map settings = null;
-        String model = null;
-        Integer predict = null;
-        Boolean minimize = null;
-
-        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
-            if (token == XContentParser.Token.FIELD_NAME) {
-                currentFieldName = parser.currentName();
-            } else if (token == XContentParser.Token.VALUE_NUMBER) {
-                if (context.getParseFieldMatcher().match(currentFieldName, WINDOW)) {
-                    window = parser.intValue();
-                    if (window <= 0) {
-                        throw new ParsingException(parser.getTokenLocation(), "[" + currentFieldName + "] value must be a positive, "
-                                + "non-zero integer.  Value supplied was [" + predict + "] in [" + pipelineAggregatorName + "].");
-                    }
-                } else if (context.getParseFieldMatcher().match(currentFieldName, PREDICT)) {
-                    predict = parser.intValue();
-                    if (predict <= 0) {
-                        throw new ParsingException(parser.getTokenLocation(), "[" + currentFieldName + "] value must be a positive integer."
-                                + "  Value supplied was [" + predict + "] in [" + pipelineAggregatorName + "].");
-                    }
-                } else {
-                    throw new ParsingException(parser.getTokenLocation(),
-                            "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
-                }
-            } else if (token == XContentParser.Token.VALUE_STRING) {
-                if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) {
-                    format = parser.text();
-                } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
-                    bucketsPaths = new String[] { parser.text() };
-                } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) {
-                    gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
-                } else if (context.getParseFieldMatcher().match(currentFieldName, MODEL)) {
-                    model = parser.text();
-                } else {
-                    throw new ParsingException(parser.getTokenLocation(),
-                            "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
-                }
-            } else if (token == XContentParser.Token.START_ARRAY) {
-                if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
-                    List paths = new ArrayList<>();
-                    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
-                        String path = parser.text();
-                        paths.add(path);
-                    }
-                    bucketsPaths = paths.toArray(new String[paths.size()]);
-                } else {
-                    throw new ParsingException(parser.getTokenLocation(),
-                            "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
-                }
-            } else if (token == XContentParser.Token.START_OBJECT) {
-                if (context.getParseFieldMatcher().match(currentFieldName, SETTINGS)) {
-                    settings = parser.map();
-                } else {
-                    throw new ParsingException(parser.getTokenLocation(),
-                            "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
-                }
-            } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
-                if (context.getParseFieldMatcher().match(currentFieldName, MINIMIZE)) {
-                    minimize = parser.booleanValue();
-                } else {
-                    throw new ParsingException(parser.getTokenLocation(),
-                            "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
-                }
-            } else {
-                throw new ParsingException(parser.getTokenLocation(),
-                        "Unexpected token " + token + " in [" + pipelineAggregatorName + "].");
-            }
-        }
-
-        if (bucketsPaths == null) {
-            throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + BUCKETS_PATH.getPreferredName()
-                    + "] for movingAvg aggregation [" + pipelineAggregatorName + "]");
-        }
-
-        MovAvgPipelineAggregatorBuilder factory =
-                new MovAvgPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]);
-        if (format != null) {
-            factory.format(format);
-        }
-        if (gapPolicy != null) {
-            factory.gapPolicy(gapPolicy);
-        }
-        if (window != null) {
-            factory.window(window);
-        }
-        if (predict != null) {
-            factory.predict(predict);
-        }
-        if (model != null) {
-            MovAvgModel.AbstractModelParser modelParser = movAvgModelParserMapper.get(model);
-            if (modelParser == null) {
-                throw new ParsingException(parser.getTokenLocation(),
-                        "Unknown model [" + model + "] specified.  Valid options are:" + movAvgModelParserMapper.getAllNames().toString());
-            }
-
-            MovAvgModel movAvgModel;
-            try {
-                movAvgModel = modelParser.parse(settings, pipelineAggregatorName, factory.window(), context.getParseFieldMatcher());
-            } catch (ParseException exception) {
-                throw new ParsingException(parser.getTokenLocation(), "Could not parse settings for model [" + model + "].", exception);
-            }
-            factory.model(movAvgModel);
-        }
-        if (minimize != null) {
-            factory.minimize(minimize);
-        }
-        return factory;
-    }
-
-    @Override
-    public MovAvgPipelineAggregatorBuilder getFactoryPrototype() {
-        return MovAvgPipelineAggregatorBuilder.PROTOTYPE;
-    }
-
-}
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregatorBuilder.java
index 2decd08954e..d9b66aa2175 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/MovAvgPipelineAggregatorBuilder.java
@@ -19,28 +19,45 @@
 
 package org.elasticsearch.search.aggregations.pipeline.movavg;
 
+import org.elasticsearch.common.ParseField;
+import org.elasticsearch.common.ParsingException;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
+import org.elasticsearch.common.xcontent.XContentParser;
+import org.elasticsearch.index.query.QueryParseContext;
 import org.elasticsearch.search.DocValueFormat;
 import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.bucket.histogram.AbstractHistogramAggregatorFactory;
+import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
-import org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy;
 import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModel;
 import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelBuilder;
+import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelParserMapper;
 import org.elasticsearch.search.aggregations.pipeline.movavg.models.MovAvgModelStreams;
 import org.elasticsearch.search.aggregations.pipeline.movavg.models.SimpleModel;
 
 import java.io.IOException;
+import java.text.ParseException;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 
-public class MovAvgPipelineAggregatorBuilder extends PipelineAggregatorBuilder {
+import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.BUCKETS_PATH;
+import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.FORMAT;
+import static org.elasticsearch.search.aggregations.pipeline.PipelineAggregator.Parser.GAP_POLICY;
 
-    static final MovAvgPipelineAggregatorBuilder PROTOTYPE = new MovAvgPipelineAggregatorBuilder("", "");
+public class MovAvgPipelineAggregatorBuilder extends PipelineAggregatorBuilder {
+    public static final String NAME = MovAvgPipelineAggregator.TYPE.name();
+    public static final ParseField AGGREGATION_FIELD_NAME = new ParseField(NAME);
+
+    public static final ParseField MODEL = new ParseField("model");
+    private static final ParseField WINDOW = new ParseField("window");
+    public static final ParseField SETTINGS = new ParseField("settings");
+    private static final ParseField PREDICT = new ParseField("predict");
+    private static final ParseField MINIMIZE = new ParseField("minimize");
 
     private String format;
     private GapPolicy gapPolicy = GapPolicy.SKIP;
@@ -50,11 +67,35 @@ public class MovAvgPipelineAggregatorBuilder extends PipelineAggregatorBuilder 0) {
-            builder.field(MovAvgParser.PREDICT.getPreferredName(), predict);
+            builder.field(PREDICT.getPreferredName(), predict);
         }
         if (minimize != null) {
-            builder.field(MovAvgParser.MINIMIZE.getPreferredName(), minimize);
+            builder.field(MINIMIZE.getPreferredName(), minimize);
         }
         return builder;
     }
 
-    @Override
-    protected MovAvgPipelineAggregatorBuilder doReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException {
-        MovAvgPipelineAggregatorBuilder factory = new MovAvgPipelineAggregatorBuilder(name, bucketsPaths);
-        factory.format = in.readOptionalString();
-        factory.gapPolicy = GapPolicy.readFrom(in);
-        factory.window = in.readVInt();
-        factory.model = MovAvgModelStreams.read(in);
-        factory.predict = in.readVInt();
-        factory.minimize = in.readOptionalBoolean();
-        return factory;
-    }
+    public static MovAvgPipelineAggregatorBuilder parse(MovAvgModelParserMapper movAvgModelParserMapper, String pipelineAggregatorName,
+            QueryParseContext context) throws IOException {
+        XContentParser parser = context.parser();
+        XContentParser.Token token;
+        String currentFieldName = null;
+        String[] bucketsPaths = null;
+        String format = null;
 
-    @Override
-    protected void doWriteTo(StreamOutput out) throws IOException {
-        out.writeOptionalString(format);
-        gapPolicy.writeTo(out);
-        out.writeVInt(window);
-        model.writeTo(out);
-        out.writeVInt(predict);
-        out.writeOptionalBoolean(minimize);
+        GapPolicy gapPolicy = null;
+        Integer window = null;
+        Map settings = null;
+        String model = null;
+        Integer predict = null;
+        Boolean minimize = null;
+
+        while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
+            if (token == XContentParser.Token.FIELD_NAME) {
+                currentFieldName = parser.currentName();
+            } else if (token == XContentParser.Token.VALUE_NUMBER) {
+                if (context.getParseFieldMatcher().match(currentFieldName, WINDOW)) {
+                    window = parser.intValue();
+                    if (window <= 0) {
+                        throw new ParsingException(parser.getTokenLocation(), "[" + currentFieldName + "] value must be a positive, "
+                                + "non-zero integer.  Value supplied was [" + predict + "] in [" + pipelineAggregatorName + "].");
+                    }
+                } else if (context.getParseFieldMatcher().match(currentFieldName, PREDICT)) {
+                    predict = parser.intValue();
+                    if (predict <= 0) {
+                        throw new ParsingException(parser.getTokenLocation(), "[" + currentFieldName + "] value must be a positive integer."
+                                + "  Value supplied was [" + predict + "] in [" + pipelineAggregatorName + "].");
+                    }
+                } else {
+                    throw new ParsingException(parser.getTokenLocation(),
+                            "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
+                }
+            } else if (token == XContentParser.Token.VALUE_STRING) {
+                if (context.getParseFieldMatcher().match(currentFieldName, FORMAT)) {
+                    format = parser.text();
+                } else if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
+                    bucketsPaths = new String[] { parser.text() };
+                } else if (context.getParseFieldMatcher().match(currentFieldName, GAP_POLICY)) {
+                    gapPolicy = GapPolicy.parse(context, parser.text(), parser.getTokenLocation());
+                } else if (context.getParseFieldMatcher().match(currentFieldName, MODEL)) {
+                    model = parser.text();
+                } else {
+                    throw new ParsingException(parser.getTokenLocation(),
+                            "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
+                }
+            } else if (token == XContentParser.Token.START_ARRAY) {
+                if (context.getParseFieldMatcher().match(currentFieldName, BUCKETS_PATH)) {
+                    List paths = new ArrayList<>();
+                    while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
+                        String path = parser.text();
+                        paths.add(path);
+                    }
+                    bucketsPaths = paths.toArray(new String[paths.size()]);
+                } else {
+                    throw new ParsingException(parser.getTokenLocation(),
+                            "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
+                }
+            } else if (token == XContentParser.Token.START_OBJECT) {
+                if (context.getParseFieldMatcher().match(currentFieldName, SETTINGS)) {
+                    settings = parser.map();
+                } else {
+                    throw new ParsingException(parser.getTokenLocation(),
+                            "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
+                }
+            } else if (token == XContentParser.Token.VALUE_BOOLEAN) {
+                if (context.getParseFieldMatcher().match(currentFieldName, MINIMIZE)) {
+                    minimize = parser.booleanValue();
+                } else {
+                    throw new ParsingException(parser.getTokenLocation(),
+                            "Unknown key for a " + token + " in [" + pipelineAggregatorName + "]: [" + currentFieldName + "].");
+                }
+            } else {
+                throw new ParsingException(parser.getTokenLocation(),
+                        "Unexpected token " + token + " in [" + pipelineAggregatorName + "].");
+            }
+        }
+
+        if (bucketsPaths == null) {
+            throw new ParsingException(parser.getTokenLocation(), "Missing required field [" + BUCKETS_PATH.getPreferredName()
+                    + "] for movingAvg aggregation [" + pipelineAggregatorName + "]");
+        }
+
+        MovAvgPipelineAggregatorBuilder factory =
+                new MovAvgPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPaths[0]);
+        if (format != null) {
+            factory.format(format);
+        }
+        if (gapPolicy != null) {
+            factory.gapPolicy(gapPolicy);
+        }
+        if (window != null) {
+            factory.window(window);
+        }
+        if (predict != null) {
+            factory.predict(predict);
+        }
+        if (model != null) {
+            MovAvgModel.AbstractModelParser modelParser = movAvgModelParserMapper.get(model);
+            if (modelParser == null) {
+                throw new ParsingException(parser.getTokenLocation(),
+                        "Unknown model [" + model + "] specified.  Valid options are:" + movAvgModelParserMapper.getAllNames().toString());
+            }
+
+            MovAvgModel movAvgModel;
+            try {
+                movAvgModel = modelParser.parse(settings, pipelineAggregatorName, factory.window(), context.getParseFieldMatcher());
+            } catch (ParseException exception) {
+                throw new ParsingException(parser.getTokenLocation(), "Could not parse settings for model [" + model + "].", exception);
+            }
+            factory.model(movAvgModel);
+        }
+        if (minimize != null) {
+            factory.minimize(minimize);
+        }
+        return factory;
     }
 
     @Override
@@ -298,4 +437,8 @@ public class MovAvgPipelineAggregatorBuilder extends PipelineAggregatorBuilder movAvgParsers;
 
-    @Inject
     public MovAvgModelParserMapper(Set parsers) {
         Map map = new HashMap<>();
         add(map, new SimpleModel.SimpleModelParser());
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/SimpleModel.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/SimpleModel.java
index 61f8c668e1a..7fb3b4e7b99 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/SimpleModel.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/movavg/models/SimpleModel.java
@@ -25,7 +25,7 @@ import org.elasticsearch.common.ParseFieldMatcher;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgParser;
+import org.elasticsearch.search.aggregations.pipeline.movavg.MovAvgPipelineAggregatorBuilder;
 
 import java.io.IOException;
 import java.text.ParseException;
@@ -90,7 +90,7 @@ public class SimpleModel extends MovAvgModel {
 
     @Override
     public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
-        builder.field(MovAvgParser.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
+        builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
         return builder;
     }
 
@@ -122,7 +122,7 @@ public class SimpleModel extends MovAvgModel {
     public static class SimpleModelBuilder implements MovAvgModelBuilder {
         @Override
         public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
-            builder.field(MovAvgParser.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
+            builder.field(MovAvgPipelineAggregatorBuilder.MODEL.getPreferredName(), NAME_FIELD.getPreferredName());
             return builder;
         }
 

From e06e122f9fa2363b67b3162406717b4356efbf77 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Christoph=20B=C3=BCscher?= 
Date: Mon, 18 Apr 2016 15:24:08 +0200
Subject: [PATCH 044/561] Wrap xcontent parser creation in try-with-resource
 statement where possible

---
 .../indices/create/CreateIndexRequest.java    |  6 +-
 .../template/put/PutIndexTemplateRequest.java |  9 ++-
 .../elasticsearch/cluster/ClusterState.java   | 13 +++--
 .../cluster/metadata/AliasMetaData.java       |  8 +--
 .../cluster/metadata/AliasValidator.java      |  6 +-
 .../cluster/metadata/IndexMetaData.java       |  9 +--
 .../metadata/IndexTemplateMetaData.java       |  7 ++-
 .../gateway/MetaDataStateFormat.java          |  6 +-
 .../index/query/GeoShapeQueryBuilder.java     |  8 +--
 .../index/query/MoreLikeThisQueryBuilder.java |  9 +--
 .../index/query/PercolatorQueryBuilder.java   |  9 +--
 .../functionscore/DecayFunctionBuilder.java   | 12 ++--
 .../RestRenderSearchTemplateAction.java       | 57 ++++++++++---------
 .../elasticsearch/script/ScriptService.java   |  3 +-
 .../elasticsearch/search/SearchService.java   |  4 ++
 .../search/builder/SearchSourceBuilder.java   |  7 ++-
 .../CompletionSuggestionBuilder.java          |  7 ++-
 .../index/reindex/RestReindexAction.java      | 21 +++----
 18 files changed, 108 insertions(+), 93 deletions(-)

diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java
index 39e3673868a..43d45672aec 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/create/CreateIndexRequest.java
@@ -21,7 +21,6 @@ package org.elasticsearch.action.admin.indices.create;
 
 import org.elasticsearch.ElasticsearchGenerationException;
 import org.elasticsearch.ElasticsearchParseException;
-import org.elasticsearch.action.ActionRequest;
 import org.elasticsearch.action.ActionRequestValidationException;
 import org.elasticsearch.action.IndicesRequest;
 import org.elasticsearch.action.admin.indices.alias.Alias;
@@ -49,9 +48,9 @@ import java.util.Map;
 import java.util.Set;
 
 import static org.elasticsearch.action.ValidateActions.addValidationError;
-import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS;
 import static org.elasticsearch.common.settings.Settings.readSettingsFromStream;
 import static org.elasticsearch.common.settings.Settings.writeSettingsToStream;
+import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS;
 
 /**
  * A request to create an index. Best created with {@link org.elasticsearch.client.Requests#createIndexRequest(String)}.
@@ -305,8 +304,7 @@ public class CreateIndexRequest extends AcknowledgedRequest
      * Sets the aliases that will be associated with the index when it gets created
      */
     public CreateIndexRequest aliases(BytesReference source) {
-        try {
-            XContentParser parser = XContentHelper.createParser(source);
+        try (XContentParser parser = XContentHelper.createParser(source)) {
             //move to the first alias
             parser.nextToken();
             while ((parser.nextToken()) != XContentParser.Token.END_OBJECT) {
diff --git a/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java b/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java
index 94d436d57d8..76c665c7b8f 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/indices/template/put/PutIndexTemplateRequest.java
@@ -47,9 +47,9 @@ import java.util.Map;
 import java.util.Set;
 
 import static org.elasticsearch.action.ValidateActions.addValidationError;
-import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS;
 import static org.elasticsearch.common.settings.Settings.readSettingsFromStream;
 import static org.elasticsearch.common.settings.Settings.writeSettingsToStream;
+import static org.elasticsearch.common.settings.Settings.Builder.EMPTY_SETTINGS;
 
 /**
  * A request to create an index template.
@@ -71,7 +71,7 @@ public class PutIndexTemplateRequest extends MasterNodeRequest mappings = new HashMap<>();
 
     private final Set aliases = new HashSet<>();
-    
+
     private Map customs = new HashMap<>();
 
     public PutIndexTemplateRequest() {
@@ -356,7 +356,7 @@ public class PutIndexTemplateRequest extends MasterNodeRequest customs() {
         return this.customs;
     }
-       
+
     public Set aliases() {
         return this.aliases;
     }
@@ -393,8 +393,7 @@ public class PutIndexTemplateRequest extends MasterNodeRequest {
                 builder.startObject("mappings");
                 for (ObjectObjectCursor cursor1 : templateMetaData.mappings()) {
                     byte[] mappingSource = cursor1.value.uncompressed();
-                    XContentParser parser = XContentFactory.xContent(mappingSource).createParser(mappingSource);
-                    Map mapping = parser.map();
+                    Map mapping;
+                    try (XContentParser parser = XContentFactory.xContent(mappingSource).createParser(mappingSource)) {
+                        mapping = parser.map();
+                    }
                     if (mapping.size() == 1 && mapping.containsKey(cursor1.key)) {
                         // the type name is the root value, reduce it
                         mapping = (Map) mapping.get(cursor1.key);
@@ -470,8 +473,10 @@ public class ClusterState implements ToXContent, Diffable {
                 builder.startObject("mappings");
                 for (ObjectObjectCursor cursor : indexMetaData.getMappings()) {
                     byte[] mappingSource = cursor.value.source().uncompressed();
-                    XContentParser parser = XContentFactory.xContent(mappingSource).createParser(mappingSource);
-                    Map mapping = parser.map();
+                    Map mapping;
+                    try (XContentParser parser = XContentFactory.xContent(mappingSource).createParser(mappingSource)) {
+                        mapping = parser.map();
+                    }
                     if (mapping.size() == 1 && mapping.containsKey(cursor.key)) {
                         // the type name is the root value, reduce it
                         mapping = (Map) mapping.get(cursor.key);
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java
index c083396482e..d6d13b55bd7 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/AliasMetaData.java
@@ -290,10 +290,10 @@ public class AliasMetaData extends AbstractDiffable {
                     builder.field("filter", aliasMetaData.filter.compressed());
                 } else {
                     byte[] data = aliasMetaData.filter().uncompressed();
-                    XContentParser parser = XContentFactory.xContent(data).createParser(data);
-                    Map filter = parser.mapOrdered();
-                    parser.close();
-                    builder.field("filter", filter);
+                    try (XContentParser parser = XContentFactory.xContent(data).createParser(data)) {
+                        Map filter = parser.mapOrdered();
+                        builder.field("filter", filter);
+                    }
                 }
             }
             if (aliasMetaData.indexRouting() != null) {
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/AliasValidator.java b/core/src/main/java/org/elasticsearch/cluster/metadata/AliasValidator.java
index dd8da761dfc..a3d776a4edb 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/AliasValidator.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/AliasValidator.java
@@ -118,8 +118,7 @@ public class AliasValidator extends AbstractComponent {
      */
     public void validateAliasFilter(String alias, String filter, QueryShardContext queryShardContext) {
         assert queryShardContext != null;
-        try {
-            XContentParser parser = XContentFactory.xContent(filter).createParser(filter);
+        try (XContentParser parser = XContentFactory.xContent(filter).createParser(filter)) {
             validateAliasFilter(parser, queryShardContext);
         } catch (Throwable e) {
             throw new IllegalArgumentException("failed to parse filter for alias [" + alias + "]", e);
@@ -133,8 +132,7 @@ public class AliasValidator extends AbstractComponent {
      */
     public void validateAliasFilter(String alias, byte[] filter, QueryShardContext queryShardContext) {
         assert queryShardContext != null;
-        try {
-            XContentParser parser = XContentFactory.xContent(filter).createParser(filter);
+        try (XContentParser parser = XContentFactory.xContent(filter).createParser(filter)) {
             validateAliasFilter(parser, queryShardContext);
         } catch (Throwable e) {
             throw new IllegalArgumentException("failed to parse filter for alias [" + alias + "]", e);
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java
index d493e3f9031..7d99f8fd74d 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexMetaData.java
@@ -23,6 +23,7 @@ import com.carrotsearch.hppc.LongArrayList;
 import com.carrotsearch.hppc.cursors.IntObjectCursor;
 import com.carrotsearch.hppc.cursors.ObjectCursor;
 import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
+
 import org.elasticsearch.Version;
 import org.elasticsearch.cluster.Diff;
 import org.elasticsearch.cluster.Diffable;
@@ -927,10 +928,10 @@ public class IndexMetaData implements Diffable, FromXContentBuild
                     builder.value(cursor.value.source().compressed());
                 } else {
                     byte[] data = cursor.value.source().uncompressed();
-                    XContentParser parser = XContentFactory.xContent(data).createParser(data);
-                    Map mapping = parser.mapOrdered();
-                    parser.close();
-                    builder.map(mapping);
+                    try (XContentParser parser = XContentFactory.xContent(data).createParser(data)) {
+                        Map mapping = parser.mapOrdered();
+                        builder.map(mapping);
+                    }
                 }
             }
             builder.endArray();
diff --git a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java
index 6ae9a6746e5..dce78a3dda4 100644
--- a/core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java
+++ b/core/src/main/java/org/elasticsearch/cluster/metadata/IndexTemplateMetaData.java
@@ -20,6 +20,7 @@ package org.elasticsearch.cluster.metadata;
 
 import com.carrotsearch.hppc.cursors.ObjectCursor;
 import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
+
 import org.elasticsearch.cluster.AbstractDiffable;
 import org.elasticsearch.common.collect.ImmutableOpenMap;
 import org.elasticsearch.common.collect.MapBuilder;
@@ -329,8 +330,10 @@ public class IndexTemplateMetaData extends AbstractDiffable cursor : indexTemplateMetaData.mappings()) {
                     byte[] mappingSource = cursor.value.uncompressed();
-                    XContentParser parser = XContentFactory.xContent(mappingSource).createParser(mappingSource);
-                    Map mapping = parser.map();
+                    Map mapping;
+                    try (XContentParser parser = XContentFactory.xContent(mappingSource).createParser(mappingSource)) {;
+                        mapping = parser.map();
+                    }
                     if (mapping.size() == 1 && mapping.containsKey(cursor.key)) {
                         // the type name is the root value, reduce it
                         mapping = (Map) mapping.get(cursor.key);
diff --git a/core/src/main/java/org/elasticsearch/gateway/MetaDataStateFormat.java b/core/src/main/java/org/elasticsearch/gateway/MetaDataStateFormat.java
index 8795a7e7d15..9a78925368e 100644
--- a/core/src/main/java/org/elasticsearch/gateway/MetaDataStateFormat.java
+++ b/core/src/main/java/org/elasticsearch/gateway/MetaDataStateFormat.java
@@ -295,15 +295,15 @@ public abstract class MetaDataStateFormat {
             try {
                 final Path stateFile = pathAndStateId.file;
                 final long id = pathAndStateId.id;
-                final XContentParser parser;
                 if (pathAndStateId.legacy) { // read the legacy format -- plain XContent
                     final byte[] data = Files.readAllBytes(stateFile);
                     if (data.length == 0) {
                         logger.debug("{}: no data for [{}], ignoring...", prefix, stateFile.toAbsolutePath());
                         continue;
                     }
-                    parser = XContentHelper.createParser(new BytesArray(data));
-                    state = fromXContent(parser);
+                    try (final XContentParser parser = XContentHelper.createParser(new BytesArray(data))) {
+                        state = fromXContent(parser);
+                    }
                     if (state == null) {
                         logger.debug("{}: no data for [{}], ignoring...", prefix, stateFile.toAbsolutePath());
                     }
diff --git a/core/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java
index 9f7b83c543e..e1734394e5b 100644
--- a/core/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java
+++ b/core/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java
@@ -382,9 +382,7 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder
     public void doXContent(XContentBuilder builder, Params params) throws IOException {
         builder.startObject(getName());
         builder.field(fieldName);
-        XContentParser parser = XContentFactory.xContent(functionBytes).createParser(functionBytes);
-        builder.copyCurrentStructure(parser);
+        try (XContentParser parser = XContentFactory.xContent(functionBytes).createParser(functionBytes)) {
+            builder.copyCurrentStructure(parser);
+        }
         builder.field(DecayFunctionParser.MULTI_VALUE_MODE.getPreferredName(), multiValueMode.name());
         builder.endObject();
     }
@@ -181,8 +182,11 @@ public abstract class DecayFunctionBuilder
 
     @Override
     protected ScoreFunction doToFunction(QueryShardContext context) throws IOException {
-        XContentParser parser = XContentFactory.xContent(functionBytes).createParser(functionBytes);
-        return parseVariable(fieldName, parser, context, multiValueMode);
+        AbstractDistanceScoreFunction scoreFunction;
+        try (XContentParser parser = XContentFactory.xContent(functionBytes).createParser(functionBytes)) {
+            scoreFunction = parseVariable(fieldName, parser, context, multiValueMode);
+        }
+        return scoreFunction;
     }
 
     /**
diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/template/RestRenderSearchTemplateAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/template/RestRenderSearchTemplateAction.java
index f1308657528..1cbe7b95816 100644
--- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/template/RestRenderSearchTemplateAction.java
+++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/template/RestRenderSearchTemplateAction.java
@@ -63,35 +63,40 @@ public class RestRenderSearchTemplateAction extends BaseRestHandler {
     protected void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception {
         RenderSearchTemplateRequest renderSearchTemplateRequest;
         BytesReference source = RestActions.getRestContent(request);
-        XContentParser parser = XContentFactory.xContent(source).createParser(source);
-        String templateId = request.param("id");
-        final Template template;
-        if (templateId == null) {
-            template = Template.parse(parser, parseFieldMatcher);
-        } else {
-            Map params = null;
-            String currentFieldName = null;
-            XContentParser.Token token = parser.nextToken();
-            if (token != XContentParser.Token.START_OBJECT) {
-                throw new ElasticsearchParseException("failed to parse request. request body must be an object but found [{}] instead", token);
-            }
-            while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
-                if (token == XContentParser.Token.FIELD_NAME) {
-                    currentFieldName = parser.currentName();
-                } else if (parseFieldMatcher.match(currentFieldName, ScriptField.PARAMS)) {
-                    if (token == XContentParser.Token.START_OBJECT) {
-                        params = parser.map();
-                    } else {
-                        throw new ElasticsearchParseException("failed to parse request. field [{}] is expected to be an object, but found [{}] instead", currentFieldName, token);
-                    }
-                } else {
-                    throw new ElasticsearchParseException("failed to parse request. unknown field [{}] of type [{}]", currentFieldName, token);
+        try (XContentParser parser = XContentFactory.xContent(source).createParser(source)) {
+            String templateId = request.param("id");
+            final Template template;
+            if (templateId == null) {
+                template = Template.parse(parser, parseFieldMatcher);
+            } else {
+                Map params = null;
+                String currentFieldName = null;
+                XContentParser.Token token = parser.nextToken();
+                if (token != XContentParser.Token.START_OBJECT) {
+                    throw new ElasticsearchParseException("failed to parse request. request body must be an object but found [{}] instead",
+                            token);
                 }
+                while ((token = parser.nextToken()) != XContentParser.Token.END_OBJECT) {
+                    if (token == XContentParser.Token.FIELD_NAME) {
+                        currentFieldName = parser.currentName();
+                    } else if (parseFieldMatcher.match(currentFieldName, ScriptField.PARAMS)) {
+                        if (token == XContentParser.Token.START_OBJECT) {
+                            params = parser.map();
+                        } else {
+                            throw new ElasticsearchParseException(
+                                    "failed to parse request. field [{}] is expected to be an object, but found [{}] instead",
+                                    currentFieldName, token);
+                        }
+                    } else {
+                        throw new ElasticsearchParseException("failed to parse request. unknown field [{}] of type [{}]", currentFieldName,
+                                token);
+                    }
+                }
+                template = new Template(templateId, ScriptType.INDEXED, Template.DEFAULT_LANG, null, params);
             }
-            template = new Template(templateId, ScriptType.INDEXED, Template.DEFAULT_LANG, null, params);
+            renderSearchTemplateRequest = new RenderSearchTemplateRequest();
+            renderSearchTemplateRequest.template(template);
         }
-        renderSearchTemplateRequest = new RenderSearchTemplateRequest();
-        renderSearchTemplateRequest.template(template);
         client.admin().cluster().renderSearchTemplate(renderSearchTemplateRequest, new RestBuilderListener(channel) {
 
             @Override
diff --git a/core/src/main/java/org/elasticsearch/script/ScriptService.java b/core/src/main/java/org/elasticsearch/script/ScriptService.java
index 8d37783d7c2..fc375901607 100644
--- a/core/src/main/java/org/elasticsearch/script/ScriptService.java
+++ b/core/src/main/java/org/elasticsearch/script/ScriptService.java
@@ -361,8 +361,7 @@ public class ScriptService extends AbstractComponent implements Closeable {
     }
 
     private void validate(BytesReference scriptBytes, String scriptLang) {
-        try {
-            XContentParser parser = XContentFactory.xContent(scriptBytes).createParser(scriptBytes);
+        try (XContentParser parser = XContentFactory.xContent(scriptBytes).createParser(scriptBytes)) {
             parser.nextToken();
             Template template = TemplateQueryBuilder.parse(scriptLang, parser, parseFieldMatcher, "params", "script", "template");
             if (Strings.hasLength(template.getScript())) {
diff --git a/core/src/main/java/org/elasticsearch/search/SearchService.java b/core/src/main/java/org/elasticsearch/search/SearchService.java
index 7f2cd4c4c1b..c03a13b5ee7 100644
--- a/core/src/main/java/org/elasticsearch/search/SearchService.java
+++ b/core/src/main/java/org/elasticsearch/search/SearchService.java
@@ -811,6 +811,10 @@ public class SearchService extends AbstractLifecycleComponent imp
                 }
                 XContentLocation location = extParser != null ? extParser.getTokenLocation() : null;
                 throw new SearchParseException(context, "failed to parse ext source [" + sSource + "]", location, e);
+            } finally {
+                if (extParser != null) {
+                    extParser.close();
+                }
             }
         }
         if (source.version() != null) {
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 a39d0273c2f..3675320184b 100644
--- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java
@@ -1257,9 +1257,10 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ
 
         if (ext != null) {
             builder.field(EXT_FIELD.getPreferredName());
-            XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(ext);
-            parser.nextToken();
-            builder.copyCurrentStructure(parser);
+            try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(ext)) {
+                parser.nextToken();
+                builder.copyCurrentStructure(parser);
+            }
         }
     }
 
diff --git a/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java b/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java
index ce75351dfb5..2d9307a8820 100644
--- a/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java
@@ -255,9 +255,10 @@ public class CompletionSuggestionBuilder extends SuggestionBuilder destParser = new ObjectParser<>("dest");

From c5bad1d93f546bbfe67f9cb3310fe9d3293e6809 Mon Sep 17 00:00:00 2001
From: Nik Everett 
Date: Mon, 18 Apr 2016 10:10:33 -0400
Subject: [PATCH 045/561] Cut remaining pipeline aggregations
 registerPipelineAggregation

Relates to #17085
---
 .../elasticsearch/search/SearchModule.java    | 25 +++---
 .../bucketmetrics/avg/AvgBucketParser.java    | 42 ---------
 .../AvgBucketPipelineAggregatorBuilder.java   | 45 +++++++---
 .../bucketmetrics/max/MaxBucketParser.java    | 44 ----------
 .../MaxBucketPipelineAggregatorBuilder.java   | 49 +++++++----
 .../bucketmetrics/min/MinBucketParser.java    | 44 ----------
 .../MinBucketPipelineAggregatorBuilder.java   | 49 +++++++----
 .../percentile/PercentilesBucketParser.java   | 78 -----------------
 ...ntilesBucketPipelineAggregatorBuilder.java | 85 +++++++++++++++----
 .../bucketmetrics/sum/SumBucketParser.java    | 42 ---------
 .../SumBucketPipelineAggregatorBuilder.java   | 49 +++++++----
 11 files changed, 209 insertions(+), 343 deletions(-)
 delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketParser.java
 delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketParser.java
 delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketParser.java
 delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketParser.java
 delete mode 100644 core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketParser.java

diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java
index 443e232bcd9..4efe49d9c23 100644
--- a/core/src/main/java/org/elasticsearch/search/SearchModule.java
+++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java
@@ -193,21 +193,21 @@ import org.elasticsearch.search.aggregations.pipeline.InternalSimpleValue;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.InternalBucketMetricValue;
-import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketParser;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregator;
-import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketParser;
+import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg.AvgBucketPipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregator;
-import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketParser;
+import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max.MaxBucketPipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregator;
-import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketParser;
+import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min.MinBucketPipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregator;
+import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucketPipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.StatsBucketPipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketParser;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucketPipelineAggregatorBuilder;
-import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketParser;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregator;
+import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum.SumBucketPipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.bucketscript.BucketScriptPipelineAggregatorBuilder;
 import org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregator;
@@ -502,15 +502,20 @@ public class SearchModule extends AbstractModule {
 
         registerPipelineAggregation(DerivativePipelineAggregatorBuilder::new, DerivativePipelineAggregatorBuilder::parse,
                 DerivativePipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
-        registerPipelineParser(new MaxBucketParser());
-        registerPipelineParser(new MinBucketParser());
-        registerPipelineParser(new AvgBucketParser());
-        registerPipelineParser(new SumBucketParser());
+        registerPipelineAggregation(MaxBucketPipelineAggregatorBuilder::new, MaxBucketPipelineAggregatorBuilder.PARSER,
+                MaxBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
+        registerPipelineAggregation(MinBucketPipelineAggregatorBuilder::new, MinBucketPipelineAggregatorBuilder.PARSER,
+                MinBucketPipelineAggregatorBuilder.AGGREGATION_FIELD_NAME);
+        registerPipelineAggregation(AvgBucketPipelineAggregatorBuilder::new, AvgBucketPipelineAggregatorBuilder.PARSER,
+                AvgBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
+        registerPipelineAggregation(SumBucketPipelineAggregatorBuilder::new, SumBucketPipelineAggregatorBuilder.PARSER,
+                SumBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
         registerPipelineAggregation(StatsBucketPipelineAggregatorBuilder::new, StatsBucketPipelineAggregatorBuilder.PARSER,
                 StatsBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
         registerPipelineAggregation(ExtendedStatsBucketPipelineAggregatorBuilder::new, new ExtendedStatsBucketParser(),
                 ExtendedStatsBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
-        registerPipelineParser(new PercentilesBucketParser());
+        registerPipelineAggregation(PercentilesBucketPipelineAggregatorBuilder::new, PercentilesBucketPipelineAggregatorBuilder.PARSER,
+                PercentilesBucketPipelineAggregatorBuilder.AGGREGATION_NAME_FIELD);
         registerPipelineAggregation(MovAvgPipelineAggregatorBuilder::new,
                 (n, c) -> MovAvgPipelineAggregatorBuilder.parse(movAvgModelParserMapper, n, c),
                 MovAvgPipelineAggregatorBuilder.AGGREGATION_FIELD_NAME);
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketParser.java
deleted file mode 100644
index f352f7ab289..00000000000
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketParser.java
+++ /dev/null
@@ -1,42 +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.aggregations.pipeline.bucketmetrics.avg;
-
-import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
-
-import java.util.Map;
-
-public class AvgBucketParser extends BucketMetricsParser {
-    @Override
-    public String type() {
-        return AvgBucketPipelineAggregator.TYPE.name();
-    }
-
-    @Override
-    protected AvgBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath,
-            Map unparsedParams) {
-        return new AvgBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath);
-    }
-
-    @Override
-    public AvgBucketPipelineAggregatorBuilder getFactoryPrototype() {
-        return AvgBucketPipelineAggregatorBuilder.PROTOTYPE;
-    }
-}
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregatorBuilder.java
index 1d62dfe10d7..49ea65d3310 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/avg/AvgBucketPipelineAggregatorBuilder.java
@@ -19,12 +19,14 @@
 
 package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.avg;
 
+import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
+import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder;
 
 import java.io.IOException;
@@ -32,15 +34,28 @@ import java.util.List;
 import java.util.Map;
 
 public class AvgBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder {
-
-    static final AvgBucketPipelineAggregatorBuilder PROTOTYPE = new AvgBucketPipelineAggregatorBuilder("", "");
+    public static final String NAME = AvgBucketPipelineAggregator.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     public AvgBucketPipelineAggregatorBuilder(String name, String bucketsPath) {
-        this(name, new String[] { bucketsPath });
+        super(name, AvgBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath });
     }
 
-    private AvgBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) {
-        super(name, AvgBucketPipelineAggregator.TYPE.name(), bucketsPaths);
+    /**
+     * Read from a stream.
+     */
+    public AvgBucketPipelineAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, NAME);
+    }
+
+    @Override
+    protected void innerWriteTo(StreamOutput out) throws IOException {
+        // Do nothing, no extra state to write to stream
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
     }
 
     @Override
@@ -62,15 +77,13 @@ public class AvgBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAgg
         return builder;
     }
 
-    @Override
-    protected AvgBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in) throws IOException {
-        return new AvgBucketPipelineAggregatorBuilder(name, bucketsPaths);
-    }
-
-    @Override
-    protected void innerWriteTo(StreamOutput out) throws IOException {
-        // Do nothing, no extra state to write to stream
-    }
+    public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() {
+        @Override
+        protected AvgBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName,
+                String bucketsPath, Map unparsedParams) {
+            return new AvgBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath);
+        }
+    };
 
     @Override
     protected int innerHashCode() {
@@ -82,4 +95,8 @@ public class AvgBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAgg
         return true;
     }
 
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketParser.java
deleted file mode 100644
index 51393e7e082..00000000000
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketParser.java
+++ /dev/null
@@ -1,44 +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.aggregations.pipeline.bucketmetrics.max;
-
-import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
-
-import java.util.Map;
-
-public class MaxBucketParser extends BucketMetricsParser {
-
-    @Override
-    public String type() {
-        return MaxBucketPipelineAggregator.TYPE.name();
-    }
-
-    @Override
-    protected MaxBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath,
-            Map unparsedParams) {
-        return new MaxBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath);
-    }
-
-    @Override
-    public MaxBucketPipelineAggregatorBuilder getFactoryPrototype() {
-        return MaxBucketPipelineAggregatorBuilder.PROTOTYPE;
-    }
-
-}
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregatorBuilder.java
index ea9e3efb8fb..acd587b5026 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/max/MaxBucketPipelineAggregatorBuilder.java
@@ -19,29 +19,43 @@
 
 package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.max;
 
+import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
+import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder;
 
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 
-public class MaxBucketPipelineAggregatorBuilder
-        extends BucketMetricsPipelineAggregatorBuilder {
-
-    static final MaxBucketPipelineAggregatorBuilder PROTOTYPE = new MaxBucketPipelineAggregatorBuilder("", "");
+public class MaxBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder {
+    public static final String NAME = MaxBucketPipelineAggregator.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     public MaxBucketPipelineAggregatorBuilder(String name, String bucketsPath) {
-        this(name, new String[] { bucketsPath });
+        super(name, MaxBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath });
     }
 
-    private MaxBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) {
-        super(name, MaxBucketPipelineAggregator.TYPE.name(), bucketsPaths);
+    /**
+     * Read from a stream.
+     */
+    public MaxBucketPipelineAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, NAME);
+    }
+
+    @Override
+    protected void innerWriteTo(StreamOutput out) throws IOException {
+        // Do nothing, no extra state to write to stream
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
     }
 
     @Override
@@ -63,16 +77,13 @@ public class MaxBucketPipelineAggregatorBuilder
         return builder;
     }
 
-    @Override
-    protected MaxBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in)
-            throws IOException {
-        return new MaxBucketPipelineAggregatorBuilder(name, bucketsPaths);
-    }
-
-    @Override
-    protected void innerWriteTo(StreamOutput out) throws IOException {
-        // Do nothing, no extra state to write to stream
-    }
+    public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() {
+        @Override
+        protected MaxBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName,
+                String bucketsPath, Map unparsedParams) {
+            return new MaxBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath);
+        }
+    };
 
     @Override
     protected int innerHashCode() {
@@ -84,4 +95,8 @@ public class MaxBucketPipelineAggregatorBuilder
         return true;
     }
 
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketParser.java
deleted file mode 100644
index ea7c2284857..00000000000
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketParser.java
+++ /dev/null
@@ -1,44 +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.aggregations.pipeline.bucketmetrics.min;
-
-import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
-
-import java.util.Map;
-
-public class MinBucketParser extends BucketMetricsParser {
-
-    @Override
-    public String type() {
-        return MinBucketPipelineAggregator.TYPE.name();
-    }
-
-    @Override
-    protected MinBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath,
-            Map unparsedParams) {
-        return new MinBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath);
-    }
-
-    @Override
-    public MinBucketPipelineAggregatorBuilder getFactoryPrototype() {
-        return MinBucketPipelineAggregatorBuilder.PROTOTYPE;
-    }
-
-}
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregatorBuilder.java
index 50e5d978f26..9b5ff99f8be 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/min/MinBucketPipelineAggregatorBuilder.java
@@ -19,29 +19,43 @@
 
 package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.min;
 
+import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
+import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder;
 
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 
-public class MinBucketPipelineAggregatorBuilder
-        extends BucketMetricsPipelineAggregatorBuilder {
-
-    static final MinBucketPipelineAggregatorBuilder PROTOTYPE = new MinBucketPipelineAggregatorBuilder("", "");
+public class MinBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder {
+    public static final String NAME = MinBucketPipelineAggregator.TYPE.name();
+    public static final ParseField AGGREGATION_FIELD_NAME = new ParseField(NAME);
 
     public MinBucketPipelineAggregatorBuilder(String name, String bucketsPath) {
-        this(name, new String[] { bucketsPath });
+        super(name, MinBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath });
     }
 
-    private MinBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) {
-        super(name, MinBucketPipelineAggregator.TYPE.name(), bucketsPaths);
+    /**
+     * Read from a stream.
+     */
+    public MinBucketPipelineAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, NAME);
+    }
+
+    @Override
+    protected void innerWriteTo(StreamOutput out) throws IOException {
+        // Do nothing, no extra state to write to stream
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
     }
 
     @Override
@@ -63,16 +77,13 @@ public class MinBucketPipelineAggregatorBuilder
         return builder;
     }
 
-    @Override
-    protected MinBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in)
-            throws IOException {
-        return new MinBucketPipelineAggregatorBuilder(name, bucketsPaths);
-    }
-
-    @Override
-    protected void innerWriteTo(StreamOutput out) throws IOException {
-        // Do nothing, no extra state to write to stream
-    }
+    public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() {
+        @Override
+        protected MinBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName,
+                String bucketsPath, Map unparsedParams) {
+            return new MinBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath);
+        }
+    };
 
     @Override
     protected int innerHashCode() {
@@ -84,4 +95,8 @@ public class MinBucketPipelineAggregatorBuilder
         return true;
     }
 
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketParser.java
deleted file mode 100644
index b1969afb558..00000000000
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketParser.java
+++ /dev/null
@@ -1,78 +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.aggregations.pipeline.bucketmetrics.percentile;
-
-import org.elasticsearch.common.ParseField;
-import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
-
-import java.text.ParseException;
-import java.util.List;
-import java.util.Map;
-
-
-public class PercentilesBucketParser extends BucketMetricsParser {
-
-    public static final ParseField PERCENTS = new ParseField("percents");
-
-    @Override
-    public String type() {
-        return PercentilesBucketPipelineAggregator.TYPE.name();
-    }
-
-    @Override
-    protected PercentilesBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName,
-            String bucketsPath, Map unparsedParams) throws ParseException {
-
-        double[] percents = null;
-        int counter = 0;
-        Object percentParam = unparsedParams.get(PERCENTS.getPreferredName());
-
-        if (percentParam != null) {
-            if (percentParam instanceof List) {
-                percents = new double[((List) percentParam).size()];
-                for (Object p : (List) percentParam) {
-                    if (p instanceof Double) {
-                        percents[counter] = (Double) p;
-                        counter += 1;
-                    } else {
-                        throw new ParseException("Parameter [" + PERCENTS.getPreferredName() + "] must be an array of doubles, type `"
-                                + percentParam.getClass().getSimpleName() + "` provided instead", 0);
-                    }
-                }
-                unparsedParams.remove(PERCENTS.getPreferredName());
-            } else {
-                throw new ParseException("Parameter [" + PERCENTS.getPreferredName() + "] must be an array of doubles, type `"
-                        + percentParam.getClass().getSimpleName() + "` provided instead", 0);
-            }
-        }
-
-        PercentilesBucketPipelineAggregatorBuilder factory = new
-                PercentilesBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath);
-        if (percents != null) {
-            factory.percents(percents);
-        }
-        return factory;
-    }
-
-    @Override
-    public PercentilesBucketPipelineAggregatorBuilder getFactoryPrototype() {
-        return PercentilesBucketPipelineAggregatorBuilder.PROTOTYPE;
-    }
-}
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregatorBuilder.java
index 5f2d279a5f0..9c6faa0dd99 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/percentile/PercentilesBucketPipelineAggregatorBuilder.java
@@ -19,15 +19,18 @@
 
 package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile;
 
+import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
+import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder;
 
 import java.io.IOException;
+import java.text.ParseException;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
@@ -35,17 +38,34 @@ import java.util.Objects;
 
 public class PercentilesBucketPipelineAggregatorBuilder
         extends BucketMetricsPipelineAggregatorBuilder {
+    public static final String NAME = PercentilesBucketPipelineAggregator.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
-    static final PercentilesBucketPipelineAggregatorBuilder PROTOTYPE = new PercentilesBucketPipelineAggregatorBuilder("", "");
+    private static final ParseField PERCENTS_FIELD = new ParseField("percents");
 
     private double[] percents = new double[] { 1.0, 5.0, 25.0, 50.0, 75.0, 95.0, 99.0 };
 
     public PercentilesBucketPipelineAggregatorBuilder(String name, String bucketsPath) {
-        this(name, new String[] { bucketsPath });
+        super(name, PercentilesBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath });
     }
 
-    private PercentilesBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) {
-        super(name, PercentilesBucketPipelineAggregator.TYPE.name(), bucketsPaths);
+    /**
+     * Read from a stream.
+     */
+    public PercentilesBucketPipelineAggregatorBuilder(StreamInput in)
+            throws IOException {
+        super(in, NAME);
+        percents = in.readDoubleArray();
+    }
+
+    @Override
+    protected void innerWriteTo(StreamOutput out) throws IOException {
+        out.writeDoubleArray(percents);
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
     }
 
     /**
@@ -64,7 +84,7 @@ public class PercentilesBucketPipelineAggregatorBuilder
         }
         for (Double p : percents) {
             if (p == null || p < 0.0 || p > 100.0) {
-                throw new IllegalArgumentException(PercentilesBucketParser.PERCENTS.getPreferredName()
+                throw new IllegalArgumentException(PERCENTS_FIELD.getPreferredName()
                         + " must only contain non-null doubles from 0.0-100.0 inclusive");
             }
         }
@@ -87,7 +107,7 @@ public class PercentilesBucketPipelineAggregatorBuilder
 
         for (Double p : percents) {
             if (p == null || p < 0.0 || p > 100.0) {
-                throw new IllegalStateException(PercentilesBucketParser.PERCENTS.getPreferredName()
+                throw new IllegalStateException(PERCENTS_FIELD.getPreferredName()
                         + " must only contain non-null doubles from 0.0-100.0 inclusive");
             }
         }
@@ -96,23 +116,48 @@ public class PercentilesBucketPipelineAggregatorBuilder
     @Override
     protected XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
         if (percents != null) {
-            builder.field(PercentilesBucketParser.PERCENTS.getPreferredName(), percents);
+            builder.field(PERCENTS_FIELD.getPreferredName(), percents);
         }
         return builder;
     }
 
-    @Override
-    protected PercentilesBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in)
-            throws IOException {
-        PercentilesBucketPipelineAggregatorBuilder factory = new PercentilesBucketPipelineAggregatorBuilder(name, bucketsPaths);
-        factory.percents = in.readDoubleArray();
-        return factory;
-    }
+    public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() {
+        @Override
+        protected PercentilesBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName,
+                String bucketsPath, Map unparsedParams) throws ParseException {
+            double[] percents = null;
+            int counter = 0;
+            Object percentParam = unparsedParams.get(PERCENTS_FIELD.getPreferredName());
 
-    @Override
-    protected void innerWriteTo(StreamOutput out) throws IOException {
-        out.writeDoubleArray(percents);
-    }
+            if (percentParam != null) {
+                if (percentParam instanceof List) {
+                    percents = new double[((List) percentParam).size()];
+                    for (Object p : (List) percentParam) {
+                        if (p instanceof Double) {
+                            percents[counter] = (Double) p;
+                            counter += 1;
+                        } else {
+                            throw new ParseException(
+                                    "Parameter [" + PERCENTS_FIELD.getPreferredName() + "] must be an array of doubles, type `"
+                                            + percentParam.getClass().getSimpleName() + "` provided instead",
+                                    0);
+                        }
+                    }
+                    unparsedParams.remove(PERCENTS_FIELD.getPreferredName());
+                } else {
+                    throw new ParseException("Parameter [" + PERCENTS_FIELD.getPreferredName() + "] must be an array of doubles, type `"
+                            + percentParam.getClass().getSimpleName() + "` provided instead", 0);
+                }
+            }
+
+            PercentilesBucketPipelineAggregatorBuilder factory = new
+                    PercentilesBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath);
+            if (percents != null) {
+                factory.percents(percents);
+            }
+            return factory;
+        }
+    };
 
     @Override
     protected int innerHashCode() {
@@ -125,4 +170,8 @@ public class PercentilesBucketPipelineAggregatorBuilder
         return Objects.deepEquals(percents, other.percents);
     }
 
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketParser.java
deleted file mode 100644
index c4a17cd084d..00000000000
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketParser.java
+++ /dev/null
@@ -1,42 +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.aggregations.pipeline.bucketmetrics.sum;
-
-import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
-
-import java.util.Map;
-
-public class SumBucketParser extends BucketMetricsParser {
-    @Override
-    public String type() {
-        return SumBucketPipelineAggregator.TYPE.name();
-    }
-
-    @Override
-    protected SumBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName, String bucketsPath,
-            Map unparsedParams) {
-        return new SumBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath);
-    }
-
-    @Override
-    public SumBucketPipelineAggregatorBuilder getFactoryPrototype() {
-        return SumBucketPipelineAggregatorBuilder.PROTOTYPE;
-    }
-}
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregatorBuilder.java
index 25a1ebe6f84..d322b25884c 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/pipeline/bucketmetrics/sum/SumBucketPipelineAggregatorBuilder.java
@@ -19,29 +19,43 @@
 
 package org.elasticsearch.search.aggregations.pipeline.bucketmetrics.sum;
 
+import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator;
 import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
+import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsParser;
 import org.elasticsearch.search.aggregations.pipeline.bucketmetrics.BucketMetricsPipelineAggregatorBuilder;
 
 import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 
-public class SumBucketPipelineAggregatorBuilder
-        extends BucketMetricsPipelineAggregatorBuilder {
-
-    static final SumBucketPipelineAggregatorBuilder PROTOTYPE = new SumBucketPipelineAggregatorBuilder("", "");
+public class SumBucketPipelineAggregatorBuilder extends BucketMetricsPipelineAggregatorBuilder {
+    public static final String NAME = SumBucketPipelineAggregator.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     public SumBucketPipelineAggregatorBuilder(String name, String bucketsPath) {
-        this(name, new String[] { bucketsPath });
+        super(name, SumBucketPipelineAggregator.TYPE.name(), new String[] { bucketsPath });
     }
 
-    private SumBucketPipelineAggregatorBuilder(String name, String[] bucketsPaths) {
-        super(name, SumBucketPipelineAggregator.TYPE.name(), bucketsPaths);
+    /**
+     * Read from a stream.
+     */
+    public SumBucketPipelineAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, NAME);
+    }
+
+    @Override
+    protected void innerWriteTo(StreamOutput out) throws IOException {
+        // Do nothing, no extra state to write to stream
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
     }
 
     @Override
@@ -63,16 +77,13 @@ public class SumBucketPipelineAggregatorBuilder
         return builder;
     }
 
-    @Override
-    protected SumBucketPipelineAggregatorBuilder innerReadFrom(String name, String[] bucketsPaths, StreamInput in)
-            throws IOException {
-        return new SumBucketPipelineAggregatorBuilder(name, bucketsPaths);
-    }
-
-    @Override
-    protected void innerWriteTo(StreamOutput out) throws IOException {
-        // Do nothing, no extra state to write to stream
-    }
+    public static final PipelineAggregator.Parser PARSER = new BucketMetricsParser() {
+        @Override
+        protected SumBucketPipelineAggregatorBuilder buildFactory(String pipelineAggregatorName,
+                String bucketsPath, Map unparsedParams) {
+            return new SumBucketPipelineAggregatorBuilder(pipelineAggregatorName, bucketsPath);
+        }
+    };
 
     @Override
     protected int innerHashCode() {
@@ -84,4 +95,8 @@ public class SumBucketPipelineAggregatorBuilder
         return true;
     }
 
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file

From f6d141a29cac730447355944d8910732130949da Mon Sep 17 00:00:00 2001
From: Nik Everett 
Date: Fri, 15 Apr 2016 12:42:29 -0400
Subject: [PATCH 046/561] Cut percentiles and percentile_ranks to
 registerAggregation

and remove their PROTOTYPEs.

Relates to #17085
---
 .../elasticsearch/search/SearchModule.java    |  8 ++-
 .../PercentileRanksAggregatorBuilder.java     | 63 +++++++++++--------
 .../percentiles/PercentileRanksParser.java    | 12 ----
 .../PercentilesAggregatorBuilder.java         | 61 ++++++++++--------
 .../percentiles/PercentilesParser.java        | 12 ----
 5 files changed, 79 insertions(+), 77 deletions(-)

diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java
index 4efe49d9c23..f4b3aa6095c 100644
--- a/core/src/main/java/org/elasticsearch/search/SearchModule.java
+++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java
@@ -170,7 +170,9 @@ import org.elasticsearch.search.aggregations.metrics.max.InternalMax;
 import org.elasticsearch.search.aggregations.metrics.max.MaxParser;
 import org.elasticsearch.search.aggregations.metrics.min.InternalMin;
 import org.elasticsearch.search.aggregations.metrics.min.MinParser;
+import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksAggregatorBuilder;
 import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksParser;
+import org.elasticsearch.search.aggregations.metrics.percentiles.PercentilesAggregatorBuilder;
 import org.elasticsearch.search.aggregations.metrics.percentiles.PercentilesParser;
 import org.elasticsearch.search.aggregations.metrics.percentiles.hdr.InternalHDRPercentileRanks;
 import org.elasticsearch.search.aggregations.metrics.percentiles.hdr.InternalHDRPercentiles;
@@ -461,8 +463,10 @@ public class SearchModule extends AbstractModule {
         registerAggregatorParser(new StatsParser());
         registerAggregatorParser(new ExtendedStatsParser());
         registerAggregation(ValueCountAggregatorBuilder::new, new ValueCountParser(), ValueCountAggregatorBuilder.AGGREGATION_NAME_FIELD);
-        registerAggregatorParser(new PercentilesParser());
-        registerAggregatorParser(new PercentileRanksParser());
+        registerAggregation(PercentilesAggregatorBuilder::new, new PercentilesParser(),
+                PercentilesAggregatorBuilder.AGGREGATION_NAME_FIELD);
+        registerAggregation(PercentileRanksAggregatorBuilder::new, new PercentileRanksParser(),
+                PercentileRanksAggregatorBuilder.AGGREGATION_NAME_FIELD);
         registerAggregation(CardinalityAggregatorBuilder::new, new CardinalityParser(),
                 CardinalityAggregatorBuilder.AGGREGATION_NAME_FIELD);
         registerAggregation(GlobalAggregatorBuilder::new, GlobalAggregatorBuilder::parse, GlobalAggregatorBuilder.AGGREGATION_NAME_FIELD);
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/percentiles/PercentileRanksAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/percentiles/PercentileRanksAggregatorBuilder.java
index de66f68103f..9124ba23559 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/percentiles/PercentileRanksAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/percentiles/PercentileRanksAggregatorBuilder.java
@@ -19,30 +19,31 @@
 
 package org.elasticsearch.search.aggregations.metrics.percentiles;
 
+import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
+import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.metrics.percentiles.hdr.HDRPercentileRanksAggregatorFactory;
 import org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.InternalTDigestPercentileRanks;
 import org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.TDigestPercentileRanksAggregatorFactory;
 import org.elasticsearch.search.aggregations.support.AggregationContext;
 import org.elasticsearch.search.aggregations.support.ValueType;
 import org.elasticsearch.search.aggregations.support.ValuesSource;
+import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
+import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder.LeafOnly;
 import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorFactory;
 import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
 import org.elasticsearch.search.aggregations.support.ValuesSourceType;
-import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
-import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder.LeafOnly;
 
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.Objects;
 
 public class PercentileRanksAggregatorBuilder extends LeafOnly {
-
-    static final PercentileRanksAggregatorBuilder PROTOTYPE = new PercentileRanksAggregatorBuilder("");
+    public static final String NAME = InternalTDigestPercentileRanks.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     private double[] values;
     private PercentilesMethod method = PercentilesMethod.TDIGEST;
@@ -54,6 +55,32 @@ public class PercentileRanksAggregatorBuilder extends LeafOnly {
-
-    static final PercentilesAggregatorBuilder PROTOTYPE = new PercentilesAggregatorBuilder("");
+    public static final String NAME = InternalTDigestPercentiles.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     private double[] percents = PercentilesParser.DEFAULT_PERCENTS;
     private PercentilesMethod method = PercentilesMethod.TDIGEST;
@@ -54,6 +55,32 @@ public class PercentilesAggregatorBuilder extends LeafOnly
Date: Fri, 15 Apr 2016 12:23:09 -0400
Subject: [PATCH 047/561] Cut max, min, stats, and extended stats aggregations
 over to registerAggregation

and remove their PROTOTYPEs.

Relates to #17085
---
 .../elasticsearch/search/SearchModule.java    | 16 ++++---
 .../metrics/max/MaxAggregatorBuilder.java     | 42 ++++++++++-------
 .../aggregations/metrics/max/MaxParser.java   | 11 -----
 .../metrics/min/MinAggregatorBuilder.java     | 43 +++++++++++-------
 .../aggregations/metrics/min/MinParser.java   | 10 -----
 .../metrics/stats/StatsAggregatorBuilder.java | 37 +++++++++------
 .../metrics/stats/StatsParser.java            | 11 -----
 .../ExtendedStatsAggregatorBuilder.java       | 45 ++++++++++++-------
 .../stats/extended/ExtendedStatsParser.java   | 11 -----
 .../metrics/sum/SumAggregatorBuilder.java     | 42 ++++++++++-------
 .../aggregations/metrics/sum/SumParser.java   | 11 -----
 11 files changed, 143 insertions(+), 136 deletions(-)

diff --git a/core/src/main/java/org/elasticsearch/search/SearchModule.java b/core/src/main/java/org/elasticsearch/search/SearchModule.java
index f4b3aa6095c..09fe3c3b3eb 100644
--- a/core/src/main/java/org/elasticsearch/search/SearchModule.java
+++ b/core/src/main/java/org/elasticsearch/search/SearchModule.java
@@ -167,8 +167,10 @@ import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidAggr
 import org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidParser;
 import org.elasticsearch.search.aggregations.metrics.geocentroid.InternalGeoCentroid;
 import org.elasticsearch.search.aggregations.metrics.max.InternalMax;
+import org.elasticsearch.search.aggregations.metrics.max.MaxAggregatorBuilder;
 import org.elasticsearch.search.aggregations.metrics.max.MaxParser;
 import org.elasticsearch.search.aggregations.metrics.min.InternalMin;
+import org.elasticsearch.search.aggregations.metrics.min.MinAggregatorBuilder;
 import org.elasticsearch.search.aggregations.metrics.min.MinParser;
 import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksAggregatorBuilder;
 import org.elasticsearch.search.aggregations.metrics.percentiles.PercentileRanksParser;
@@ -181,10 +183,13 @@ import org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.Interna
 import org.elasticsearch.search.aggregations.metrics.scripted.InternalScriptedMetric;
 import org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetricAggregatorBuilder;
 import org.elasticsearch.search.aggregations.metrics.stats.InternalStats;
+import org.elasticsearch.search.aggregations.metrics.stats.StatsAggregatorBuilder;
 import org.elasticsearch.search.aggregations.metrics.stats.StatsParser;
+import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregatorBuilder;
 import org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsParser;
 import org.elasticsearch.search.aggregations.metrics.stats.extended.InternalExtendedStats;
 import org.elasticsearch.search.aggregations.metrics.sum.InternalSum;
+import org.elasticsearch.search.aggregations.metrics.sum.SumAggregatorBuilder;
 import org.elasticsearch.search.aggregations.metrics.sum.SumParser;
 import org.elasticsearch.search.aggregations.metrics.tophits.InternalTopHits;
 import org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregatorBuilder;
@@ -457,11 +462,12 @@ public class SearchModule extends AbstractModule {
         SignificanceHeuristicParserMapper significanceHeuristicParserMapper = new SignificanceHeuristicParserMapper(heuristicParsers);
 
         registerAggregation(AvgAggregatorBuilder::new, new AvgParser(), AvgAggregatorBuilder.AGGREGATION_NAME_FIELD);
-        registerAggregatorParser(new SumParser());
-        registerAggregatorParser(new MinParser());
-        registerAggregatorParser(new MaxParser());
-        registerAggregatorParser(new StatsParser());
-        registerAggregatorParser(new ExtendedStatsParser());
+        registerAggregation(SumAggregatorBuilder::new, new SumParser(), SumAggregatorBuilder.AGGREGATION_NAME_FIELD);
+        registerAggregation(MinAggregatorBuilder::new, new MinParser(), MinAggregatorBuilder.AGGREGATION_NAME_FIELD);
+        registerAggregation(MaxAggregatorBuilder::new, new MaxParser(), MaxAggregatorBuilder.AGGREGATION_NAME_FIELD);
+        registerAggregation(StatsAggregatorBuilder::new, new StatsParser(), StatsAggregatorBuilder.AGGREGATION_NAME_FIELD);
+        registerAggregation(ExtendedStatsAggregatorBuilder::new, new ExtendedStatsParser(),
+        ExtendedStatsAggregatorBuilder.AGGREGATION_NAME_FIELD);
         registerAggregation(ValueCountAggregatorBuilder::new, new ValueCountParser(), ValueCountAggregatorBuilder.AGGREGATION_NAME_FIELD);
         registerAggregation(PercentilesAggregatorBuilder::new, new PercentilesParser(),
                 PercentilesAggregatorBuilder.AGGREGATION_NAME_FIELD);
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregatorBuilder.java
index 2eb86535ca0..3b71dcb6bf5 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxAggregatorBuilder.java
@@ -19,47 +19,53 @@
 
 package org.elasticsearch.search.aggregations.metrics.max;
 
+import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.ToXContent.Params;
-import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
+import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.support.AggregationContext;
 import org.elasticsearch.search.aggregations.support.ValueType;
 import org.elasticsearch.search.aggregations.support.ValuesSource;
+import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
 import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder;
 import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
 import org.elasticsearch.search.aggregations.support.ValuesSourceType;
-import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
 
 import java.io.IOException;
 
 public class MaxAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly {
-
-    static final MaxAggregatorBuilder PROTOTYPE = new MaxAggregatorBuilder("");
+    public static final String NAME = InternalMax.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     public MaxAggregatorBuilder(String name) {
         super(name, InternalMax.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
     }
 
+    /**
+     * Read from a stream.
+     */
+    public MaxAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, InternalMax.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
+    }
+
+    @Override
+    protected void innerWriteTo(StreamOutput out) {
+        // Do nothing, no extra state to write to stream
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
+    }
+
     @Override
     protected MaxAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config,
             AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException {
         return new MaxAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData);
     }
 
-    @Override
-    protected MaxAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType,
-            ValueType targetValueType, StreamInput in) {
-        return new MaxAggregatorBuilder(name);
-    }
-
-    @Override
-    protected void innerWriteTo(StreamOutput out) {
-        // Do nothing, no extra state to write to stream
-    }
-
     @Override
     public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
         return builder;
@@ -75,4 +81,8 @@ public class MaxAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly
         return true;
     }
 
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxParser.java
index 50b622f9019..41c321acf33 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxParser.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/max/MaxParser.java
@@ -37,11 +37,6 @@ public class MaxParser extends NumericValuesSourceParser {
         super(true, true, false);
     }
 
-    @Override
-    public String type() {
-        return InternalMax.TYPE.name();
-    }
-
     @Override
     protected boolean token(String aggregationName, String currentFieldName, XContentParser.Token token, XContentParser parser,
             ParseFieldMatcher parseFieldMatcher, Map otherOptions) throws IOException {
@@ -53,10 +48,4 @@ public class MaxParser extends NumericValuesSourceParser {
             ValueType targetValueType, Map otherOptions) {
         return new MaxAggregatorBuilder(aggregationName);
     }
-
-    @Override
-    public MaxAggregatorBuilder getFactoryPrototypes() {
-        return MaxAggregatorBuilder.PROTOTYPE;
-    }
-
 }
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregatorBuilder.java
index 186c38d26d3..25049bd71b0 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinAggregatorBuilder.java
@@ -19,47 +19,53 @@
 
 package org.elasticsearch.search.aggregations.metrics.min;
 
+import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.ToXContent.Params;
-import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
+import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.support.AggregationContext;
 import org.elasticsearch.search.aggregations.support.ValueType;
 import org.elasticsearch.search.aggregations.support.ValuesSource;
+import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
 import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder;
 import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
 import org.elasticsearch.search.aggregations.support.ValuesSourceType;
-import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
 
 import java.io.IOException;
 
 public class MinAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly {
-
-    static final MinAggregatorBuilder PROTOTYPE = new MinAggregatorBuilder("");
+    public static final String NAME = InternalMin.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     public MinAggregatorBuilder(String name) {
         super(name, InternalMin.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
     }
 
+    /**
+     * Read from a stream.
+     */
+    public MinAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, InternalMin.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
+    }
+
+    @Override
+    protected void innerWriteTo(StreamOutput out) {
+        // Do nothing, no extra state to write to stream
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
+    }
+
     @Override
     protected MinAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config,
             AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException {
         return new MinAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData);
     }
 
-    @Override
-    protected MinAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType,
-            ValueType targetValueType, StreamInput in) {
-        return new MinAggregatorBuilder(name);
-    }
-
-    @Override
-    protected void innerWriteTo(StreamOutput out) {
-        // Do nothing, no extra state to write to stream
-    }
-
     @Override
     public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
         return builder;
@@ -74,4 +80,9 @@ public class MinAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly
     protected boolean innerEquals(Object obj) {
         return true;
     }
+
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinParser.java
index f7a3a04c6ae..9f9eafc5035 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinParser.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/min/MinParser.java
@@ -38,11 +38,6 @@ public class MinParser extends NumericValuesSourceParser {
         super(true, true, false);
     }
 
-    @Override
-    public String type() {
-        return InternalMin.TYPE.name();
-    }
-
     @Override
     protected boolean token(String aggregationName, String currentFieldName, Token token, XContentParser parser,
             ParseFieldMatcher parseFieldMatcher, Map otherOptions) throws IOException {
@@ -54,9 +49,4 @@ public class MinParser extends NumericValuesSourceParser {
             ValueType targetValueType, Map otherOptions) {
         return new MinAggregatorBuilder(aggregationName);
     }
-
-    @Override
-    public MinAggregatorBuilder getFactoryPrototypes() {
-        return MinAggregatorBuilder.PROTOTYPE;
-    }
 }
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregatorBuilder.java
index 646332f97ad..6775b9a9610 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsAggregatorBuilder.java
@@ -19,30 +19,42 @@
 
 package org.elasticsearch.search.aggregations.metrics.stats;
 
+import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.ToXContent.Params;
-import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
+import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.support.AggregationContext;
 import org.elasticsearch.search.aggregations.support.ValueType;
 import org.elasticsearch.search.aggregations.support.ValuesSource;
+import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
 import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder;
 import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
 import org.elasticsearch.search.aggregations.support.ValuesSourceType;
-import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
 
 import java.io.IOException;
 
 public class StatsAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly {
-
-    static final StatsAggregatorBuilder PROTOTYPE = new StatsAggregatorBuilder("");
+    public static final String NAME = InternalStats.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     public StatsAggregatorBuilder(String name) {
         super(name, InternalStats.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
     }
 
+    /**
+     * Read from a stream.
+     */
+    public StatsAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, InternalStats.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
+    }
+
+    @Override
+    protected void innerWriteTo(StreamOutput out) {
+        // Do nothing, no extra state to write to stream
+    }
+
     @Override
     protected StatsAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config,
             AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException {
@@ -50,14 +62,8 @@ public class StatsAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOn
     }
 
     @Override
-    protected StatsAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType,
-            ValueType targetValueType, StreamInput in) {
-        return new StatsAggregatorBuilder(name);
-    }
-
-    @Override
-    protected void innerWriteTo(StreamOutput out) {
-        // Do nothing, no extra state to write to stream
+    protected boolean usesNewStyleSerialization() {
+        return true;
     }
 
     @Override
@@ -74,4 +80,9 @@ public class StatsAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOn
     protected boolean innerEquals(Object obj) {
         return true;
     }
+
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsParser.java
index 6bf558d197d..a57ba89b676 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsParser.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/StatsParser.java
@@ -21,7 +21,6 @@ package org.elasticsearch.search.aggregations.metrics.stats;
 import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.ParseFieldMatcher;
 import org.elasticsearch.common.xcontent.XContentParser;
-import org.elasticsearch.search.aggregations.AggregatorBuilder;
 import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.NumericValuesSourceParser;
 import org.elasticsearch.search.aggregations.support.ValueType;
 import org.elasticsearch.search.aggregations.support.ValuesSourceType;
@@ -38,11 +37,6 @@ public class StatsParser extends NumericValuesSourceParser {
         super(true, true, false);
     }
 
-    @Override
-    public String type() {
-        return InternalStats.TYPE.name();
-    }
-
     @Override
     protected boolean token(String aggregationName, String currentFieldName, XContentParser.Token token, XContentParser parser,
             ParseFieldMatcher parseFieldMatcher, Map otherOptions) throws IOException {
@@ -54,9 +48,4 @@ public class StatsParser extends NumericValuesSourceParser {
             ValueType targetValueType, Map otherOptions) {
         return new StatsAggregatorBuilder(aggregationName);
     }
-
-    @Override
-    public AggregatorBuilder getFactoryPrototypes() {
-        return StatsAggregatorBuilder.PROTOTYPE;
-    }
 }
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregatorBuilder.java
index 80fd04b6c18..c5b6c30e494 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsAggregatorBuilder.java
@@ -19,26 +19,27 @@
 
 package org.elasticsearch.search.aggregations.metrics.stats.extended;
 
+import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
+import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.support.AggregationContext;
 import org.elasticsearch.search.aggregations.support.ValueType;
 import org.elasticsearch.search.aggregations.support.ValuesSource;
+import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
 import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder;
 import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
 import org.elasticsearch.search.aggregations.support.ValuesSourceType;
-import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
 
 import java.io.IOException;
 import java.util.Objects;
 
 public class ExtendedStatsAggregatorBuilder
         extends ValuesSourceAggregatorBuilder.LeafOnly {
-
-    static final ExtendedStatsAggregatorBuilder PROTOTYPE = new ExtendedStatsAggregatorBuilder("");
+    public static final String NAME = InternalExtendedStats.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     private double sigma = 2.0;
 
@@ -46,6 +47,24 @@ public class ExtendedStatsAggregatorBuilder
         super(name, InternalExtendedStats.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
     }
 
+    /**
+     * Read from a stream.
+     */
+    public ExtendedStatsAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, InternalExtendedStats.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
+        sigma = in.readDouble();
+    }
+
+    @Override
+    protected void innerWriteTo(StreamOutput out) throws IOException {
+        out.writeDouble(sigma);
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
+    }
+
     public ExtendedStatsAggregatorBuilder sigma(double sigma) {
         if (sigma < 0.0) {
             throw new IllegalArgumentException("[sigma] must be greater than or equal to 0. Found [" + sigma + "] in [" + name + "]");
@@ -64,19 +83,6 @@ public class ExtendedStatsAggregatorBuilder
         return new ExtendedStatsAggregatorFactory(name, type, config, sigma, context, parent, subFactoriesBuilder, metaData);
     }
 
-    @Override
-    protected ExtendedStatsAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType,
-            ValueType targetValueType, StreamInput in) throws IOException {
-        ExtendedStatsAggregatorBuilder factory = new ExtendedStatsAggregatorBuilder(name);
-        factory.sigma = in.readDouble();
-        return factory;
-    }
-
-    @Override
-    protected void innerWriteTo(StreamOutput out) throws IOException {
-        out.writeDouble(sigma);
-    }
-
     @Override
     public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
         builder.field(ExtendedStatsAggregator.SIGMA_FIELD.getPreferredName(), sigma);
@@ -93,4 +99,9 @@ public class ExtendedStatsAggregatorBuilder
         ExtendedStatsAggregatorBuilder other = (ExtendedStatsAggregatorBuilder) obj;
         return Objects.equals(sigma, other.sigma);
     }
+
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsParser.java
index faae604111a..76e6beac2da 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsParser.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/ExtendedStatsParser.java
@@ -21,7 +21,6 @@ package org.elasticsearch.search.aggregations.metrics.stats.extended;
 import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.ParseFieldMatcher;
 import org.elasticsearch.common.xcontent.XContentParser;
-import org.elasticsearch.search.aggregations.AggregatorBuilder;
 import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.NumericValuesSourceParser;
 import org.elasticsearch.search.aggregations.support.ValueType;
 import org.elasticsearch.search.aggregations.support.ValuesSourceType;
@@ -38,11 +37,6 @@ public class ExtendedStatsParser extends NumericValuesSourceParser {
         super(true, true, false);
     }
 
-    @Override
-    public String type() {
-        return InternalExtendedStats.TYPE.name();
-    }
-
     @Override
     protected boolean token(String aggregationName, String currentFieldName, XContentParser.Token token, XContentParser parser,
             ParseFieldMatcher parseFieldMatcher, Map otherOptions) throws IOException {
@@ -65,9 +59,4 @@ public class ExtendedStatsParser extends NumericValuesSourceParser {
         }
         return factory;
     }
-
-    @Override
-    public AggregatorBuilder getFactoryPrototypes() {
-        return ExtendedStatsAggregatorBuilder.PROTOTYPE;
-    }
 }
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregatorBuilder.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregatorBuilder.java
index 17671d9ffa3..6f83f0f64f1 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregatorBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumAggregatorBuilder.java
@@ -19,46 +19,53 @@
 
 package org.elasticsearch.search.aggregations.metrics.sum;
 
+import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
+import org.elasticsearch.search.aggregations.AggregatorFactory;
 import org.elasticsearch.search.aggregations.support.AggregationContext;
 import org.elasticsearch.search.aggregations.support.ValueType;
 import org.elasticsearch.search.aggregations.support.ValuesSource;
+import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
 import org.elasticsearch.search.aggregations.support.ValuesSourceAggregatorBuilder;
 import org.elasticsearch.search.aggregations.support.ValuesSourceConfig;
 import org.elasticsearch.search.aggregations.support.ValuesSourceType;
-import org.elasticsearch.search.aggregations.support.ValuesSource.Numeric;
 
 import java.io.IOException;
 
 public class SumAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly {
-
-    static final SumAggregatorBuilder PROTOTYPE = new SumAggregatorBuilder("");
+    public static final String NAME = InternalSum.TYPE.name();
+    public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
 
     public SumAggregatorBuilder(String name) {
         super(name, InternalSum.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
     }
 
+    /**
+     * Read from a stream.
+     */
+    public SumAggregatorBuilder(StreamInput in) throws IOException {
+        super(in, InternalSum.TYPE, ValuesSourceType.NUMERIC, ValueType.NUMERIC);
+    }
+
+    @Override
+    protected void innerWriteTo(StreamOutput out) {
+        // Do nothing, no extra state to write to stream
+    }
+
+    @Override
+    protected boolean usesNewStyleSerialization() {
+        return true;
+    }
+
     @Override
     protected SumAggregatorFactory innerBuild(AggregationContext context, ValuesSourceConfig config,
             AggregatorFactory parent, Builder subFactoriesBuilder) throws IOException {
         return new SumAggregatorFactory(name, type, config, context, parent, subFactoriesBuilder, metaData);
     }
 
-    @Override
-    protected ValuesSourceAggregatorBuilder innerReadFrom(String name, ValuesSourceType valuesSourceType,
-            ValueType targetValueType, StreamInput in) {
-        return new SumAggregatorBuilder(name);
-    }
-
-    @Override
-    protected void innerWriteTo(StreamOutput out) {
-        // Do nothing, no extra state to write to stream
-    }
-
     @Override
     public XContentBuilder doXContentBody(XContentBuilder builder, Params params) throws IOException {
         return builder;
@@ -73,4 +80,9 @@ public class SumAggregatorBuilder extends ValuesSourceAggregatorBuilder.LeafOnly
     protected boolean innerEquals(Object obj) {
         return true;
     }
+
+    @Override
+    public String getWriteableName() {
+        return NAME;
+    }
 }
\ No newline at end of file
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumParser.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumParser.java
index 92664c9a6d8..7971adba4eb 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumParser.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/sum/SumParser.java
@@ -21,7 +21,6 @@ package org.elasticsearch.search.aggregations.metrics.sum;
 import org.elasticsearch.common.ParseField;
 import org.elasticsearch.common.ParseFieldMatcher;
 import org.elasticsearch.common.xcontent.XContentParser;
-import org.elasticsearch.search.aggregations.AggregatorBuilder;
 import org.elasticsearch.search.aggregations.support.AbstractValuesSourceParser.NumericValuesSourceParser;
 import org.elasticsearch.search.aggregations.support.ValueType;
 import org.elasticsearch.search.aggregations.support.ValuesSourceType;
@@ -38,11 +37,6 @@ public class SumParser extends NumericValuesSourceParser {
         super(true, true, false);
     }
 
-    @Override
-    public String type() {
-        return InternalSum.TYPE.name();
-    }
-
     @Override
     protected boolean token(String aggregationName, String currentFieldName, XContentParser.Token token, XContentParser parser,
             ParseFieldMatcher parseFieldMatcher, Map otherOptions) throws IOException {
@@ -54,9 +48,4 @@ public class SumParser extends NumericValuesSourceParser {
             ValueType targetValueType, Map otherOptions) {
         return new SumAggregatorBuilder(aggregationName);
     }
-
-    @Override
-    public AggregatorBuilder getFactoryPrototypes() {
-        return SumAggregatorBuilder.PROTOTYPE;
-    }
 }

From 40b84d2ef6df2704a168c04e866714b35e7b3796 Mon Sep 17 00:00:00 2001
From: Clinton Gormley 
Date: Mon, 18 Apr 2016 21:00:27 +0200
Subject: [PATCH 048/561] Update mapping.asciidoc

Correct `fielddata.frequency.regex` to `fielddata.filter.regex` in breaking changes
---
 docs/reference/migration/migrate_5_0/mapping.asciidoc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/reference/migration/migrate_5_0/mapping.asciidoc b/docs/reference/migration/migrate_5_0/mapping.asciidoc
index 98a33d80aa9..bb250b172cb 100644
--- a/docs/reference/migration/migrate_5_0/mapping.asciidoc
+++ b/docs/reference/migration/migrate_5_0/mapping.asciidoc
@@ -107,7 +107,7 @@ Setting `fielddata.format: doc_values` in the mappings used to implicitly
 enable doc-values on a field. This no longer works: the only way to enable or
 disable doc-values is by using the `doc_values` property of mappings.
 
-==== `fielddata.frequency.regex`
+==== `fielddata.filter.regex`
 
 Regex filters are not supported anymore and will be dropped on upgrade.
 

From 68b4371bd919afa5b426f0ffebdf8018f4186d73 Mon Sep 17 00:00:00 2001
From: Nik Everett 
Date: Mon, 18 Apr 2016 14:30:07 -0400
Subject: [PATCH 049/561] Make readNamedWriteable and writeNamedWriteable
 public

Now anyone can read or write whatever, whenever.

Closes #17682
---
 .../common/io/stream/NamedWriteableAwareStreamInput.java        | 2 +-
 .../java/org/elasticsearch/common/io/stream/StreamInput.java    | 2 +-
 .../java/org/elasticsearch/common/io/stream/StreamOutput.java   | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/NamedWriteableAwareStreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/NamedWriteableAwareStreamInput.java
index e8787c766c8..ccfb2bbdd8d 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/NamedWriteableAwareStreamInput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/NamedWriteableAwareStreamInput.java
@@ -34,7 +34,7 @@ public class NamedWriteableAwareStreamInput extends FilterStreamInput {
     }
 
     @Override
-    > C readNamedWriteable(Class categoryClass) throws IOException {
+    public > C readNamedWriteable(Class categoryClass) throws IOException {
         String name = readString();
         Writeable.Reader reader = namedWriteableRegistry.getReader(categoryClass, name);
         C c = reader.read(this);
diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
index 601c7eb82ff..0bfbcfa3143 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
@@ -725,7 +725,7 @@ public abstract class StreamInput extends InputStream {
      * Default implementation throws {@link UnsupportedOperationException} as StreamInput doesn't hold a registry.
      * Use {@link FilterInputStream} instead which wraps a stream and supports a {@link NamedWriteableRegistry} too.
      */
-    > C readNamedWriteable(@SuppressWarnings("unused") Class categoryClass) throws IOException {
+    public > C readNamedWriteable(@SuppressWarnings("unused") Class categoryClass) throws IOException {
         throw new UnsupportedOperationException("can't read named writeable from StreamInput");
     }
 
diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
index 1ace1e6d5aa..716d6b861a2 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
@@ -687,7 +687,7 @@ public abstract class StreamOutput extends OutputStream {
     /**
      * Writes a {@link NamedWriteable} to the current stream, by first writing its name and then the object itself
      */
-    void writeNamedWriteable(NamedWriteable namedWriteable) throws IOException {
+    public void writeNamedWriteable(NamedWriteable namedWriteable) throws IOException {
         writeString(namedWriteable.getWriteableName());
         namedWriteable.writeTo(this);
     }

From 8cffe0fc282776e9846ca27258acc0c87ec33959 Mon Sep 17 00:00:00 2001
From: Nik Everett 
Date: Mon, 18 Apr 2016 14:33:20 -0400
Subject: [PATCH 050/561] Remove readOptionalQuery

Replace it with readOptionalNamedWriteable
---
 .../common/io/stream/StreamInput.java         | 20 +++++++++----------
 .../search/sort/FieldSortBuilder.java         |  2 +-
 .../search/sort/GeoDistanceSortBuilder.java   |  2 +-
 .../search/sort/ScriptSortBuilder.java        |  2 +-
 4 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
index 0bfbcfa3143..4b30da0b9f5 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
@@ -729,6 +729,16 @@ public abstract class StreamInput extends InputStream {
         throw new UnsupportedOperationException("can't read named writeable from StreamInput");
     }
 
+    /**
+     * Reads an optional {@link QueryBuilder}.
+     */
+    public > C readOptionalNamedWriteable(Class categoryClass) throws IOException {
+        if (readBoolean()) {
+            return readNamedWriteable(categoryClass);
+        }
+        return null;
+    }
+
     /**
      * Reads a {@link AggregatorBuilder} from the current stream
      */
@@ -750,16 +760,6 @@ public abstract class StreamInput extends InputStream {
         return readNamedWriteable(QueryBuilder.class);
     }
 
-    /**
-     * Reads an optional {@link QueryBuilder}.
-     */
-    public QueryBuilder readOptionalQuery() throws IOException {
-        if (readBoolean()) {
-            return readNamedWriteable(QueryBuilder.class);
-        }
-        return null;
-    }
-
     /**
      * Reads a {@link ShapeBuilder} from the current stream
      */
diff --git a/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java
index dfced1d8f57..72a248db393 100644
--- a/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java
@@ -101,7 +101,7 @@ public class FieldSortBuilder extends SortBuilder {
      */
     public FieldSortBuilder(StreamInput in) throws IOException {
         fieldName = in.readString();
-        nestedFilter = in.readOptionalQuery();
+        nestedFilter = in.readOptionalNamedWriteable(QueryBuilder.class);
         nestedPath = in.readOptionalString();
         missing = in.readGenericValue();
         order = in.readOptionalWriteable(SortOrder::readFromStream);
diff --git a/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java
index ef86c45afd8..dbefbb460ba 100644
--- a/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java
@@ -159,7 +159,7 @@ public class GeoDistanceSortBuilder extends SortBuilder
         unit = DistanceUnit.readFromStream(in);
         order = SortOrder.readFromStream(in);
         sortMode = in.readOptionalWriteable(SortMode::readFromStream);
-        nestedFilter = in.readOptionalQuery();
+        nestedFilter = in.readOptionalNamedWriteable(QueryBuilder.class);
         nestedPath = in.readOptionalString();
         coerce = in.readBoolean();
         ignoreMalformed =in.readBoolean();
diff --git a/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java
index 3e0314bda1b..93b7de74b61 100644
--- a/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java
@@ -118,7 +118,7 @@ public class ScriptSortBuilder extends SortBuilder {
         order = SortOrder.readFromStream(in);
         sortMode = in.readOptionalWriteable(SortMode::readFromStream);
         nestedPath = in.readOptionalString();
-        nestedFilter = in.readOptionalQuery();
+        nestedFilter = in.readOptionalNamedWriteable(QueryBuilder.class);
     }
 
     @Override

From 70d55b36e1280a1f4359567410bb41d6fdafe043 Mon Sep 17 00:00:00 2001
From: Nik Everett 
Date: Mon, 18 Apr 2016 14:36:24 -0400
Subject: [PATCH 051/561] Replace writeOptionalQuery with
 writeOptionalNamedWriteable

---
 .../common/io/stream/StreamInput.java         |  2 +-
 .../common/io/stream/StreamOutput.java        | 24 +++++++++----------
 .../search/sort/FieldSortBuilder.java         |  2 +-
 .../search/sort/GeoDistanceSortBuilder.java   |  2 +-
 .../search/sort/ScriptSortBuilder.java        |  2 +-
 5 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
index 4b30da0b9f5..0b819daf82c 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
@@ -730,7 +730,7 @@ public abstract class StreamInput extends InputStream {
     }
 
     /**
-     * Reads an optional {@link QueryBuilder}.
+     * Reads an optional {@link NamedWriteable}.
      */
     public > C readOptionalNamedWriteable(Class categoryClass) throws IOException {
         if (readBoolean()) {
diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
index 716d6b861a2..81cbad760d9 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
@@ -692,6 +692,18 @@ public abstract class StreamOutput extends OutputStream {
         namedWriteable.writeTo(this);
     }
 
+    /**
+     * Write an optional {@link QueryBuilder} to the stream.
+     */
+    public void writeOptionalNamedWriteable(@Nullable NamedWriteable namedWriteable) throws IOException {
+        if (namedWriteable == null) {
+            writeBoolean(false);
+        } else {
+            writeBoolean(true);
+            writeNamedWriteable(namedWriteable);
+        }
+    }
+
     /**
      * Writes a {@link AggregatorBuilder} to the current stream
      */
@@ -713,18 +725,6 @@ public abstract class StreamOutput extends OutputStream {
         writeNamedWriteable(queryBuilder);
     }
 
-    /**
-     * Write an optional {@link QueryBuilder} to the stream.
-     */
-    public void writeOptionalQuery(@Nullable QueryBuilder queryBuilder) throws IOException {
-        if (queryBuilder == null) {
-            writeBoolean(false);
-        } else {
-            writeBoolean(true);
-            writeQuery(queryBuilder);
-        }
-    }
-
     /**
      * Writes a {@link ShapeBuilder} to the current stream
      */
diff --git a/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java
index 72a248db393..8d89322e5cd 100644
--- a/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/sort/FieldSortBuilder.java
@@ -112,7 +112,7 @@ public class FieldSortBuilder extends SortBuilder {
     @Override
     public void writeTo(StreamOutput out) throws IOException {
         out.writeString(fieldName);
-        out.writeOptionalQuery(nestedFilter);
+        out.writeOptionalNamedWriteable(nestedFilter);
         out.writeOptionalString(nestedPath);
         out.writeGenericValue(missing);
         out.writeOptionalWriteable(order);
diff --git a/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java
index dbefbb460ba..e6570543c83 100644
--- a/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/sort/GeoDistanceSortBuilder.java
@@ -173,7 +173,7 @@ public class GeoDistanceSortBuilder extends SortBuilder
         unit.writeTo(out);
         order.writeTo(out);
         out.writeOptionalWriteable(sortMode);
-        out.writeOptionalQuery(nestedFilter);
+        out.writeOptionalNamedWriteable(nestedFilter);
         out.writeOptionalString(nestedPath);
         out.writeBoolean(coerce);
         out.writeBoolean(ignoreMalformed);
diff --git a/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java b/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java
index 93b7de74b61..5c58d10b67f 100644
--- a/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/sort/ScriptSortBuilder.java
@@ -128,7 +128,7 @@ public class ScriptSortBuilder extends SortBuilder {
         order.writeTo(out);
         out.writeOptionalWriteable(sortMode);
         out.writeOptionalString(nestedPath);
-        out.writeOptionalQuery(nestedFilter);
+        out.writeOptionalNamedWriteable(nestedFilter);
     }
 
     /**

From 4ba8bce3fd8f066c0c9ef04e8dd374a17fd6d3c7 Mon Sep 17 00:00:00 2001
From: Nik Everett 
Date: Mon, 18 Apr 2016 14:39:18 -0400
Subject: [PATCH 052/561] Replace (read|write)AggregatorBuilder with
 (read|write)NamedWriteable

---
 .../common/io/stream/StreamInput.java              |  7 -------
 .../common/io/stream/StreamOutput.java             |  7 -------
 .../search/aggregations/AggregatorFactories.java   | 14 ++++++--------
 .../aggregations/BaseAggregationTestCase.java      |  4 ++--
 4 files changed, 8 insertions(+), 24 deletions(-)

diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
index 0b819daf82c..f4cf824fdd4 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
@@ -739,13 +739,6 @@ public abstract class StreamInput extends InputStream {
         return null;
     }
 
-    /**
-     * Reads a {@link AggregatorBuilder} from the current stream
-     */
-    public AggregatorBuilder readAggregatorBuilder() throws IOException {
-        return readNamedWriteable(AggregatorBuilder.class);
-    }
-
     /**
      * Reads a {@link PipelineAggregatorBuilder} from the current stream
      */
diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
index 81cbad760d9..f574c8fda2b 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
@@ -704,13 +704,6 @@ public abstract class StreamOutput extends OutputStream {
         }
     }
 
-    /**
-     * Writes a {@link AggregatorBuilder} to the current stream
-     */
-    public void writeAggregatorBuilder(AggregatorBuilder builder) throws IOException {
-        writeNamedWriteable(builder);
-    }
-
     /**
      * Writes a {@link PipelineAggregatorBuilder} to the current stream
      */
diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java b/core/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java
index f295e8849af..b84c0cda5df 100644
--- a/core/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java
+++ b/core/src/main/java/org/elasticsearch/search/aggregations/AggregatorFactories.java
@@ -277,13 +277,11 @@ public class AggregatorFactories {
             Builder builder = new Builder();
             int factoriesSize = in.readVInt();
             for (int i = 0; i < factoriesSize; i++) {
-                AggregatorBuilder factory = in.readAggregatorBuilder();
-                builder.addAggregator(factory);
+                builder.addAggregator(in.readNamedWriteable(AggregatorBuilder.class));
             }
             int pipelineFactoriesSize = in.readVInt();
             for (int i = 0; i < pipelineFactoriesSize; i++) {
-                PipelineAggregatorBuilder factory = in.readPipelineAggregatorBuilder();
-                builder.addPipelineAggregator(factory);
+                builder.addPipelineAggregator(in.readNamedWriteable(PipelineAggregatorBuilder.class));
             }
             return builder;
         }
@@ -291,12 +289,12 @@ public class AggregatorFactories {
         @Override
         public void writeTo(StreamOutput out) throws IOException {
             out.writeVInt(this.aggregatorBuilders.size());
-            for (AggregatorBuilder factory : aggregatorBuilders) {
-                out.writeAggregatorBuilder(factory);
+            for (AggregatorBuilder builder : aggregatorBuilders) {
+                out.writeNamedWriteable(builder);
             }
             out.writeVInt(this.pipelineAggregatorBuilders.size());
-            for (PipelineAggregatorBuilder factory : pipelineAggregatorBuilders) {
-                out.writePipelineAggregatorBuilder(factory);
+            for (PipelineAggregatorBuilder builder : pipelineAggregatorBuilders) {
+                out.writeNamedWriteable(builder);
             }
         }
 
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java
index 5e5dc92393a..329b90058e4 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/BaseAggregationTestCase.java
@@ -251,9 +251,9 @@ public abstract class BaseAggregationTestCase>
     public void testSerialization() throws IOException {
         AB testAgg = createTestAggregatorBuilder();
         try (BytesStreamOutput output = new BytesStreamOutput()) {
-            output.writeAggregatorBuilder(testAgg);
+            output.writeNamedWriteable(testAgg);
             try (StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(output.bytes()), namedWriteableRegistry)) {
-                AggregatorBuilder deserialized = in.readAggregatorBuilder();
+                AggregatorBuilder deserialized = in.readNamedWriteable(AggregatorBuilder.class);
                 assertEquals(testAgg, deserialized);
                 assertEquals(testAgg.hashCode(), deserialized.hashCode());
                 assertNotSame(testAgg, deserialized);

From d22603831da67f41f097ad87c73b7c99b9e1e3f2 Mon Sep 17 00:00:00 2001
From: Nik Everett 
Date: Mon, 18 Apr 2016 14:41:28 -0400
Subject: [PATCH 053/561] Replace (read|write)PipelineAggregatorBuilder with
 (read|write)NamedWriteable

---
 .../org/elasticsearch/common/io/stream/StreamInput.java   | 7 -------
 .../org/elasticsearch/common/io/stream/StreamOutput.java  | 7 -------
 .../aggregations/BasePipelineAggregationTestCase.java     | 8 ++++----
 3 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
index f4cf824fdd4..92506214480 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
@@ -739,13 +739,6 @@ public abstract class StreamInput extends InputStream {
         return null;
     }
 
-    /**
-     * Reads a {@link PipelineAggregatorBuilder} from the current stream
-     */
-    public PipelineAggregatorBuilder readPipelineAggregatorBuilder() throws IOException {
-        return readNamedWriteable(PipelineAggregatorBuilder.class);
-    }
-
     /**
      * Reads a {@link QueryBuilder} from the current stream
      */
diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
index f574c8fda2b..c3c6e5c1671 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
@@ -704,13 +704,6 @@ public abstract class StreamOutput extends OutputStream {
         }
     }
 
-    /**
-     * Writes a {@link PipelineAggregatorBuilder} to the current stream
-     */
-    public void writePipelineAggregatorBuilder(PipelineAggregatorBuilder builder) throws IOException {
-        writeNamedWriteable(builder);
-    }
-
     /**
      * Writes a {@link QueryBuilder} to the current stream
      */
diff --git a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java
index 29db7aee5e9..daee1782f4b 100644
--- a/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java
+++ b/core/src/test/java/org/elasticsearch/search/aggregations/BasePipelineAggregationTestCase.java
@@ -256,9 +256,9 @@ public abstract class BasePipelineAggregationTestCase deserializedQuery = in.readNamedWriteable(PipelineAggregatorBuilder.class);
                 assertEquals(deserializedQuery, testAgg);
                 assertEquals(deserializedQuery.hashCode(), testAgg.hashCode());
                 assertNotSame(deserializedQuery, testAgg);
@@ -296,10 +296,10 @@ public abstract class BasePipelineAggregationTestCase
Date: Mon, 18 Apr 2016 14:43:40 -0400
Subject: [PATCH 054/561] Replace (read|write)Shape with
 (read|write)NamedWriteable

---
 .../common/geo/builders/GeometryCollectionBuilder.java     | 4 ++--
 .../org/elasticsearch/common/io/stream/StreamInput.java    | 7 -------
 .../org/elasticsearch/common/io/stream/StreamOutput.java   | 7 -------
 .../elasticsearch/index/query/GeoShapeQueryBuilder.java    | 4 ++--
 4 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/core/src/main/java/org/elasticsearch/common/geo/builders/GeometryCollectionBuilder.java b/core/src/main/java/org/elasticsearch/common/geo/builders/GeometryCollectionBuilder.java
index b8559fcb48f..de6ed35ff90 100644
--- a/core/src/main/java/org/elasticsearch/common/geo/builders/GeometryCollectionBuilder.java
+++ b/core/src/main/java/org/elasticsearch/common/geo/builders/GeometryCollectionBuilder.java
@@ -53,7 +53,7 @@ public class GeometryCollectionBuilder extends ShapeBuilder {
     public GeometryCollectionBuilder(StreamInput in) throws IOException {
         int shapes = in.readVInt();
         for (int i = 0; i < shapes; i++) {
-            shape(in.readShape());
+            shape(in.readNamedWriteable(ShapeBuilder.class));
         }
     }
 
@@ -61,7 +61,7 @@ public class GeometryCollectionBuilder extends ShapeBuilder {
     public void writeTo(StreamOutput out) throws IOException {
         out.writeVInt(shapes.size());
         for (ShapeBuilder shape : shapes) {
-            out.writeShape(shape);
+            out.writeNamedWriteable(shape);
         }
     }
 
diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
index 92506214480..3d05c0908b7 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
@@ -746,13 +746,6 @@ public abstract class StreamInput extends InputStream {
         return readNamedWriteable(QueryBuilder.class);
     }
 
-    /**
-     * Reads a {@link ShapeBuilder} from the current stream
-     */
-    public ShapeBuilder readShape() throws IOException {
-        return readNamedWriteable(ShapeBuilder.class);
-    }
-
     /**
      * Reads a {@link RescoreBuilder} from the current stream
      */
diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
index c3c6e5c1671..9d648dff7bd 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
@@ -711,13 +711,6 @@ public abstract class StreamOutput extends OutputStream {
         writeNamedWriteable(queryBuilder);
     }
 
-    /**
-     * Writes a {@link ShapeBuilder} to the current stream
-     */
-    public void writeShape(ShapeBuilder shapeBuilder) throws IOException {
-        writeNamedWriteable(shapeBuilder);
-    }
-
     /**
      * Writes a {@link ScoreFunctionBuilder} to the current stream
      */
diff --git a/core/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java
index e1734394e5b..e39c89a1590 100644
--- a/core/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java
+++ b/core/src/main/java/org/elasticsearch/index/query/GeoShapeQueryBuilder.java
@@ -144,7 +144,7 @@ public class GeoShapeQueryBuilder extends AbstractQueryBuilder
Date: Mon, 18 Apr 2016 14:45:26 -0400
Subject: [PATCH 055/561] Replace (read|write)Rescorer with
 (read|write)NamedWriteable

---
 .../elasticsearch/common/io/stream/StreamInput.java   | 11 -----------
 .../elasticsearch/common/io/stream/StreamOutput.java  | 11 -----------
 .../search/builder/SearchSourceBuilder.java           |  4 ++--
 .../search/rescore/QueryRescoreBuilderTests.java      |  4 ++--
 4 files changed, 4 insertions(+), 26 deletions(-)

diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
index 3d05c0908b7..6516926edd1 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
@@ -34,14 +34,10 @@ import org.elasticsearch.common.Strings;
 import org.elasticsearch.common.bytes.BytesArray;
 import org.elasticsearch.common.bytes.BytesReference;
 import org.elasticsearch.common.geo.GeoPoint;
-import org.elasticsearch.common.geo.builders.ShapeBuilder;
 import org.elasticsearch.common.text.Text;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder;
 import org.elasticsearch.search.DocValueFormat;
-import org.elasticsearch.search.aggregations.AggregatorBuilder;
-import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
-import org.elasticsearch.search.rescore.RescoreBuilder;
 import org.elasticsearch.search.sort.SortBuilder;
 import org.elasticsearch.search.suggest.SuggestionBuilder;
 import org.elasticsearch.search.suggest.phrase.SmoothingModel;
@@ -746,13 +742,6 @@ public abstract class StreamInput extends InputStream {
         return readNamedWriteable(QueryBuilder.class);
     }
 
-    /**
-     * Reads a {@link RescoreBuilder} from the current stream
-     */
-    public RescoreBuilder readRescorer() throws IOException {
-        return readNamedWriteable(RescoreBuilder.class);
-    }
-
     /**
      * Reads a {@link SuggestionBuilder} from the current stream
      */
diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
index 9d648dff7bd..02c55609b5b 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
@@ -33,14 +33,10 @@ import org.elasticsearch.cluster.routing.allocation.command.AllocationCommand;
 import org.elasticsearch.common.Nullable;
 import org.elasticsearch.common.bytes.BytesReference;
 import org.elasticsearch.common.geo.GeoPoint;
-import org.elasticsearch.common.geo.builders.ShapeBuilder;
 import org.elasticsearch.common.text.Text;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder;
 import org.elasticsearch.search.DocValueFormat;
-import org.elasticsearch.search.aggregations.AggregatorBuilder;
-import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilder;
-import org.elasticsearch.search.rescore.RescoreBuilder;
 import org.elasticsearch.search.sort.SortBuilder;
 import org.elasticsearch.search.suggest.SuggestionBuilder;
 import org.elasticsearch.search.suggest.phrase.SmoothingModel;
@@ -769,13 +765,6 @@ public abstract class StreamOutput extends OutputStream {
         }
      }
 
-     /**
-     * Writes a {@link RescoreBuilder} to the current stream
-     */
-    public void writeRescorer(RescoreBuilder rescorer) throws IOException {
-        writeNamedWriteable(rescorer);
-    }
-
     /**
      * Writes a {@link SuggestionBuilder} to the current stream
      */
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 3675320184b..c7fc0948272 100644
--- a/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java
+++ b/core/src/main/java/org/elasticsearch/search/builder/SearchSourceBuilder.java
@@ -226,7 +226,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ
             int size = in.readVInt();
             rescoreBuilders = new ArrayList<>();
             for (int i = 0; i < size; i++) {
-                rescoreBuilders.add(in.readRescorer());
+                rescoreBuilders.add(in.readNamedWriteable(RescoreBuilder.class));
             }
         }
         if (in.readBoolean()) {
@@ -328,7 +328,7 @@ public final class SearchSourceBuilder extends ToXContentToBytes implements Writ
         if (hasRescoreBuilders) {
             out.writeVInt(rescoreBuilders.size());
             for (RescoreBuilder rescoreBuilder : rescoreBuilders) {
-                out.writeRescorer(rescoreBuilder);
+                out.writeNamedWriteable(rescoreBuilder);
             }
         }
         boolean hasScriptFields = scriptFields != null;
diff --git a/core/src/test/java/org/elasticsearch/search/rescore/QueryRescoreBuilderTests.java b/core/src/test/java/org/elasticsearch/search/rescore/QueryRescoreBuilderTests.java
index 1b221e3199d..de3df9b34aa 100644
--- a/core/src/test/java/org/elasticsearch/search/rescore/QueryRescoreBuilderTests.java
+++ b/core/src/test/java/org/elasticsearch/search/rescore/QueryRescoreBuilderTests.java
@@ -335,9 +335,9 @@ public class QueryRescoreBuilderTests extends ESTestCase {
 
     private static RescoreBuilder serializedCopy(RescoreBuilder original) throws IOException {
         try (BytesStreamOutput output = new BytesStreamOutput()) {
-            output.writeRescorer(original);
+            output.writeNamedWriteable(original);
             try (StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(output.bytes()), namedWriteableRegistry)) {
-                return in.readRescorer();
+                return in.readNamedWriteable(RescoreBuilder.class);
             }
         }
     }

From ff9b28d806629c929cd61517437a627de77799ec Mon Sep 17 00:00:00 2001
From: Nik Everett 
Date: Mon, 18 Apr 2016 15:04:23 -0400
Subject: [PATCH 056/561] Deprecate remaining readXYZ|writeXYZ methods

---
 .../common/io/stream/StreamInput.java         | 16 +++++++++++++++
 .../common/io/stream/StreamOutput.java        | 20 ++++++++++++++++++-
 .../deletebyquery/DeleteByQueryRequest.java   |  4 ++--
 3 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
index 6516926edd1..887a30afb13 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
@@ -737,56 +737,72 @@ public abstract class StreamInput extends InputStream {
 
     /**
      * Reads a {@link QueryBuilder} from the current stream
+     * @deprecated prefer {@link #readNamedWriteable(Class)} passing {@link QueryBuilder}.
      */
+    @Deprecated
     public QueryBuilder readQuery() throws IOException {
         return readNamedWriteable(QueryBuilder.class);
     }
 
     /**
      * Reads a {@link SuggestionBuilder} from the current stream
+     * @deprecated prefer {@link #readNamedWriteable(Class)} passing {@link SuggestionBuilder}.
      */
+    @Deprecated
     public SuggestionBuilder readSuggestion() throws IOException {
         return readNamedWriteable(SuggestionBuilder.class);
     }
 
     /**
      * Reads a {@link SortBuilder} from the current stream
+     * @deprecated prefer {@link #readNamedWriteable(Class)} passing {@link SortBuilder}.
      */
+    @Deprecated
     public SortBuilder readSortBuilder() throws IOException {
         return readNamedWriteable(SortBuilder.class);
     }
 
     /**
      * Reads a {@link org.elasticsearch.index.query.functionscore.ScoreFunctionBuilder} from the current stream
+     * @deprecated prefer {@link #readNamedWriteable(Class)} passing {@link ScoreFunctionBuilder}.
      */
+    @Deprecated
     public ScoreFunctionBuilder readScoreFunction() throws IOException {
         return readNamedWriteable(ScoreFunctionBuilder.class);
     }
 
     /**
      * Reads a {@link SmoothingModel} from the current stream
+     * @deprecated prefer {@link #readNamedWriteable(Class)} passing {@link SmoothingModel}.
      */
+    @Deprecated
     public SmoothingModel readPhraseSuggestionSmoothingModel() throws IOException {
         return readNamedWriteable(SmoothingModel.class);
     }
 
     /**
      * Reads a {@link Task.Status} from the current stream.
+     * @deprecated prefer {@link #readNamedWriteable(Class)} passing {@link Task.Status}.
      */
+    @Deprecated
     public Task.Status readTaskStatus() throws IOException {
         return readNamedWriteable(Task.Status.class);
     }
 
     /**
      * Reads a {@link DocValueFormat} from the current stream.
+     * @deprecated prefer {@link #readNamedWriteable(Class)} passing {@link DocValueFormat}.
      */
+    @Deprecated
     public DocValueFormat readValueFormat() throws IOException {
         return readNamedWriteable(DocValueFormat.class);
     }
 
     /**
      * Reads an {@link AllocationCommand} from the stream.
+     * @deprecated prefer {@link #readNamedWriteable(Class)} passing {@link AllocationCommand}.
      */
+    @Deprecated
     public AllocationCommand readAllocationCommand() throws IOException {
         return readNamedWriteable(AllocationCommand.class);
     }
diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
index 02c55609b5b..1a0213ca094 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
@@ -702,28 +702,36 @@ public abstract class StreamOutput extends OutputStream {
 
     /**
      * Writes a {@link QueryBuilder} to the current stream
+     * @deprecated prefer {@link #writeNamedWriteable(NamedWriteable)}
      */
+    @Deprecated
     public void writeQuery(QueryBuilder queryBuilder) throws IOException {
         writeNamedWriteable(queryBuilder);
     }
 
     /**
      * Writes a {@link ScoreFunctionBuilder} to the current stream
+     * @deprecated prefer {@link #writeNamedWriteable(NamedWriteable)}
      */
+    @Deprecated
     public void writeScoreFunction(ScoreFunctionBuilder scoreFunctionBuilder) throws IOException {
         writeNamedWriteable(scoreFunctionBuilder);
     }
 
     /**
      * Writes the given {@link SmoothingModel} to the stream
+     * @deprecated prefer {@link #writeNamedWriteable(NamedWriteable)}
      */
+    @Deprecated
     public void writePhraseSuggestionSmoothingModel(SmoothingModel smoothinModel) throws IOException {
         writeNamedWriteable(smoothinModel);
     }
 
     /**
      * Writes a {@link Task.Status} to the current stream.
+     * @deprecated prefer {@link #writeNamedWriteable(NamedWriteable)}
      */
+    @Deprecated
     public void writeTaskStatus(Task.Status status) throws IOException {
         writeNamedWriteable(status);
     }
@@ -767,26 +775,36 @@ public abstract class StreamOutput extends OutputStream {
 
     /**
      * Writes a {@link SuggestionBuilder} to the current stream
+     * @deprecated prefer {@link #writeNamedWriteable(NamedWriteable)}
      */
+    @Deprecated
     public void writeSuggestion(SuggestionBuilder suggestion) throws IOException {
         writeNamedWriteable(suggestion);
     }
 
     /**
      * Writes a {@link SortBuilder} to the current stream
+     * @deprecated prefer {@link #writeNamedWriteable(NamedWriteable)}
      */
+    @Deprecated
     public void writeSortBuilder(SortBuilder sort) throws IOException {
         writeNamedWriteable(sort);
     }
 
-    /** Writes a {@link DocValueFormat}. */
+    /**
+     * Writes a {@link DocValueFormat}.
+     * @deprecated prefer {@link #writeNamedWriteable(NamedWriteable)}
+     */
+    @Deprecated
     public void writeValueFormat(DocValueFormat format) throws IOException {
         writeNamedWriteable(format);
     }
 
     /**
      * Writes an {@link AllocationCommand} to the stream.
+     * @deprecated prefer {@link #writeNamedWriteable(NamedWriteable)}
      */
+    @Deprecated
     public void writeAllocationCommand(AllocationCommand command) throws IOException {
         writeNamedWriteable(command);
     }
diff --git a/plugins/delete-by-query/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryRequest.java b/plugins/delete-by-query/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryRequest.java
index 7103cf1a4e0..145ef690dc3 100644
--- a/plugins/delete-by-query/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryRequest.java
+++ b/plugins/delete-by-query/src/main/java/org/elasticsearch/action/deletebyquery/DeleteByQueryRequest.java
@@ -208,7 +208,7 @@ public class DeleteByQueryRequest extends ActionRequest im
         indices = in.readStringArray();
         indicesOptions = IndicesOptions.readIndicesOptions(in);
         types = in.readStringArray();
-        query = in.readQuery();
+        query = in.readNamedWriteable(QueryBuilder.class);
         routing = in.readOptionalString();
         size = in.readVInt();
         if (in.readBoolean()) {
@@ -225,7 +225,7 @@ public class DeleteByQueryRequest extends ActionRequest im
         out.writeStringArray(indices);
         indicesOptions.writeIndicesOptions(out);
         out.writeStringArray(types);
-        out.writeQuery(query);
+        out.writeNamedWriteable(query);
         out.writeOptionalString(routing);
         out.writeVInt(size);
         out.writeOptionalStreamable(scroll);

From 23dc2d18a285ea19b443ff1b5d1ad151243ef261 Mon Sep 17 00:00:00 2001
From: Nik Everett 
Date: Mon, 18 Apr 2016 16:21:50 -0400
Subject: [PATCH 057/561] Fix javadoc for new methods

---
 .../java/org/elasticsearch/common/io/stream/StreamInput.java    | 1 +
 .../java/org/elasticsearch/common/io/stream/StreamOutput.java   | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
index 887a30afb13..5469ced526f 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
@@ -721,6 +721,7 @@ public abstract class StreamInput extends InputStream {
      * Default implementation throws {@link UnsupportedOperationException} as StreamInput doesn't hold a registry.
      * Use {@link FilterInputStream} instead which wraps a stream and supports a {@link NamedWriteableRegistry} too.
      */
+    @Nullable
     public > C readNamedWriteable(@SuppressWarnings("unused") Class categoryClass) throws IOException {
         throw new UnsupportedOperationException("can't read named writeable from StreamInput");
     }
diff --git a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
index 1a0213ca094..fac66d42265 100644
--- a/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
+++ b/core/src/main/java/org/elasticsearch/common/io/stream/StreamOutput.java
@@ -689,7 +689,7 @@ public abstract class StreamOutput extends OutputStream {
     }
 
     /**
-     * Write an optional {@link QueryBuilder} to the stream.
+     * Write an optional {@link NamedWriteable} to the stream.
      */
     public void writeOptionalNamedWriteable(@Nullable NamedWriteable namedWriteable) throws IOException {
         if (namedWriteable == null) {

From fbe1f50b1893110b1370a3f105482c9e7df96cb4 Mon Sep 17 00:00:00 2001
From: Ryan Ernst 
Date: Mon, 18 Apr 2016 14:24:11 -0700
Subject: [PATCH 058/561] Add check that no dynamic update was done with
 existing mappings and dots

---
 .../java/org/elasticsearch/index/mapper/DocumentParserTests.java | 1 +
 1 file changed, 1 insertion(+)

diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java
index a3b56ec9fc5..cf1cbfd4d30 100644
--- a/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java
+++ b/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java
@@ -90,6 +90,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
             .endObject()
             .endObject().bytes();
         ParsedDocument doc = mapper.parse("test", "type", "1", bytes);
+        assertNull(doc.dynamicMappingsUpdate()); // no update!
         String[] values = doc.rootDoc().getValues("foo.bar.baz");
         assertEquals(3, values.length);
         assertEquals("123", values[0]);

From 523b071836be9c9b954c9e45a026311c83483c05 Mon Sep 17 00:00:00 2001
From: Ryan Ernst 
Date: Mon, 18 Apr 2016 14:32:18 -0700
Subject: [PATCH 059/561] Internal: Remove XContentBuilderString

This was previously used by xcontentbuilder to support camelCase.
However, it is no longer used, and can be replaced with just String.
---
 .../action/DocWriteResponse.java              |   9 +-
 .../action/ReplicationResponse.java           |  25 +-
 .../cluster/health/ClusterHealthResponse.java |  39 +-
 .../verify/VerifyRepositoryResponse.java      |   5 +-
 .../create/CreateSnapshotResponse.java        |   5 +-
 .../snapshots/get/GetSnapshotsResponse.java   |   3 +-
 .../restore/RestoreSnapshotResponse.java      |   5 +-
 .../status/SnapshotIndexShardStatus.java      |   7 +-
 .../snapshots/status/SnapshotIndexStatus.java |   3 +-
 .../snapshots/status/SnapshotShardsStats.java |  15 +-
 .../snapshots/status/SnapshotStats.java       |  21 +-
 .../snapshots/status/SnapshotStatus.java      |   9 +-
 .../status/SnapshotsStatusResponse.java       |   3 +-
 .../cluster/stats/ClusterStatsIndices.java    |  23 +-
 .../cluster/stats/ClusterStatsNodes.java      |  67 ++-
 .../cluster/stats/ClusterStatsResponse.java   |  11 +-
 .../tasks/PendingClusterTasksResponse.java    |  15 +-
 .../indices/analyze/AnalyzeResponse.java      |  15 +-
 .../analyze/DetailAnalyzeResponse.java        |  15 +-
 .../indices/flush/SyncedFlushResponse.java    |  17 +-
 .../segments/IndicesSegmentResponse.java      |  51 ++-
 .../shards/IndicesShardStoresResponse.java    |  17 +-
 .../indices/stats/IndicesStatsResponse.java   |   5 +-
 .../admin/indices/stats/ShardStats.java       |  19 +-
 .../upgrade/get/UpgradeStatusResponse.java    |  27 +-
 .../action/bulk/BulkItemResponse.java         |  11 +-
 .../action/delete/DeleteResponse.java         |   3 +-
 .../action/fieldstats/FieldStats.java         |  19 +-
 .../action/get/MultiGetResponse.java          |  15 +-
 .../action/index/IndexResponse.java           |   3 +-
 .../ingest/SimulatePipelineResponse.java      |   3 +-
 .../percolate/MultiPercolateResponse.java     |   5 +-
 .../action/percolate/PercolateResponse.java   |  15 +-
 .../action/search/ClearScrollResponse.java    |   5 +-
 .../action/search/MultiSearchResponse.java    |   9 +-
 .../action/search/SearchResponse.java         |   9 +-
 .../termvectors/MultiTermVectorsResponse.java |  11 +-
 .../termvectors/TermVectorsResponse.java      |  47 ++-
 .../action/update/UpdateResponse.java         |   3 +-
 .../cluster/SnapshotsInProgress.java          |  27 +-
 .../cluster/health/ClusterIndexHealth.java    |  23 +-
 .../elasticsearch/common/unit/Fuzziness.java  |   5 +-
 .../common/xcontent/XContentBuilder.java      | 381 +-----------------
 .../xcontent/XContentBuilderString.java       |  36 --
 .../common/xcontent/XContentGenerator.java    |  23 --
 .../common/xcontent/XContentParser.java       |   4 +-
 .../common/xcontent/XContentString.java       |  32 --
 .../xcontent/json/JsonXContentGenerator.java  |  66 ---
 .../discovery/DiscoveryStats.java             |   3 +-
 .../zen/publish/PendingClusterStateStats.java |   9 +-
 .../java/org/elasticsearch/http/HttpInfo.java |  11 +-
 .../org/elasticsearch/http/HttpStats.java     |   9 +-
 .../index/cache/query/QueryCacheStats.java    |  19 +-
 .../cache/request/RequestCacheStats.java      |  13 +-
 .../index/engine/CommitStats.java             |  11 +-
 .../index/engine/SegmentsStats.java           |  57 ++-
 .../index/fielddata/FieldDataStats.java       |  11 +-
 .../elasticsearch/index/flush/FlushStats.java |  11 +-
 .../elasticsearch/index/get/GetResult.java    |  13 +-
 .../org/elasticsearch/index/get/GetStats.java |  23 +-
 .../elasticsearch/index/merge/MergeStats.java |  35 +-
 .../percolator/PercolatorQueryCacheStats.java |   5 +-
 .../index/recovery/RecoveryStats.java         |  11 +-
 .../index/refresh/RefreshStats.java           |  11 +-
 .../index/search/stats/SearchStats.java       |  39 +-
 .../elasticsearch/index/shard/DocsStats.java  |   7 +-
 .../index/shard/IndexingStats.java            |  31 +-
 .../BlobStoreIndexShardSnapshot.java          |  29 +-
 .../BlobStoreIndexShardSnapshots.java         |   5 +-
 .../elasticsearch/index/store/StoreStats.java |  11 +-
 .../index/translog/TranslogStats.java         |   9 +-
 .../index/warmer/WarmerStats.java             |  13 +-
 .../indices/NodeIndicesStats.java             |   3 +-
 .../breaker/AllCircuitBreakerStats.java       |   3 +-
 .../indices/breaker/CircuitBreakerStats.java  |  13 +-
 .../indices/recovery/RecoveryState.java       |  77 ++--
 .../org/elasticsearch/monitor/fs/FsInfo.java  |  29 +-
 .../elasticsearch/monitor/jvm/JvmInfo.java    |  45 +--
 .../elasticsearch/monitor/jvm/JvmStats.java   |  83 ++--
 .../org/elasticsearch/monitor/os/OsInfo.java  |  17 +-
 .../org/elasticsearch/monitor/os/OsStats.java |  37 +-
 .../monitor/process/ProcessInfo.java          |  11 +-
 .../monitor/process/ProcessStats.java         |  23 +-
 .../org/elasticsearch/plugins/PluginInfo.java |  11 +-
 .../cluster/state/RestClusterStateAction.java |   3 +-
 .../alias/get/RestGetAliasesAction.java       |   3 +-
 .../indices/get/RestGetIndicesAction.java     |   7 +-
 .../mapping/get/RestGetMappingAction.java     |   3 +-
 .../query/RestValidateQueryAction.java        |  11 +-
 .../rest/action/bulk/RestBulkAction.java      |   9 +-
 .../action/explain/RestExplainAction.java     |  19 +-
 .../script/RestDeleteIndexedScriptAction.java |  11 +-
 .../script/RestGetIndexedScriptAction.java    |  13 +-
 .../script/RestPutIndexedScriptAction.java    |   7 +-
 .../support/AcknowledgedRestListener.java     |   3 +-
 .../rest/action/support/RestActions.java      |  11 +-
 .../template/RestGetSearchTemplateAction.java |   5 +-
 .../org/elasticsearch/script/ScriptStats.java |   7 +-
 .../aggregations/InternalAggregation.java     |  25 +-
 .../aggregations/InternalAggregations.java    |   3 +-
 .../geocentroid/InternalGeoCentroid.java      |   3 +-
 .../metrics/stats/InternalStats.java          |  19 +-
 .../stats/extended/InternalExtendedStats.java |  21 +-
 .../search/internal/InternalSearchHit.java    |  35 +-
 .../search/internal/InternalSearchHits.java   |   7 +-
 .../elasticsearch/search/suggest/Suggest.java |  19 +-
 .../suggest/completion/CompletionStats.java   |   9 +-
 .../suggest/phrase/PhraseSuggestion.java      |   3 +-
 .../search/suggest/term/TermSuggestion.java   |   3 +-
 .../elasticsearch/snapshots/RestoreInfo.java  |  15 +-
 .../org/elasticsearch/snapshots/Snapshot.java |  23 +-
 .../elasticsearch/snapshots/SnapshotInfo.java |  33 +-
 .../elasticsearch/threadpool/ThreadPool.java  |  11 +-
 .../threadpool/ThreadPoolInfo.java            |   3 +-
 .../threadpool/ThreadPoolStats.java           |  15 +-
 .../transport/TransportInfo.java              |   9 +-
 .../transport/TransportStats.java             |  19 +-
 .../builder/XContentBuilderTests.java         |   5 +-
 .../deletebyquery/DeleteByQueryResponse.java  |   9 +-
 .../IndexDeleteByQueryResponse.java           |  11 +-
 120 files changed, 867 insertions(+), 1479 deletions(-)
 delete mode 100644 core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilderString.java
 delete mode 100644 core/src/main/java/org/elasticsearch/common/xcontent/XContentString.java

diff --git a/core/src/main/java/org/elasticsearch/action/DocWriteResponse.java b/core/src/main/java/org/elasticsearch/action/DocWriteResponse.java
index 76093aa9cb7..4df43b75401 100644
--- a/core/src/main/java/org/elasticsearch/action/DocWriteResponse.java
+++ b/core/src/main/java/org/elasticsearch/action/DocWriteResponse.java
@@ -22,7 +22,6 @@ import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.StatusToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 import org.elasticsearch.index.shard.ShardId;
 import org.elasticsearch.rest.RestStatus;
 
@@ -110,10 +109,10 @@ public abstract class DocWriteResponse extends ReplicationResponse implements St
     }
 
     static final class Fields {
-        static final XContentBuilderString _INDEX = new XContentBuilderString("_index");
-        static final XContentBuilderString _TYPE = new XContentBuilderString("_type");
-        static final XContentBuilderString _ID = new XContentBuilderString("_id");
-        static final XContentBuilderString _VERSION = new XContentBuilderString("_version");
+        static final String _INDEX = "_index";
+        static final String _TYPE = "_type";
+        static final String _ID = "_id";
+        static final String _VERSION = "_version";
     }
 
     @Override
diff --git a/core/src/main/java/org/elasticsearch/action/ReplicationResponse.java b/core/src/main/java/org/elasticsearch/action/ReplicationResponse.java
index 8a81446d459..df2f90b0020 100644
--- a/core/src/main/java/org/elasticsearch/action/ReplicationResponse.java
+++ b/core/src/main/java/org/elasticsearch/action/ReplicationResponse.java
@@ -28,7 +28,6 @@ import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.io.stream.Streamable;
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 import org.elasticsearch.index.shard.ShardId;
 import org.elasticsearch.rest.RestStatus;
 
@@ -280,24 +279,24 @@ public class ReplicationResponse extends ActionResponse {
 
             private static class Fields {
 
-                private static final XContentBuilderString _INDEX = new XContentBuilderString("_index");
-                private static final XContentBuilderString _SHARD = new XContentBuilderString("_shard");
-                private static final XContentBuilderString _NODE = new XContentBuilderString("_node");
-                private static final XContentBuilderString REASON = new XContentBuilderString("reason");
-                private static final XContentBuilderString STATUS = new XContentBuilderString("status");
-                private static final XContentBuilderString PRIMARY = new XContentBuilderString("primary");
+                private static final String _INDEX = "_index";
+                private static final String _SHARD = "_shard";
+                private static final String _NODE = "_node";
+                private static final String REASON = "reason";
+                private static final String STATUS = "status";
+                private static final String PRIMARY = "primary";
 
             }
         }
 
         private static class Fields {
 
-            private static final XContentBuilderString _SHARDS = new XContentBuilderString("_shards");
-            private static final XContentBuilderString TOTAL = new XContentBuilderString("total");
-            private static final XContentBuilderString SUCCESSFUL = new XContentBuilderString("successful");
-            private static final XContentBuilderString PENDING = new XContentBuilderString("pending");
-            private static final XContentBuilderString FAILED = new XContentBuilderString("failed");
-            private static final XContentBuilderString FAILURES = new XContentBuilderString("failures");
+            private static final String _SHARDS = "_shards";
+            private static final String TOTAL = "total";
+            private static final String SUCCESSFUL = "successful";
+            private static final String PENDING = "pending";
+            private static final String FAILED = "failed";
+            private static final String FAILURES = "failures";
 
         }
     }
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java
index 7c0bd350289..d9b95af8516 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthResponse.java
@@ -30,7 +30,6 @@ import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.common.xcontent.StatusToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 import org.elasticsearch.common.xcontent.XContentFactory;
 import org.elasticsearch.rest.RestStatus;
 
@@ -234,25 +233,25 @@ public class ClusterHealthResponse extends ActionResponse implements StatusToXCo
     }
 
     static final class Fields {
-        static final XContentBuilderString CLUSTER_NAME = new XContentBuilderString("cluster_name");
-        static final XContentBuilderString STATUS = new XContentBuilderString("status");
-        static final XContentBuilderString TIMED_OUT = new XContentBuilderString("timed_out");
-        static final XContentBuilderString NUMBER_OF_NODES = new XContentBuilderString("number_of_nodes");
-        static final XContentBuilderString NUMBER_OF_DATA_NODES = new XContentBuilderString("number_of_data_nodes");
-        static final XContentBuilderString NUMBER_OF_PENDING_TASKS = new XContentBuilderString("number_of_pending_tasks");
-        static final XContentBuilderString NUMBER_OF_IN_FLIGHT_FETCH = new XContentBuilderString("number_of_in_flight_fetch");
-        static final XContentBuilderString DELAYED_UNASSIGNED_SHARDS = new XContentBuilderString("delayed_unassigned_shards");
-        static final XContentBuilderString TASK_MAX_WAIT_TIME_IN_QUEUE = new XContentBuilderString("task_max_waiting_in_queue");
-        static final XContentBuilderString TASK_MAX_WAIT_TIME_IN_QUEUE_IN_MILLIS = new XContentBuilderString("task_max_waiting_in_queue_millis");
-        static final XContentBuilderString ACTIVE_SHARDS_PERCENT_AS_NUMBER = new XContentBuilderString("active_shards_percent_as_number");
-        static final XContentBuilderString ACTIVE_SHARDS_PERCENT = new XContentBuilderString("active_shards_percent");
-        static final XContentBuilderString ACTIVE_PRIMARY_SHARDS = new XContentBuilderString("active_primary_shards");
-        static final XContentBuilderString ACTIVE_SHARDS = new XContentBuilderString("active_shards");
-        static final XContentBuilderString RELOCATING_SHARDS = new XContentBuilderString("relocating_shards");
-        static final XContentBuilderString INITIALIZING_SHARDS = new XContentBuilderString("initializing_shards");
-        static final XContentBuilderString UNASSIGNED_SHARDS = new XContentBuilderString("unassigned_shards");
-        static final XContentBuilderString VALIDATION_FAILURES = new XContentBuilderString("validation_failures");
-        static final XContentBuilderString INDICES = new XContentBuilderString("indices");
+        static final String CLUSTER_NAME = "cluster_name";
+        static final String STATUS = "status";
+        static final String TIMED_OUT = "timed_out";
+        static final String NUMBER_OF_NODES = "number_of_nodes";
+        static final String NUMBER_OF_DATA_NODES = "number_of_data_nodes";
+        static final String NUMBER_OF_PENDING_TASKS = "number_of_pending_tasks";
+        static final String NUMBER_OF_IN_FLIGHT_FETCH = "number_of_in_flight_fetch";
+        static final String DELAYED_UNASSIGNED_SHARDS = "delayed_unassigned_shards";
+        static final String TASK_MAX_WAIT_TIME_IN_QUEUE = "task_max_waiting_in_queue";
+        static final String TASK_MAX_WAIT_TIME_IN_QUEUE_IN_MILLIS = "task_max_waiting_in_queue_millis";
+        static final String ACTIVE_SHARDS_PERCENT_AS_NUMBER = "active_shards_percent_as_number";
+        static final String ACTIVE_SHARDS_PERCENT = "active_shards_percent";
+        static final String ACTIVE_PRIMARY_SHARDS = "active_primary_shards";
+        static final String ACTIVE_SHARDS = "active_shards";
+        static final String RELOCATING_SHARDS = "relocating_shards";
+        static final String INITIALIZING_SHARDS = "initializing_shards";
+        static final String UNASSIGNED_SHARDS = "unassigned_shards";
+        static final String VALIDATION_FAILURES = "validation_failures";
+        static final String INDICES = "indices";
     }
 
     @Override
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java
index 11020beac4a..823487155f5 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/repositories/verify/VerifyRepositoryResponse.java
@@ -26,7 +26,6 @@ import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 import org.elasticsearch.common.xcontent.XContentHelper;
 
 import java.io.IOException;
@@ -78,8 +77,8 @@ public class VerifyRepositoryResponse extends ActionResponse implements ToXConte
     }
 
     static final class Fields {
-        static final XContentBuilderString NODES = new XContentBuilderString("nodes");
-        static final XContentBuilderString NAME = new XContentBuilderString("name");
+        static final String NODES = "nodes";
+        static final String NAME = "name";
     }
 
     @Override
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotResponse.java
index c1c5e9f4658..0be07c703f1 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotResponse.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/create/CreateSnapshotResponse.java
@@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 import org.elasticsearch.rest.RestStatus;
 import org.elasticsearch.snapshots.SnapshotInfo;
 
@@ -83,8 +82,8 @@ public class CreateSnapshotResponse extends ActionResponse implements ToXContent
     }
 
     static final class Fields {
-        static final XContentBuilderString SNAPSHOT = new XContentBuilderString("snapshot");
-        static final XContentBuilderString ACCEPTED = new XContentBuilderString("accepted");
+        static final String SNAPSHOT = "snapshot";
+        static final String ACCEPTED = "accepted";
     }
 
     @Override
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsResponse.java
index 4ca88daad54..65b0e4faa4a 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsResponse.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/get/GetSnapshotsResponse.java
@@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 import org.elasticsearch.snapshots.SnapshotInfo;
 
 import java.io.IOException;
@@ -76,7 +75,7 @@ public class GetSnapshotsResponse extends ActionResponse implements ToXContent {
     }
 
     static final class Fields {
-        static final XContentBuilderString SNAPSHOTS = new XContentBuilderString("snapshots");
+        static final String SNAPSHOTS = "snapshots";
     }
 
     @Override
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotResponse.java
index 0101b95acc7..a54c01ed15a 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotResponse.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/restore/RestoreSnapshotResponse.java
@@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 import org.elasticsearch.rest.RestStatus;
 import org.elasticsearch.snapshots.RestoreInfo;
 
@@ -75,8 +74,8 @@ public class RestoreSnapshotResponse extends ActionResponse implements ToXConten
     }
 
     static final class Fields {
-        static final XContentBuilderString SNAPSHOT = new XContentBuilderString("snapshot");
-        static final XContentBuilderString ACCEPTED = new XContentBuilderString("accepted");
+        static final String SNAPSHOT = "snapshot";
+        static final String ACCEPTED = "accepted";
     }
 
     @Override
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotIndexShardStatus.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotIndexShardStatus.java
index 1f358915662..3d287eee9d1 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotIndexShardStatus.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotIndexShardStatus.java
@@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 import org.elasticsearch.index.shard.ShardId;
 import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus;
 
@@ -135,9 +134,9 @@ public class SnapshotIndexShardStatus extends BroadcastShardResponse implements
     }
 
     static final class Fields {
-        static final XContentBuilderString STAGE = new XContentBuilderString("stage");
-        static final XContentBuilderString REASON = new XContentBuilderString("reason");
-        static final XContentBuilderString NODE = new XContentBuilderString("node");
+        static final String STAGE = "stage";
+        static final String REASON = "reason";
+        static final String NODE = "node";
     }
 
     @Override
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotIndexStatus.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotIndexStatus.java
index 87d153a83fd..16c361d5ca6 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotIndexStatus.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotIndexStatus.java
@@ -21,7 +21,6 @@ package org.elasticsearch.action.admin.cluster.snapshots.status;
 
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 
 import java.io.IOException;
 import java.util.Collection;
@@ -91,7 +90,7 @@ public class SnapshotIndexStatus implements Iterable,
     }
 
     static final class Fields {
-        static final XContentBuilderString SHARDS = new XContentBuilderString("shards");
+        static final String SHARDS = "shards";
     }
 
     @Override
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotShardsStats.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotShardsStats.java
index ba3bd7a8c77..63bbed43182 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotShardsStats.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotShardsStats.java
@@ -21,7 +21,6 @@ package org.elasticsearch.action.admin.cluster.snapshots.status;
 
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 
 import java.io.IOException;
 import java.util.Collection;
@@ -106,13 +105,13 @@ public class SnapshotShardsStats  implements ToXContent {
     }
 
     static final class Fields {
-        static final XContentBuilderString SHARDS_STATS = new XContentBuilderString("shards_stats");
-        static final XContentBuilderString INITIALIZING = new XContentBuilderString("initializing");
-        static final XContentBuilderString STARTED = new XContentBuilderString("started");
-        static final XContentBuilderString FINALIZING = new XContentBuilderString("finalizing");
-        static final XContentBuilderString DONE = new XContentBuilderString("done");
-        static final XContentBuilderString FAILED = new XContentBuilderString("failed");
-        static final XContentBuilderString TOTAL = new XContentBuilderString("total");
+        static final String SHARDS_STATS = "shards_stats";
+        static final String INITIALIZING = "initializing";
+        static final String STARTED = "started";
+        static final String FINALIZING = "finalizing";
+        static final String DONE = "done";
+        static final String FAILED = "failed";
+        static final String TOTAL = "total";
     }
 
     @Override
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStats.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStats.java
index 5dd2617fea2..2e0e3f993a1 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStats.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStats.java
@@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.io.stream.Streamable;
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 import org.elasticsearch.index.snapshots.IndexShardSnapshotStatus;
 
 import java.io.IOException;
@@ -130,16 +129,16 @@ public class SnapshotStats implements Streamable, ToXContent {
     }
 
     static final class Fields {
-        static final XContentBuilderString STATS = new XContentBuilderString("stats");
-        static final XContentBuilderString NUMBER_OF_FILES = new XContentBuilderString("number_of_files");
-        static final XContentBuilderString PROCESSED_FILES = new XContentBuilderString("processed_files");
-        static final XContentBuilderString TOTAL_SIZE_IN_BYTES = new XContentBuilderString("total_size_in_bytes");
-        static final XContentBuilderString TOTAL_SIZE = new XContentBuilderString("total_size");
-        static final XContentBuilderString PROCESSED_SIZE_IN_BYTES = new XContentBuilderString("processed_size_in_bytes");
-        static final XContentBuilderString PROCESSED_SIZE = new XContentBuilderString("processed_size");
-        static final XContentBuilderString START_TIME_IN_MILLIS = new XContentBuilderString("start_time_in_millis");
-        static final XContentBuilderString TIME_IN_MILLIS = new XContentBuilderString("time_in_millis");
-        static final XContentBuilderString TIME = new XContentBuilderString("time");
+        static final String STATS = "stats";
+        static final String NUMBER_OF_FILES = "number_of_files";
+        static final String PROCESSED_FILES = "processed_files";
+        static final String TOTAL_SIZE_IN_BYTES = "total_size_in_bytes";
+        static final String TOTAL_SIZE = "total_size";
+        static final String PROCESSED_SIZE_IN_BYTES = "processed_size_in_bytes";
+        static final String PROCESSED_SIZE = "processed_size";
+        static final String START_TIME_IN_MILLIS = "start_time_in_millis";
+        static final String TIME_IN_MILLIS = "time_in_millis";
+        static final String TIME = "time";
     }
 
     @Override
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStatus.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStatus.java
index 860b414fa3e..54f87f3c5fc 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStatus.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotStatus.java
@@ -26,7 +26,6 @@ import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.io.stream.Streamable;
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 import org.elasticsearch.common.xcontent.XContentFactory;
 
 import java.io.IOException;
@@ -180,10 +179,10 @@ public class SnapshotStatus implements ToXContent, Streamable {
     }
 
     static final class Fields {
-        static final XContentBuilderString SNAPSHOT = new XContentBuilderString("snapshot");
-        static final XContentBuilderString REPOSITORY = new XContentBuilderString("repository");
-        static final XContentBuilderString STATE = new XContentBuilderString("state");
-        static final XContentBuilderString INDICES = new XContentBuilderString("indices");
+        static final String SNAPSHOT = "snapshot";
+        static final String REPOSITORY = "repository";
+        static final String STATE = "state";
+        static final String INDICES = "indices";
     }
 
     @Override
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotsStatusResponse.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotsStatusResponse.java
index e5692374fcb..34e503224ce 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotsStatusResponse.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/snapshots/status/SnapshotsStatusResponse.java
@@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.StreamInput;
 import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 
 import java.io.IOException;
 import java.util.ArrayList;
@@ -75,7 +74,7 @@ public class SnapshotsStatusResponse extends ActionResponse implements ToXConten
     }
 
     static final class Fields {
-        static final XContentBuilderString SNAPSHOTS = new XContentBuilderString("snapshots");
+        static final String SNAPSHOTS = "snapshots";
     }
 
     @Override
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIndices.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIndices.java
index f8304bf76a9..b23b6467288 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIndices.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsIndices.java
@@ -27,7 +27,6 @@ import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.io.stream.Streamable;
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 import org.elasticsearch.index.cache.query.QueryCacheStats;
 import org.elasticsearch.index.engine.SegmentsStats;
 import org.elasticsearch.index.fielddata.FieldDataStats;
@@ -165,7 +164,7 @@ public class ClusterStatsIndices implements ToXContent, Streamable {
     }
 
     static final class Fields {
-        static final XContentBuilderString COUNT = new XContentBuilderString("count");
+        static final String COUNT = "count";
     }
 
     @Override
@@ -362,17 +361,17 @@ public class ClusterStatsIndices implements ToXContent, Streamable {
         }
 
         static final class Fields {
-            static final XContentBuilderString SHARDS = new XContentBuilderString("shards");
-            static final XContentBuilderString TOTAL = new XContentBuilderString("total");
-            static final XContentBuilderString PRIMARIES = new XContentBuilderString("primaries");
-            static final XContentBuilderString REPLICATION = new XContentBuilderString("replication");
-            static final XContentBuilderString MIN = new XContentBuilderString("min");
-            static final XContentBuilderString MAX = new XContentBuilderString("max");
-            static final XContentBuilderString AVG = new XContentBuilderString("avg");
-            static final XContentBuilderString INDEX = new XContentBuilderString("index");
+            static final String SHARDS = "shards";
+            static final String TOTAL = "total";
+            static final String PRIMARIES = "primaries";
+            static final String REPLICATION = "replication";
+            static final String MIN = "min";
+            static final String MAX = "max";
+            static final String AVG = "avg";
+            static final String INDEX = "index";
         }
 
-        private void addIntMinMax(XContentBuilderString field, int min, int max, double avg, XContentBuilder builder) throws IOException {
+        private void addIntMinMax(String field, int min, int max, double avg, XContentBuilder builder) throws IOException {
             builder.startObject(field);
             builder.field(Fields.MIN, min);
             builder.field(Fields.MAX, max);
@@ -380,7 +379,7 @@ public class ClusterStatsIndices implements ToXContent, Streamable {
             builder.endObject();
         }
 
-        private void addDoubleMinMax(XContentBuilderString field, double min, double max, double avg, XContentBuilder builder) throws IOException {
+        private void addDoubleMinMax(String field, double min, double max, double avg, XContentBuilder builder) throws IOException {
             builder.startObject(field);
             builder.field(Fields.MIN, min);
             builder.field(Fields.MAX, max);
diff --git a/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java b/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java
index 61ec31b2699..992d3589a90 100644
--- a/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java
+++ b/core/src/main/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodes.java
@@ -35,7 +35,6 @@ import org.elasticsearch.common.unit.ByteSizeValue;
 import org.elasticsearch.common.unit.TimeValue;
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 import org.elasticsearch.monitor.fs.FsInfo;
 import org.elasticsearch.monitor.jvm.JvmInfo;
 import org.elasticsearch.plugins.PluginInfo;
@@ -163,13 +162,13 @@ public class ClusterStatsNodes implements ToXContent, Writeable implements Streamable, ToXContent {
 
     private final static class Fields {
 
-        final static XContentBuilderString MAX_DOC = new XContentBuilderString("max_doc");
-        final static XContentBuilderString DOC_COUNT = new XContentBuilderString("doc_count");
-        final static XContentBuilderString DENSITY = new XContentBuilderString("density");
-        final static XContentBuilderString SUM_DOC_FREQ = new XContentBuilderString("sum_doc_freq");
-        final static XContentBuilderString SUM_TOTAL_TERM_FREQ = new XContentBuilderString("sum_total_term_freq");
-        final static XContentBuilderString MIN_VALUE = new XContentBuilderString("min_value");
-        final static XContentBuilderString MIN_VALUE_AS_STRING = new XContentBuilderString("min_value_as_string");
-        final static XContentBuilderString MAX_VALUE = new XContentBuilderString("max_value");
-        final static XContentBuilderString MAX_VALUE_AS_STRING = new XContentBuilderString("max_value_as_string");
+        final static String MAX_DOC = new String("max_doc");
+        final static String DOC_COUNT = new String("doc_count");
+        final static String DENSITY = new String("density");
+        final static String SUM_DOC_FREQ = new String("sum_doc_freq");
+        final static String SUM_TOTAL_TERM_FREQ = new String("sum_total_term_freq");
+        final static String MIN_VALUE = new String("min_value");
+        final static String MIN_VALUE_AS_STRING = new String("min_value_as_string");
+        final static String MAX_VALUE = new String("max_value");
+        final static String MAX_VALUE_AS_STRING = new String("max_value_as_string");
 
     }
 
diff --git a/core/src/main/java/org/elasticsearch/action/get/MultiGetResponse.java b/core/src/main/java/org/elasticsearch/action/get/MultiGetResponse.java
index 32e10b82de2..891f1cf6597 100644
--- a/core/src/main/java/org/elasticsearch/action/get/MultiGetResponse.java
+++ b/core/src/main/java/org/elasticsearch/action/get/MultiGetResponse.java
@@ -26,7 +26,6 @@ import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.io.stream.Streamable;
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 
 import java.io.IOException;
 import java.util.Arrays;
@@ -151,12 +150,12 @@ public class MultiGetResponse extends ActionResponse implements Iterable implements Cus
     }
 
     static final class Fields {
-        static final XContentBuilderString REPOSITORY = new XContentBuilderString("repository");
-        static final XContentBuilderString SNAPSHOTS = new XContentBuilderString("snapshots");
-        static final XContentBuilderString SNAPSHOT = new XContentBuilderString("snapshot");
-        static final XContentBuilderString INCLUDE_GLOBAL_STATE = new XContentBuilderString("include_global_state");
-        static final XContentBuilderString PARTIAL = new XContentBuilderString("partial");
-        static final XContentBuilderString STATE = new XContentBuilderString("state");
-        static final XContentBuilderString INDICES = new XContentBuilderString("indices");
-        static final XContentBuilderString START_TIME_MILLIS = new XContentBuilderString("start_time_millis");
-        static final XContentBuilderString START_TIME = new XContentBuilderString("start_time");
-        static final XContentBuilderString SHARDS = new XContentBuilderString("shards");
-        static final XContentBuilderString INDEX = new XContentBuilderString("index");
-        static final XContentBuilderString SHARD = new XContentBuilderString("shard");
-        static final XContentBuilderString NODE = new XContentBuilderString("node");
+        static final String REPOSITORY = "repository";
+        static final String SNAPSHOTS = "snapshots";
+        static final String SNAPSHOT = "snapshot";
+        static final String INCLUDE_GLOBAL_STATE = "include_global_state";
+        static final String PARTIAL = "partial";
+        static final String STATE = "state";
+        static final String INDICES = "indices";
+        static final String START_TIME_MILLIS = "start_time_millis";
+        static final String START_TIME = "start_time";
+        static final String SHARDS = "shards";
+        static final String INDEX = "index";
+        static final String SHARD = "shard";
+        static final String NODE = "node";
     }
 
     @Override
diff --git a/core/src/main/java/org/elasticsearch/cluster/health/ClusterIndexHealth.java b/core/src/main/java/org/elasticsearch/cluster/health/ClusterIndexHealth.java
index ce1f3adb539..c511eb71f82 100644
--- a/core/src/main/java/org/elasticsearch/cluster/health/ClusterIndexHealth.java
+++ b/core/src/main/java/org/elasticsearch/cluster/health/ClusterIndexHealth.java
@@ -27,7 +27,6 @@ import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.io.stream.Streamable;
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 
 import java.io.IOException;
 import java.util.Arrays;
@@ -202,17 +201,17 @@ public final class ClusterIndexHealth implements Iterable, S
     }
 
     static final class Fields {
-        static final XContentBuilderString STATUS = new XContentBuilderString("status");
-        static final XContentBuilderString NUMBER_OF_SHARDS = new XContentBuilderString("number_of_shards");
-        static final XContentBuilderString NUMBER_OF_REPLICAS = new XContentBuilderString("number_of_replicas");
-        static final XContentBuilderString ACTIVE_PRIMARY_SHARDS = new XContentBuilderString("active_primary_shards");
-        static final XContentBuilderString ACTIVE_SHARDS = new XContentBuilderString("active_shards");
-        static final XContentBuilderString RELOCATING_SHARDS = new XContentBuilderString("relocating_shards");
-        static final XContentBuilderString INITIALIZING_SHARDS = new XContentBuilderString("initializing_shards");
-        static final XContentBuilderString UNASSIGNED_SHARDS = new XContentBuilderString("unassigned_shards");
-        static final XContentBuilderString VALIDATION_FAILURES = new XContentBuilderString("validation_failures");
-        static final XContentBuilderString SHARDS = new XContentBuilderString("shards");
-        static final XContentBuilderString PRIMARY_ACTIVE = new XContentBuilderString("primary_active");
+        static final String STATUS = "status";
+        static final String NUMBER_OF_SHARDS = "number_of_shards";
+        static final String NUMBER_OF_REPLICAS = "number_of_replicas";
+        static final String ACTIVE_PRIMARY_SHARDS = "active_primary_shards";
+        static final String ACTIVE_SHARDS = "active_shards";
+        static final String RELOCATING_SHARDS = "relocating_shards";
+        static final String INITIALIZING_SHARDS = "initializing_shards";
+        static final String UNASSIGNED_SHARDS = "unassigned_shards";
+        static final String VALIDATION_FAILURES = "validation_failures";
+        static final String SHARDS = "shards";
+        static final String PRIMARY_ACTIVE = "primary_active";
     }
 
     @Override
diff --git a/core/src/main/java/org/elasticsearch/common/unit/Fuzziness.java b/core/src/main/java/org/elasticsearch/common/unit/Fuzziness.java
index 139dfd75494..afe37e221a0 100644
--- a/core/src/main/java/org/elasticsearch/common/unit/Fuzziness.java
+++ b/core/src/main/java/org/elasticsearch/common/unit/Fuzziness.java
@@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.StreamOutput;
 import org.elasticsearch.common.io.stream.Writeable;
 import org.elasticsearch.common.xcontent.ToXContent;
 import org.elasticsearch.common.xcontent.XContentBuilder;
-import org.elasticsearch.common.xcontent.XContentBuilderString;
 import org.elasticsearch.common.xcontent.XContentParser;
 
 import java.io.IOException;
@@ -38,12 +37,12 @@ import java.util.Objects;
  */
 public final class Fuzziness implements ToXContent, Writeable {
 
-    public static final XContentBuilderString X_FIELD_NAME = new XContentBuilderString("fuzziness");
+    public static final String X_FIELD_NAME = "fuzziness";
     public static final Fuzziness ZERO = new Fuzziness(0);
     public static final Fuzziness ONE = new Fuzziness(1);
     public static final Fuzziness TWO = new Fuzziness(2);
     public static final Fuzziness AUTO = new Fuzziness("AUTO");
-    public static final ParseField FIELD = new ParseField(X_FIELD_NAME.value());
+    public static final ParseField FIELD = new ParseField(X_FIELD_NAME);
 
     private final String fuzziness;
 
diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java b/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java
index 83122646df6..4367b15fd52 100644
--- a/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java
+++ b/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java
@@ -19,22 +19,6 @@
 
 package org.elasticsearch.common.xcontent;
 
-import org.apache.lucene.util.BytesRef;
-import org.elasticsearch.common.Strings;
-import org.elasticsearch.common.bytes.BytesArray;
-import org.elasticsearch.common.bytes.BytesReference;
-import org.elasticsearch.common.geo.GeoPoint;
-import org.elasticsearch.common.io.BytesStream;
-import org.elasticsearch.common.io.stream.BytesStreamOutput;
-import org.elasticsearch.common.lease.Releasable;
-import org.elasticsearch.common.text.Text;
-import org.elasticsearch.common.unit.ByteSizeValue;
-import org.elasticsearch.common.unit.TimeValue;
-import org.joda.time.DateTimeZone;
-import org.joda.time.ReadableInstant;
-import org.joda.time.format.DateTimeFormatter;
-import org.joda.time.format.ISODateTimeFormat;
-
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -50,6 +34,21 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.lucene.util.BytesRef;
+import org.elasticsearch.common.bytes.BytesArray;
+import org.elasticsearch.common.bytes.BytesReference;
+import org.elasticsearch.common.geo.GeoPoint;
+import org.elasticsearch.common.io.BytesStream;
+import org.elasticsearch.common.io.stream.BytesStreamOutput;
+import org.elasticsearch.common.lease.Releasable;
+import org.elasticsearch.common.text.Text;
+import org.elasticsearch.common.unit.ByteSizeValue;
+import org.elasticsearch.common.unit.TimeValue;
+import org.joda.time.DateTimeZone;
+import org.joda.time.ReadableInstant;
+import org.joda.time.format.DateTimeFormatter;
+import org.joda.time.format.ISODateTimeFormat;
+
 /**
  * A utility to build XContent (ie json).
  */
@@ -146,12 +145,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder startObject(XContentBuilderString name) throws IOException {
-        field(name);
-        startObject();
-        return this;
-    }
-
     public XContentBuilder startObject() throws IOException {
         generator.writeStartObject();
         return this;
@@ -171,15 +164,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder array(XContentBuilderString name, String... values) throws IOException {
-        startArray(name);
-        for (String value : values) {
-            value(value);
-        }
-        endArray();
-        return this;
-    }
-
     public XContentBuilder array(String name, Object... values) throws IOException {
         startArray(name);
         for (Object value : values) {
@@ -189,27 +173,12 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder array(XContentBuilderString name, Object... values) throws IOException {
-        startArray(name);
-        for (Object value : values) {
-            value(value);
-        }
-        endArray();
-        return this;
-    }
-
     public XContentBuilder startArray(String name) throws IOException {
         field(name);
         startArray();
         return this;
     }
 
-    public XContentBuilder startArray(XContentBuilderString name) throws IOException {
-        field(name);
-        startArray();
-        return this;
-    }
-
     public XContentBuilder startArray() throws IOException {
         generator.writeStartArray();
         return this;
@@ -220,10 +189,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name) throws IOException {
-        return field(name.value());
-    }
-
     public XContentBuilder field(String name) throws IOException {
         if (name == null) {
             throw new IllegalArgumentException("field name cannot be null");
@@ -242,16 +207,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, char[] value, int offset, int length) throws IOException {
-        field(name);
-        if (value == null) {
-            generator.writeNull();
-        } else {
-            generator.writeString(value, offset, length);
-        }
-        return this;
-    }
-
     public XContentBuilder field(String name, String value) throws IOException {
         field(name);
         if (value == null) {
@@ -262,16 +217,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, String value) throws IOException {
-        field(name);
-        if (value == null) {
-            generator.writeNull();
-        } else {
-            generator.writeString(value);
-        }
-        return this;
-    }
-
     public XContentBuilder field(String name, Integer value) throws IOException {
         field(name);
         if (value == null) {
@@ -282,28 +227,12 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, Integer value) throws IOException {
-        field(name);
-        if (value == null) {
-            generator.writeNull();
-        } else {
-            generator.writeNumber(value.intValue());
-        }
-        return this;
-    }
-
     public XContentBuilder field(String name, int value) throws IOException {
         field(name);
         generator.writeNumber(value);
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, int value) throws IOException {
-        field(name);
-        generator.writeNumber(value);
-        return this;
-    }
-
     public XContentBuilder field(String name, Long value) throws IOException {
         field(name);
         if (value == null) {
@@ -314,28 +243,12 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, Long value) throws IOException {
-        field(name);
-        if (value == null) {
-            generator.writeNull();
-        } else {
-            generator.writeNumber(value.longValue());
-        }
-        return this;
-    }
-
     public XContentBuilder field(String name, long value) throws IOException {
         field(name);
         generator.writeNumber(value);
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, long value) throws IOException {
-        field(name);
-        generator.writeNumber(value);
-        return this;
-    }
-
     public XContentBuilder field(String name, Float value) throws IOException {
         field(name);
         if (value == null) {
@@ -346,28 +259,12 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, Float value) throws IOException {
-        field(name);
-        if (value == null) {
-            generator.writeNull();
-        } else {
-            generator.writeNumber(value.floatValue());
-        }
-        return this;
-    }
-
     public XContentBuilder field(String name, float value) throws IOException {
         field(name);
         generator.writeNumber(value);
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, float value) throws IOException {
-        field(name);
-        generator.writeNumber(value);
-        return this;
-    }
-
     public XContentBuilder field(String name, Double value) throws IOException {
         field(name);
         if (value == null) {
@@ -378,36 +275,16 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, Double value) throws IOException {
-        field(name);
-        if (value == null) {
-            generator.writeNull();
-        } else {
-            generator.writeNumber(value);
-        }
-        return this;
-    }
-
     public XContentBuilder field(String name, double value) throws IOException {
         field(name);
         generator.writeNumber(value);
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, double value) throws IOException {
-        field(name);
-        generator.writeNumber(value);
-        return this;
-    }
-
     public XContentBuilder field(String name, BigDecimal value) throws IOException {
         return field(name, value, value.scale(), RoundingMode.HALF_UP, true);
     }
 
-    public XContentBuilder field(XContentBuilderString name, BigDecimal value) throws IOException {
-        return field(name, value, value.scale(), RoundingMode.HALF_UP, true);
-    }
-
     public XContentBuilder field(String name, BigDecimal value, int scale, RoundingMode rounding, boolean toDouble) throws IOException {
         field(name);
         if (value == null) {
@@ -426,24 +303,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, BigDecimal value, int scale, RoundingMode rounding, boolean toDouble) throws IOException {
-        field(name);
-        if (value == null) {
-            generator.writeNull();
-        } else {
-            if (toDouble) {
-                try {
-                    generator.writeNumber(value.setScale(scale, rounding).doubleValue());
-                } catch (ArithmeticException e) {
-                    generator.writeString(value.toEngineeringString());
-                }
-            } else {
-                generator.writeString(value.toEngineeringString());
-            }
-        }
-        return this;
-    }
-
     /**
      * Writes the binary content of the given BytesRef
      * Use {@link org.elasticsearch.common.xcontent.XContentParser#binaryValue()} to read the value back
@@ -454,16 +313,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    /**
-     * Writes the binary content of the given BytesRef
-     * Use {@link org.elasticsearch.common.xcontent.XContentParser#binaryValue()} to read the value back
-     */
-    public XContentBuilder field(XContentBuilderString name, BytesRef value) throws IOException {
-        field(name);
-        generator.writeBinary(value.bytes, value.offset, value.length);
-        return this;
-    }
-
     /**
      * Writes the binary content of the given BytesReference
      * Use {@link org.elasticsearch.common.xcontent.XContentParser#binaryValue()} to read the value back
@@ -477,29 +326,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    /**
-     * Writes the binary content of the given BytesReference
-     * Use {@link org.elasticsearch.common.xcontent.XContentParser#binaryValue()} to read the value back
-     */
-    public XContentBuilder field(XContentBuilderString name, BytesReference value) throws IOException {
-        field(name);
-        if (!value.hasArray()) {
-            value = value.toBytesArray();
-        }
-        generator.writeBinary(value.array(), value.arrayOffset(), value.length());
-        return this;
-    }
-
-    /**
-     * Writes the binary content of the given BytesRef as UTF-8 bytes
-     * Use {@link XContentParser#utf8Bytes()} to read the value back
-     */
-    public XContentBuilder utf8Field(XContentBuilderString name, BytesRef value) throws IOException {
-        field(name);
-        generator.writeUTF8String(value.bytes, value.offset, value.length);
-        return this;
-    }
-
     /**
      * Writes the binary content of the given BytesRef as UTF-8 bytes
      * Use {@link XContentParser#utf8Bytes()} to read the value back
@@ -526,22 +352,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, Text value) throws IOException {
-        field(name);
-        if (value.hasBytes() && value.bytes().hasArray()) {
-            generator.writeUTF8String(value.bytes().array(), value.bytes().arrayOffset(), value.bytes().length());
-            return this;
-        }
-        if (value.hasString()) {
-            generator.writeString(value.string());
-            return this;
-        }
-        // TODO: TextBytesOptimization we can use a buffer here to convert it? maybe add a request to jackson to support InputStream as well?
-        BytesArray bytesArray = value.bytes().toBytesArray();
-        generator.writeUTF8String(bytesArray.array(), bytesArray.arrayOffset(), bytesArray.length());
-        return this;
-    }
-
     public XContentBuilder field(String name, byte[] value, int offset, int length) throws IOException {
         field(name);
         generator.writeBinary(value, offset, length);
@@ -554,12 +364,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, Map value) throws IOException {
-        field(name);
-        value(value);
-        return this;
-    }
-
     public XContentBuilder field(String name, Iterable value) throws IOException {
         if (value instanceof Path) {
             //treat Paths as single value
@@ -575,21 +379,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, Iterable value) throws IOException {
-        if (value instanceof Path) {
-            //treat Paths as single value
-            field(name);
-            value(value);
-        } else {
-            startArray(name);
-            for (Object o : value) {
-                value(o);
-            }
-            endArray();
-        }
-        return this;
-    }
-
     public XContentBuilder field(String name, boolean... value) throws IOException {
         startArray(name);
         for (boolean o : value) {
@@ -599,16 +388,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-
-    public XContentBuilder field(XContentBuilderString name, boolean... value) throws IOException {
-        startArray(name);
-        for (boolean o : value) {
-            value(o);
-        }
-        endArray();
-        return this;
-    }
-
     public XContentBuilder field(String name, String... value) throws IOException {
         startArray(name);
         for (String o : value) {
@@ -618,16 +397,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-
-    public XContentBuilder field(XContentBuilderString name, String... value) throws IOException {
-        startArray(name);
-        for (String o : value) {
-            value(o);
-        }
-        endArray();
-        return this;
-    }
-
     public XContentBuilder field(String name, Object... value) throws IOException {
         startArray(name);
         for (Object o : value) {
@@ -637,15 +406,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, Object... value) throws IOException {
-        startArray(name);
-        for (Object o : value) {
-            value(o);
-        }
-        endArray();
-        return this;
-    }
-
     public XContentBuilder field(String name, int... value) throws IOException {
         startArray(name);
         for (Object o : value) {
@@ -655,25 +415,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, int offset, int length, int... value) throws IOException {
-        assert ((offset >= 0) && (value.length > length));
-        startArray(name);
-        for (int i = offset; i < length; i++) {
-            value(value[i]);
-        }
-        endArray();
-        return this;
-    }
-
-    public XContentBuilder field(XContentBuilderString name, int... value) throws IOException {
-        startArray(name);
-        for (Object o : value) {
-            value(o);
-        }
-        endArray();
-        return this;
-    }
-
     public XContentBuilder field(String name, long... value) throws IOException {
         startArray(name);
         for (Object o : value) {
@@ -683,15 +424,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, long... value) throws IOException {
-        startArray(name);
-        for (Object o : value) {
-            value(o);
-        }
-        endArray();
-        return this;
-    }
-
     public XContentBuilder field(String name, float... value) throws IOException {
         startArray(name);
         for (Object o : value) {
@@ -701,15 +433,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, float... value) throws IOException {
-        startArray(name);
-        for (Object o : value) {
-            value(o);
-        }
-        endArray();
-        return this;
-    }
-
     public XContentBuilder field(String name, double... value) throws IOException {
         startArray(name);
         for (Object o : value) {
@@ -719,27 +442,12 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, double... value) throws IOException {
-        startArray(name);
-        for (Object o : value) {
-            value(o);
-        }
-        endArray();
-        return this;
-    }
-
     public XContentBuilder field(String name, Object value) throws IOException {
         field(name);
         writeValue(value);
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, Object value) throws IOException {
-        field(name);
-        writeValue(value);
-        return this;
-    }
-
     public XContentBuilder value(Object value) throws IOException {
         writeValue(value);
         return this;
@@ -751,12 +459,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, boolean value) throws IOException {
-        field(name);
-        generator.writeBoolean(value);
-        return this;
-    }
-
     public XContentBuilder field(String name, byte[] value) throws IOException {
         field(name);
         if (value == null) {
@@ -767,62 +469,31 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder field(XContentBuilderString name, byte[] value) throws IOException {
-        field(name);
-        return value(value);
-    }
-
     public XContentBuilder field(String name, ReadableInstant date) throws IOException {
         field(name);
         return value(date);
     }
 
-    public XContentBuilder field(XContentBuilderString name, ReadableInstant date) throws IOException {
-        field(name);
-        return value(date);
-    }
-
     public XContentBuilder field(String name, ReadableInstant date, DateTimeFormatter formatter) throws IOException {
         field(name);
         return value(date, formatter);
     }
 
-    public XContentBuilder field(XContentBuilderString name, ReadableInstant date, DateTimeFormatter formatter) throws IOException {
-        field(name);
-        return value(date, formatter);
-    }
-
     public XContentBuilder field(String name, Date date) throws IOException {
         field(name);
         return value(date);
     }
 
-    public XContentBuilder field(XContentBuilderString name, Date date) throws IOException {
-        field(name);
-        return value(date);
-    }
-
     public XContentBuilder field(String name, Date date, DateTimeFormatter formatter) throws IOException {
         field(name);
         return value(date, formatter);
     }
 
-    public XContentBuilder field(XContentBuilderString name, Date date, DateTimeFormatter formatter) throws IOException {
-        field(name);
-        return value(date, formatter);
-    }
-
     public XContentBuilder nullField(String name) throws IOException {
         generator.writeNullField(name);
         return this;
     }
 
-    public XContentBuilder nullField(XContentBuilderString name) throws IOException {
-        field(name);
-        generator.writeNull();
-        return this;
-    }
-
     public XContentBuilder nullValue() throws IOException {
         generator.writeNull();
         return this;
@@ -843,7 +514,7 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder timeValueField(XContentBuilderString rawFieldName, XContentBuilderString readableFieldName, TimeValue timeValue) throws IOException {
+    public XContentBuilder timeValueField(String rawFieldName, String readableFieldName, TimeValue timeValue) throws IOException {
         if (humanReadable) {
             field(readableFieldName, timeValue.toString());
         }
@@ -851,7 +522,7 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder timeValueField(XContentBuilderString rawFieldName, XContentBuilderString readableFieldName, long rawTime) throws IOException {
+    public XContentBuilder timeValueField(String rawFieldName, String readableFieldName, long rawTime) throws IOException {
         if (humanReadable) {
             field(readableFieldName, new TimeValue(rawTime).toString());
         }
@@ -859,18 +530,6 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder dateValueField(XContentBuilderString rawFieldName, XContentBuilderString readableFieldName, long rawTimestamp) throws IOException {
-        if (humanReadable) {
-            field(readableFieldName, defaultDatePrinter.print(rawTimestamp));
-        }
-        field(rawFieldName, rawTimestamp);
-        return this;
-    }
-
-    public XContentBuilder timeValueField(String rawFieldName, String readableFieldName, TimeValue timeValue) throws IOException {
-        return timeValueField(rawFieldName, readableFieldName, timeValue.millis(), TimeUnit.MILLISECONDS);
-    }
-
     public XContentBuilder timeValueField(String rawFieldName, String readableFieldName, long rawTime, TimeUnit timeUnit) throws
         IOException {
         if (humanReadable) {
@@ -888,7 +547,7 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder byteSizeField(XContentBuilderString rawFieldName, XContentBuilderString readableFieldName, ByteSizeValue byteSizeValue) throws IOException {
+    public XContentBuilder byteSizeField(String rawFieldName, String readableFieldName, ByteSizeValue byteSizeValue) throws IOException {
         if (humanReadable) {
             field(readableFieldName, byteSizeValue.toString());
         }
@@ -896,7 +555,7 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder byteSizeField(XContentBuilderString rawFieldName, XContentBuilderString readableFieldName, long rawSize) throws IOException {
+    public XContentBuilder byteSizeField(String rawFieldName, String readableFieldName, long rawSize) throws IOException {
         if (humanReadable) {
             field(readableFieldName, new ByteSizeValue(rawSize).toString());
         }
@@ -904,7 +563,7 @@ public final class XContentBuilder implements BytesStream, Releasable {
         return this;
     }
 
-    public XContentBuilder percentageField(XContentBuilderString rawFieldName, XContentBuilderString readableFieldName, double percentage) throws IOException {
+    public XContentBuilder percentageField(String rawFieldName, String readableFieldName, double percentage) throws IOException {
         if (humanReadable) {
             field(readableFieldName, String.format(Locale.ROOT, "%1.1f%%", percentage));
         }
diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilderString.java b/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilderString.java
deleted file mode 100644
index b056131f585..00000000000
--- a/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilderString.java
+++ /dev/null
@@ -1,36 +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.common.xcontent;
-
-/**
- * TODO: remove this, it is just a wrapper that is no longer needed
- */
-public class XContentBuilderString {
-
-    private final String value;
-
-    public XContentBuilderString(String value) {
-        this.value = value;
-    }
-
-    public String value() {
-        return value;
-    }
-}
diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/XContentGenerator.java b/core/src/main/java/org/elasticsearch/common/xcontent/XContentGenerator.java
index e11fc42b5a8..f23ae441989 100644
--- a/core/src/main/java/org/elasticsearch/common/xcontent/XContentGenerator.java
+++ b/core/src/main/java/org/elasticsearch/common/xcontent/XContentGenerator.java
@@ -46,8 +46,6 @@ public interface XContentGenerator extends Closeable {
 
     void writeFieldName(String name) throws IOException;
 
-    void writeFieldName(XContentString name) throws IOException;
-
     void writeString(String text) throws IOException;
 
     void writeString(char[] text, int offset, int len) throws IOException;
@@ -70,47 +68,26 @@ public interface XContentGenerator extends Closeable {
 
     void writeNull() throws IOException;
 
-
     void writeStringField(String fieldName, String value) throws IOException;
 
-    void writeStringField(XContentString fieldName, String value) throws IOException;
-
     void writeBooleanField(String fieldName, boolean value) throws IOException;
 
-    void writeBooleanField(XContentString fieldName, boolean value) throws IOException;
-
     void writeNullField(String fieldName) throws IOException;
 
-    void writeNullField(XContentString fieldName) throws IOException;
-
     void writeNumberField(String fieldName, int value) throws IOException;
 
-    void writeNumberField(XContentString fieldName, int value) throws IOException;
-
     void writeNumberField(String fieldName, long value) throws IOException;
 
-    void writeNumberField(XContentString fieldName, long value) throws IOException;
-
     void writeNumberField(String fieldName, double value) throws IOException;
 
-    void writeNumberField(XContentString fieldName, double value) throws IOException;
-
     void writeNumberField(String fieldName, float value) throws IOException;
 
-    void writeNumberField(XContentString fieldName, float value) throws IOException;
-
     void writeBinaryField(String fieldName, byte[] data) throws IOException;
 
-    void writeBinaryField(XContentString fieldName, byte[] data) throws IOException;
-
     void writeArrayFieldStart(String fieldName) throws IOException;
 
-    void writeArrayFieldStart(XContentString fieldName) throws IOException;
-
     void writeObjectFieldStart(String fieldName) throws IOException;
 
-    void writeObjectFieldStart(XContentString fieldName) throws IOException;
-
     void writeRawField(String fieldName, InputStream content) throws IOException;
 
     void writeRawField(String fieldName, BytesReference content) throws IOException;
diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java b/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java
index 54de31c3150..f8513828636 100644
--- a/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java
+++ b/core/src/main/java/org/elasticsearch/common/xcontent/XContentParser.java
@@ -218,10 +218,10 @@ public interface XContentParser extends Releasable {
      *     
  • {@link XContentBuilder#field(String, byte[])}}
  • * * - * as well as via their XContentBuilderString variants of the separated value methods. + * as well as via their String variants of the separated value methods. * Note: Do not use this method to read values written with: *
      - *
    • {@link XContentBuilder#utf8Field(XContentBuilderString, org.apache.lucene.util.BytesRef)}
    • + *
    • {@link XContentBuilder#utf8Field(String, org.apache.lucene.util.BytesRef)}
    • *
    • {@link XContentBuilder#utf8Field(String, org.apache.lucene.util.BytesRef)}
    • *
    * diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/XContentString.java b/core/src/main/java/org/elasticsearch/common/xcontent/XContentString.java deleted file mode 100644 index 512703887af..00000000000 --- a/core/src/main/java/org/elasticsearch/common/xcontent/XContentString.java +++ /dev/null @@ -1,32 +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.common.xcontent; - -import com.fasterxml.jackson.core.io.SerializedString; - -/** - * - */ -public class XContentString extends SerializedString { - - public XContentString(String v) { - super(v); - } -} diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentGenerator.java b/core/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentGenerator.java index 96cfd63f753..4148148e507 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentGenerator.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContentGenerator.java @@ -34,7 +34,6 @@ import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentGenerator; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentString; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.support.filtering.FilterPathBasedFilter; @@ -157,11 +156,6 @@ public class JsonXContentGenerator implements XContentGenerator { generator.writeFieldName(name); } - @Override - public void writeFieldName(XContentString name) throws IOException { - generator.writeFieldName(name); - } - @Override public void writeString(String text) throws IOException { generator.writeString(text); @@ -222,111 +216,51 @@ public class JsonXContentGenerator implements XContentGenerator { generator.writeStringField(fieldName, value); } - @Override - public void writeStringField(XContentString fieldName, String value) throws IOException { - generator.writeFieldName(fieldName); - generator.writeString(value); - } - @Override public void writeBooleanField(String fieldName, boolean value) throws IOException { generator.writeBooleanField(fieldName, value); } - @Override - public void writeBooleanField(XContentString fieldName, boolean value) throws IOException { - generator.writeFieldName(fieldName); - generator.writeBoolean(value); - } - @Override public void writeNullField(String fieldName) throws IOException { generator.writeNullField(fieldName); } - @Override - public void writeNullField(XContentString fieldName) throws IOException { - generator.writeFieldName(fieldName); - generator.writeNull(); - } - @Override public void writeNumberField(String fieldName, int value) throws IOException { generator.writeNumberField(fieldName, value); } - @Override - public void writeNumberField(XContentString fieldName, int value) throws IOException { - generator.writeFieldName(fieldName); - generator.writeNumber(value); - } - @Override public void writeNumberField(String fieldName, long value) throws IOException { generator.writeNumberField(fieldName, value); } - @Override - public void writeNumberField(XContentString fieldName, long value) throws IOException { - generator.writeFieldName(fieldName); - generator.writeNumber(value); - } - @Override public void writeNumberField(String fieldName, double value) throws IOException { generator.writeNumberField(fieldName, value); } - @Override - public void writeNumberField(XContentString fieldName, double value) throws IOException { - generator.writeFieldName(fieldName); - generator.writeNumber(value); - } - @Override public void writeNumberField(String fieldName, float value) throws IOException { generator.writeNumberField(fieldName, value); } - @Override - public void writeNumberField(XContentString fieldName, float value) throws IOException { - generator.writeFieldName(fieldName); - generator.writeNumber(value); - } - @Override public void writeBinaryField(String fieldName, byte[] data) throws IOException { generator.writeBinaryField(fieldName, data); } - @Override - public void writeBinaryField(XContentString fieldName, byte[] value) throws IOException { - generator.writeFieldName(fieldName); - generator.writeBinary(value); - } - @Override public void writeArrayFieldStart(String fieldName) throws IOException { generator.writeArrayFieldStart(fieldName); } - @Override - public void writeArrayFieldStart(XContentString fieldName) throws IOException { - generator.writeFieldName(fieldName); - generator.writeStartArray(); - } - @Override public void writeObjectFieldStart(String fieldName) throws IOException { generator.writeObjectFieldStart(fieldName); } - @Override - public void writeObjectFieldStart(XContentString fieldName) throws IOException { - generator.writeFieldName(fieldName); - generator.writeStartObject(); - } - private void writeStartRaw(String fieldName) throws IOException { writeFieldName(fieldName); generator.writeRaw(':'); diff --git a/core/src/main/java/org/elasticsearch/discovery/DiscoveryStats.java b/core/src/main/java/org/elasticsearch/discovery/DiscoveryStats.java index dcd75b07651..74c6c3b7f35 100644 --- a/core/src/main/java/org/elasticsearch/discovery/DiscoveryStats.java +++ b/core/src/main/java/org/elasticsearch/discovery/DiscoveryStats.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.discovery.zen.publish.PendingClusterStateStats; import java.io.IOException; @@ -69,7 +68,7 @@ public class DiscoveryStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString DISCOVERY = new XContentBuilderString("discovery"); + static final String DISCOVERY = "discovery"; } public PendingClusterStateStats getQueueStats() { diff --git a/core/src/main/java/org/elasticsearch/discovery/zen/publish/PendingClusterStateStats.java b/core/src/main/java/org/elasticsearch/discovery/zen/publish/PendingClusterStateStats.java index 44265b0e481..3c4a2b84c50 100644 --- a/core/src/main/java/org/elasticsearch/discovery/zen/publish/PendingClusterStateStats.java +++ b/core/src/main/java/org/elasticsearch/discovery/zen/publish/PendingClusterStateStats.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -84,10 +83,10 @@ public class PendingClusterStateStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString QUEUE = new XContentBuilderString("cluster_state_queue"); - static final XContentBuilderString TOTAL = new XContentBuilderString("total"); - static final XContentBuilderString PENDING = new XContentBuilderString("pending"); - static final XContentBuilderString COMMITTED = new XContentBuilderString("committed"); + static final String QUEUE = "cluster_state_queue"; + static final String TOTAL = "total"; + static final String PENDING = "pending"; + static final String COMMITTED = "committed"; } @Override diff --git a/core/src/main/java/org/elasticsearch/http/HttpInfo.java b/core/src/main/java/org/elasticsearch/http/HttpInfo.java index df51de96d3b..0f285974e8a 100644 --- a/core/src/main/java/org/elasticsearch/http/HttpInfo.java +++ b/core/src/main/java/org/elasticsearch/http/HttpInfo.java @@ -26,7 +26,6 @@ import org.elasticsearch.common.transport.BoundTransportAddress; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -47,11 +46,11 @@ public class HttpInfo implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString HTTP = new XContentBuilderString("http"); - static final XContentBuilderString BOUND_ADDRESS = new XContentBuilderString("bound_address"); - static final XContentBuilderString PUBLISH_ADDRESS = new XContentBuilderString("publish_address"); - static final XContentBuilderString MAX_CONTENT_LENGTH = new XContentBuilderString("max_content_length"); - static final XContentBuilderString MAX_CONTENT_LENGTH_IN_BYTES = new XContentBuilderString("max_content_length_in_bytes"); + static final String HTTP = "http"; + static final String BOUND_ADDRESS = "bound_address"; + static final String PUBLISH_ADDRESS = "publish_address"; + static final String MAX_CONTENT_LENGTH = "max_content_length"; + static final String MAX_CONTENT_LENGTH_IN_BYTES = "max_content_length_in_bytes"; } @Override diff --git a/core/src/main/java/org/elasticsearch/http/HttpStats.java b/core/src/main/java/org/elasticsearch/http/HttpStats.java index 7cbe8a7ea55..973821f4a5e 100644 --- a/core/src/main/java/org/elasticsearch/http/HttpStats.java +++ b/core/src/main/java/org/elasticsearch/http/HttpStats.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -69,9 +68,9 @@ public class HttpStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString HTTP = new XContentBuilderString("http"); - static final XContentBuilderString CURRENT_OPEN = new XContentBuilderString("current_open"); - static final XContentBuilderString TOTAL_OPENED = new XContentBuilderString("total_opened"); + static final String HTTP = "http"; + static final String CURRENT_OPEN = "current_open"; + static final String TOTAL_OPENED = "total_opened"; } @Override @@ -82,4 +81,4 @@ public class HttpStats implements Streamable, ToXContent { builder.endObject(); return builder; } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/elasticsearch/index/cache/query/QueryCacheStats.java b/core/src/main/java/org/elasticsearch/index/cache/query/QueryCacheStats.java index 62b8d3ba138..fcbb6190048 100644 --- a/core/src/main/java/org/elasticsearch/index/cache/query/QueryCacheStats.java +++ b/core/src/main/java/org/elasticsearch/index/cache/query/QueryCacheStats.java @@ -26,7 +26,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -149,15 +148,15 @@ public class QueryCacheStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString QUERY_CACHE = new XContentBuilderString("query_cache"); - static final XContentBuilderString MEMORY_SIZE = new XContentBuilderString("memory_size"); - static final XContentBuilderString MEMORY_SIZE_IN_BYTES = new XContentBuilderString("memory_size_in_bytes"); - static final XContentBuilderString TOTAL_COUNT = new XContentBuilderString("total_count"); - static final XContentBuilderString HIT_COUNT = new XContentBuilderString("hit_count"); - static final XContentBuilderString MISS_COUNT = new XContentBuilderString("miss_count"); - static final XContentBuilderString CACHE_SIZE = new XContentBuilderString("cache_size"); - static final XContentBuilderString CACHE_COUNT = new XContentBuilderString("cache_count"); - static final XContentBuilderString EVICTIONS = new XContentBuilderString("evictions"); + static final String QUERY_CACHE = "query_cache"; + static final String MEMORY_SIZE = "memory_size"; + static final String MEMORY_SIZE_IN_BYTES = "memory_size_in_bytes"; + static final String TOTAL_COUNT = "total_count"; + static final String HIT_COUNT = "hit_count"; + static final String MISS_COUNT = "miss_count"; + static final String CACHE_SIZE = "cache_size"; + static final String CACHE_COUNT = "cache_count"; + static final String EVICTIONS = "evictions"; } } diff --git a/core/src/main/java/org/elasticsearch/index/cache/request/RequestCacheStats.java b/core/src/main/java/org/elasticsearch/index/cache/request/RequestCacheStats.java index 9186fadbcee..5eb9775b816 100644 --- a/core/src/main/java/org/elasticsearch/index/cache/request/RequestCacheStats.java +++ b/core/src/main/java/org/elasticsearch/index/cache/request/RequestCacheStats.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -103,11 +102,11 @@ public class RequestCacheStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString REQUEST_CACHE_STATS = new XContentBuilderString("request_cache"); - static final XContentBuilderString MEMORY_SIZE = new XContentBuilderString("memory_size"); - static final XContentBuilderString MEMORY_SIZE_IN_BYTES = new XContentBuilderString("memory_size_in_bytes"); - static final XContentBuilderString EVICTIONS = new XContentBuilderString("evictions"); - static final XContentBuilderString HIT_COUNT = new XContentBuilderString("hit_count"); - static final XContentBuilderString MISS_COUNT = new XContentBuilderString("miss_count"); + static final String REQUEST_CACHE_STATS = "request_cache"; + static final String MEMORY_SIZE = "memory_size"; + static final String MEMORY_SIZE_IN_BYTES = "memory_size_in_bytes"; + static final String EVICTIONS = "evictions"; + static final String HIT_COUNT = "hit_count"; + static final String MISS_COUNT = "miss_count"; } } diff --git a/core/src/main/java/org/elasticsearch/index/engine/CommitStats.java b/core/src/main/java/org/elasticsearch/index/engine/CommitStats.java index 050c23701f8..3656dcbfb96 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/CommitStats.java +++ b/core/src/main/java/org/elasticsearch/index/engine/CommitStats.java @@ -27,7 +27,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; import java.util.Map; @@ -111,11 +110,11 @@ public final class CommitStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString GENERATION = new XContentBuilderString("generation"); - static final XContentBuilderString USER_DATA = new XContentBuilderString("user_data"); - static final XContentBuilderString ID = new XContentBuilderString("id"); - static final XContentBuilderString COMMIT = new XContentBuilderString("commit"); - static final XContentBuilderString NUM_DOCS = new XContentBuilderString("num_docs"); + static final String GENERATION = "generation"; + static final String USER_DATA = "user_data"; + static final String ID = "id"; + static final String COMMIT = "commit"; + static final String NUM_DOCS = "num_docs"; } diff --git a/core/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java b/core/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java index b4b80e32680..dcd97dfef0e 100644 --- a/core/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java +++ b/core/src/main/java/org/elasticsearch/index/engine/SegmentsStats.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; import java.util.Iterator; @@ -325,34 +324,34 @@ public class SegmentsStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString SEGMENTS = new XContentBuilderString("segments"); - static final XContentBuilderString COUNT = new XContentBuilderString("count"); - static final XContentBuilderString MEMORY = new XContentBuilderString("memory"); - static final XContentBuilderString MEMORY_IN_BYTES = new XContentBuilderString("memory_in_bytes"); - static final XContentBuilderString TERMS_MEMORY = new XContentBuilderString("terms_memory"); - static final XContentBuilderString TERMS_MEMORY_IN_BYTES = new XContentBuilderString("terms_memory_in_bytes"); - static final XContentBuilderString STORED_FIELDS_MEMORY = new XContentBuilderString("stored_fields_memory"); - static final XContentBuilderString STORED_FIELDS_MEMORY_IN_BYTES = new XContentBuilderString("stored_fields_memory_in_bytes"); - static final XContentBuilderString TERM_VECTORS_MEMORY = new XContentBuilderString("term_vectors_memory"); - static final XContentBuilderString TERM_VECTORS_MEMORY_IN_BYTES = new XContentBuilderString("term_vectors_memory_in_bytes"); - static final XContentBuilderString NORMS_MEMORY = new XContentBuilderString("norms_memory"); - static final XContentBuilderString NORMS_MEMORY_IN_BYTES = new XContentBuilderString("norms_memory_in_bytes"); - static final XContentBuilderString POINTS_MEMORY = new XContentBuilderString("points_memory"); - static final XContentBuilderString POINTS_MEMORY_IN_BYTES = new XContentBuilderString("points_memory_in_bytes"); - static final XContentBuilderString DOC_VALUES_MEMORY = new XContentBuilderString("doc_values_memory"); - static final XContentBuilderString DOC_VALUES_MEMORY_IN_BYTES = new XContentBuilderString("doc_values_memory_in_bytes"); - static final XContentBuilderString INDEX_WRITER_MEMORY = new XContentBuilderString("index_writer_memory"); - static final XContentBuilderString INDEX_WRITER_MEMORY_IN_BYTES = new XContentBuilderString("index_writer_memory_in_bytes"); - static final XContentBuilderString INDEX_WRITER_MAX_MEMORY = new XContentBuilderString("index_writer_max_memory"); - static final XContentBuilderString INDEX_WRITER_MAX_MEMORY_IN_BYTES = new XContentBuilderString("index_writer_max_memory_in_bytes"); - static final XContentBuilderString VERSION_MAP_MEMORY = new XContentBuilderString("version_map_memory"); - static final XContentBuilderString VERSION_MAP_MEMORY_IN_BYTES = new XContentBuilderString("version_map_memory_in_bytes"); - static final XContentBuilderString FIXED_BIT_SET = new XContentBuilderString("fixed_bit_set"); - static final XContentBuilderString FIXED_BIT_SET_MEMORY_IN_BYTES = new XContentBuilderString("fixed_bit_set_memory_in_bytes"); - static final XContentBuilderString FILE_SIZES = new XContentBuilderString("file_sizes"); - static final XContentBuilderString SIZE = new XContentBuilderString("size"); - static final XContentBuilderString SIZE_IN_BYTES = new XContentBuilderString("size_in_bytes"); - static final XContentBuilderString DESCRIPTION = new XContentBuilderString("description"); + static final String SEGMENTS = "segments"; + static final String COUNT = "count"; + static final String MEMORY = "memory"; + static final String MEMORY_IN_BYTES = "memory_in_bytes"; + static final String TERMS_MEMORY = "terms_memory"; + static final String TERMS_MEMORY_IN_BYTES = "terms_memory_in_bytes"; + static final String STORED_FIELDS_MEMORY = "stored_fields_memory"; + static final String STORED_FIELDS_MEMORY_IN_BYTES = "stored_fields_memory_in_bytes"; + static final String TERM_VECTORS_MEMORY = "term_vectors_memory"; + static final String TERM_VECTORS_MEMORY_IN_BYTES = "term_vectors_memory_in_bytes"; + static final String NORMS_MEMORY = "norms_memory"; + static final String NORMS_MEMORY_IN_BYTES = "norms_memory_in_bytes"; + static final String POINTS_MEMORY = "points_memory"; + static final String POINTS_MEMORY_IN_BYTES = "points_memory_in_bytes"; + static final String DOC_VALUES_MEMORY = "doc_values_memory"; + static final String DOC_VALUES_MEMORY_IN_BYTES = "doc_values_memory_in_bytes"; + static final String INDEX_WRITER_MEMORY = "index_writer_memory"; + static final String INDEX_WRITER_MEMORY_IN_BYTES = "index_writer_memory_in_bytes"; + static final String INDEX_WRITER_MAX_MEMORY = "index_writer_max_memory"; + static final String INDEX_WRITER_MAX_MEMORY_IN_BYTES = "index_writer_max_memory_in_bytes"; + static final String VERSION_MAP_MEMORY = "version_map_memory"; + static final String VERSION_MAP_MEMORY_IN_BYTES = "version_map_memory_in_bytes"; + static final String FIXED_BIT_SET = "fixed_bit_set"; + static final String FIXED_BIT_SET_MEMORY_IN_BYTES = "fixed_bit_set_memory_in_bytes"; + static final String FILE_SIZES = "file_sizes"; + static final String SIZE = "size"; + static final String SIZE_IN_BYTES = "size_in_bytes"; + static final String DESCRIPTION = "description"; } @Override diff --git a/core/src/main/java/org/elasticsearch/index/fielddata/FieldDataStats.java b/core/src/main/java/org/elasticsearch/index/fielddata/FieldDataStats.java index 3f3f1b550c3..d8548f72476 100644 --- a/core/src/main/java/org/elasticsearch/index/fielddata/FieldDataStats.java +++ b/core/src/main/java/org/elasticsearch/index/fielddata/FieldDataStats.java @@ -27,7 +27,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -150,10 +149,10 @@ public class FieldDataStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString FIELDDATA = new XContentBuilderString("fielddata"); - static final XContentBuilderString MEMORY_SIZE = new XContentBuilderString("memory_size"); - static final XContentBuilderString MEMORY_SIZE_IN_BYTES = new XContentBuilderString("memory_size_in_bytes"); - static final XContentBuilderString EVICTIONS = new XContentBuilderString("evictions"); - static final XContentBuilderString FIELDS = new XContentBuilderString("fields"); + static final String FIELDDATA = "fielddata"; + static final String MEMORY_SIZE = "memory_size"; + static final String MEMORY_SIZE_IN_BYTES = "memory_size_in_bytes"; + static final String EVICTIONS = "evictions"; + static final String FIELDS = "fields"; } } diff --git a/core/src/main/java/org/elasticsearch/index/flush/FlushStats.java b/core/src/main/java/org/elasticsearch/index/flush/FlushStats.java index a1d18c13506..600651ad306 100644 --- a/core/src/main/java/org/elasticsearch/index/flush/FlushStats.java +++ b/core/src/main/java/org/elasticsearch/index/flush/FlushStats.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -98,10 +97,10 @@ public class FlushStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString FLUSH = new XContentBuilderString("flush"); - static final XContentBuilderString TOTAL = new XContentBuilderString("total"); - static final XContentBuilderString TOTAL_TIME = new XContentBuilderString("total_time"); - static final XContentBuilderString TOTAL_TIME_IN_MILLIS = new XContentBuilderString("total_time_in_millis"); + static final String FLUSH = "flush"; + static final String TOTAL = "total"; + static final String TOTAL_TIME = "total_time"; + static final String TOTAL_TIME_IN_MILLIS = "total_time_in_millis"; } @Override @@ -115,4 +114,4 @@ public class FlushStats implements Streamable, ToXContent { out.writeVLong(total); out.writeVLong(totalTimeInMillis); } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/elasticsearch/index/get/GetResult.java b/core/src/main/java/org/elasticsearch/index/get/GetResult.java index d2436949503..428db08dbcb 100644 --- a/core/src/main/java/org/elasticsearch/index/get/GetResult.java +++ b/core/src/main/java/org/elasticsearch/index/get/GetResult.java @@ -27,7 +27,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.search.lookup.SourceLookup; @@ -199,12 +198,12 @@ public class GetResult implements Streamable, Iterable, ToXContent { } static final class Fields { - static final XContentBuilderString _INDEX = new XContentBuilderString("_index"); - static final XContentBuilderString _TYPE = new XContentBuilderString("_type"); - static final XContentBuilderString _ID = new XContentBuilderString("_id"); - static final XContentBuilderString _VERSION = new XContentBuilderString("_version"); - static final XContentBuilderString FOUND = new XContentBuilderString("found"); - static final XContentBuilderString FIELDS = new XContentBuilderString("fields"); + static final String _INDEX = "_index"; + static final String _TYPE = "_type"; + static final String _ID = "_id"; + static final String _VERSION = "_version"; + static final String FOUND = "found"; + static final String FIELDS = "fields"; } public XContentBuilder toXContentEmbedded(XContentBuilder builder, Params params) throws IOException { diff --git a/core/src/main/java/org/elasticsearch/index/get/GetStats.java b/core/src/main/java/org/elasticsearch/index/get/GetStats.java index 876c9ac565a..10b4f64c19e 100644 --- a/core/src/main/java/org/elasticsearch/index/get/GetStats.java +++ b/core/src/main/java/org/elasticsearch/index/get/GetStats.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -124,17 +123,17 @@ public class GetStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString GET = new XContentBuilderString("get"); - static final XContentBuilderString TOTAL = new XContentBuilderString("total"); - static final XContentBuilderString TIME = new XContentBuilderString("getTime"); - static final XContentBuilderString TIME_IN_MILLIS = new XContentBuilderString("time_in_millis"); - static final XContentBuilderString EXISTS_TOTAL = new XContentBuilderString("exists_total"); - static final XContentBuilderString EXISTS_TIME = new XContentBuilderString("exists_time"); - static final XContentBuilderString EXISTS_TIME_IN_MILLIS = new XContentBuilderString("exists_time_in_millis"); - static final XContentBuilderString MISSING_TOTAL = new XContentBuilderString("missing_total"); - static final XContentBuilderString MISSING_TIME = new XContentBuilderString("missing_time"); - static final XContentBuilderString MISSING_TIME_IN_MILLIS = new XContentBuilderString("missing_time_in_millis"); - static final XContentBuilderString CURRENT = new XContentBuilderString("current"); + static final String GET = "get"; + static final String TOTAL = "total"; + static final String TIME = "getTime"; + static final String TIME_IN_MILLIS = "time_in_millis"; + static final String EXISTS_TOTAL = "exists_total"; + static final String EXISTS_TIME = "exists_time"; + static final String EXISTS_TIME_IN_MILLIS = "exists_time_in_millis"; + static final String MISSING_TOTAL = "missing_total"; + static final String MISSING_TIME = "missing_time"; + static final String MISSING_TIME_IN_MILLIS = "missing_time_in_millis"; + static final String CURRENT = "current"; } public static GetStats readGetStats(StreamInput in) throws IOException { diff --git a/core/src/main/java/org/elasticsearch/index/merge/MergeStats.java b/core/src/main/java/org/elasticsearch/index/merge/MergeStats.java index a6f1d1c3291..ee8c08f00d0 100644 --- a/core/src/main/java/org/elasticsearch/index/merge/MergeStats.java +++ b/core/src/main/java/org/elasticsearch/index/merge/MergeStats.java @@ -26,7 +26,6 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -210,23 +209,23 @@ public class MergeStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString MERGES = new XContentBuilderString("merges"); - static final XContentBuilderString CURRENT = new XContentBuilderString("current"); - static final XContentBuilderString CURRENT_DOCS = new XContentBuilderString("current_docs"); - static final XContentBuilderString CURRENT_SIZE = new XContentBuilderString("current_size"); - static final XContentBuilderString CURRENT_SIZE_IN_BYTES = new XContentBuilderString("current_size_in_bytes"); - static final XContentBuilderString TOTAL = new XContentBuilderString("total"); - static final XContentBuilderString TOTAL_TIME = new XContentBuilderString("total_time"); - static final XContentBuilderString TOTAL_TIME_IN_MILLIS = new XContentBuilderString("total_time_in_millis"); - static final XContentBuilderString TOTAL_STOPPED_TIME = new XContentBuilderString("total_stopped_time"); - static final XContentBuilderString TOTAL_STOPPED_TIME_IN_MILLIS = new XContentBuilderString("total_stopped_time_in_millis"); - static final XContentBuilderString TOTAL_THROTTLED_TIME = new XContentBuilderString("total_throttled_time"); - static final XContentBuilderString TOTAL_THROTTLED_TIME_IN_MILLIS = new XContentBuilderString("total_throttled_time_in_millis"); - static final XContentBuilderString TOTAL_DOCS = new XContentBuilderString("total_docs"); - static final XContentBuilderString TOTAL_SIZE = new XContentBuilderString("total_size"); - static final XContentBuilderString TOTAL_SIZE_IN_BYTES = new XContentBuilderString("total_size_in_bytes"); - static final XContentBuilderString TOTAL_THROTTLE_BYTES_PER_SEC_IN_BYTES = new XContentBuilderString("total_auto_throttle_in_bytes"); - static final XContentBuilderString TOTAL_THROTTLE_BYTES_PER_SEC = new XContentBuilderString("total_auto_throttle"); + static final String MERGES = "merges"; + static final String CURRENT = "current"; + static final String CURRENT_DOCS = "current_docs"; + static final String CURRENT_SIZE = "current_size"; + static final String CURRENT_SIZE_IN_BYTES = "current_size_in_bytes"; + static final String TOTAL = "total"; + static final String TOTAL_TIME = "total_time"; + static final String TOTAL_TIME_IN_MILLIS = "total_time_in_millis"; + static final String TOTAL_STOPPED_TIME = "total_stopped_time"; + static final String TOTAL_STOPPED_TIME_IN_MILLIS = "total_stopped_time_in_millis"; + static final String TOTAL_THROTTLED_TIME = "total_throttled_time"; + static final String TOTAL_THROTTLED_TIME_IN_MILLIS = "total_throttled_time_in_millis"; + static final String TOTAL_DOCS = "total_docs"; + static final String TOTAL_SIZE = "total_size"; + static final String TOTAL_SIZE_IN_BYTES = "total_size_in_bytes"; + static final String TOTAL_THROTTLE_BYTES_PER_SEC_IN_BYTES = "total_auto_throttle_in_bytes"; + static final String TOTAL_THROTTLE_BYTES_PER_SEC = "total_auto_throttle"; } @Override diff --git a/core/src/main/java/org/elasticsearch/index/percolator/PercolatorQueryCacheStats.java b/core/src/main/java/org/elasticsearch/index/percolator/PercolatorQueryCacheStats.java index a8e3b7f4799..cbc21286e20 100644 --- a/core/src/main/java/org/elasticsearch/index/percolator/PercolatorQueryCacheStats.java +++ b/core/src/main/java/org/elasticsearch/index/percolator/PercolatorQueryCacheStats.java @@ -23,7 +23,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -68,8 +67,8 @@ public class PercolatorQueryCacheStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString PERCOLATOR = new XContentBuilderString("percolator"); - static final XContentBuilderString QUERIES = new XContentBuilderString("num_queries"); + static final String PERCOLATOR = "percolator"; + static final String QUERIES = "num_queries"; } public static PercolatorQueryCacheStats readPercolateStats(StreamInput in) throws IOException { diff --git a/core/src/main/java/org/elasticsearch/index/recovery/RecoveryStats.java b/core/src/main/java/org/elasticsearch/index/recovery/RecoveryStats.java index 3f512b3e123..750e77092ce 100644 --- a/core/src/main/java/org/elasticsearch/index/recovery/RecoveryStats.java +++ b/core/src/main/java/org/elasticsearch/index/recovery/RecoveryStats.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; @@ -115,11 +114,11 @@ public class RecoveryStats implements ToXContent, Streamable { } static final class Fields { - static final XContentBuilderString RECOVERY = new XContentBuilderString("recovery"); - static final XContentBuilderString CURRENT_AS_SOURCE = new XContentBuilderString("current_as_source"); - static final XContentBuilderString CURRENT_AS_TARGET = new XContentBuilderString("current_as_target"); - static final XContentBuilderString THROTTLE_TIME = new XContentBuilderString("throttle_time"); - static final XContentBuilderString THROTTLE_TIME_IN_MILLIS = new XContentBuilderString("throttle_time_in_millis"); + static final String RECOVERY = "recovery"; + static final String CURRENT_AS_SOURCE = "current_as_source"; + static final String CURRENT_AS_TARGET = "current_as_target"; + static final String THROTTLE_TIME = "throttle_time"; + static final String THROTTLE_TIME_IN_MILLIS = "throttle_time_in_millis"; } @Override diff --git a/core/src/main/java/org/elasticsearch/index/refresh/RefreshStats.java b/core/src/main/java/org/elasticsearch/index/refresh/RefreshStats.java index 4ef6e9dbb31..9b9b4673acc 100644 --- a/core/src/main/java/org/elasticsearch/index/refresh/RefreshStats.java +++ b/core/src/main/java/org/elasticsearch/index/refresh/RefreshStats.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -98,10 +97,10 @@ public class RefreshStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString REFRESH = new XContentBuilderString("refresh"); - static final XContentBuilderString TOTAL = new XContentBuilderString("total"); - static final XContentBuilderString TOTAL_TIME = new XContentBuilderString("total_time"); - static final XContentBuilderString TOTAL_TIME_IN_MILLIS = new XContentBuilderString("total_time_in_millis"); + static final String REFRESH = "refresh"; + static final String TOTAL = "total"; + static final String TOTAL_TIME = "total_time"; + static final String TOTAL_TIME_IN_MILLIS = "total_time_in_millis"; } @Override @@ -115,4 +114,4 @@ public class RefreshStats implements Streamable, ToXContent { out.writeVLong(total); out.writeVLong(totalTimeInMillis); } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java b/core/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java index 83252103c40..d514571d0e2 100644 --- a/core/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java +++ b/core/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java @@ -26,7 +26,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentFactory; import java.io.IOException; @@ -320,25 +319,25 @@ public class SearchStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString SEARCH = new XContentBuilderString("search"); - static final XContentBuilderString OPEN_CONTEXTS = new XContentBuilderString("open_contexts"); - static final XContentBuilderString GROUPS = new XContentBuilderString("groups"); - static final XContentBuilderString QUERY_TOTAL = new XContentBuilderString("query_total"); - static final XContentBuilderString QUERY_TIME = new XContentBuilderString("query_time"); - static final XContentBuilderString QUERY_TIME_IN_MILLIS = new XContentBuilderString("query_time_in_millis"); - static final XContentBuilderString QUERY_CURRENT = new XContentBuilderString("query_current"); - static final XContentBuilderString FETCH_TOTAL = new XContentBuilderString("fetch_total"); - static final XContentBuilderString FETCH_TIME = new XContentBuilderString("fetch_time"); - static final XContentBuilderString FETCH_TIME_IN_MILLIS = new XContentBuilderString("fetch_time_in_millis"); - static final XContentBuilderString FETCH_CURRENT = new XContentBuilderString("fetch_current"); - static final XContentBuilderString SCROLL_TOTAL = new XContentBuilderString("scroll_total"); - static final XContentBuilderString SCROLL_TIME = new XContentBuilderString("scroll_time"); - static final XContentBuilderString SCROLL_TIME_IN_MILLIS = new XContentBuilderString("scroll_time_in_millis"); - static final XContentBuilderString SCROLL_CURRENT = new XContentBuilderString("scroll_current"); - static final XContentBuilderString SUGGEST_TOTAL = new XContentBuilderString("suggest_total"); - static final XContentBuilderString SUGGEST_TIME = new XContentBuilderString("suggest_time"); - static final XContentBuilderString SUGGEST_TIME_IN_MILLIS = new XContentBuilderString("suggest_time_in_millis"); - static final XContentBuilderString SUGGEST_CURRENT = new XContentBuilderString("suggest_current"); + static final String SEARCH = "search"; + static final String OPEN_CONTEXTS = "open_contexts"; + static final String GROUPS = "groups"; + static final String QUERY_TOTAL = "query_total"; + static final String QUERY_TIME = "query_time"; + static final String QUERY_TIME_IN_MILLIS = "query_time_in_millis"; + static final String QUERY_CURRENT = "query_current"; + static final String FETCH_TOTAL = "fetch_total"; + static final String FETCH_TIME = "fetch_time"; + static final String FETCH_TIME_IN_MILLIS = "fetch_time_in_millis"; + static final String FETCH_CURRENT = "fetch_current"; + static final String SCROLL_TOTAL = "scroll_total"; + static final String SCROLL_TIME = "scroll_time"; + static final String SCROLL_TIME_IN_MILLIS = "scroll_time_in_millis"; + static final String SCROLL_CURRENT = "scroll_current"; + static final String SUGGEST_TOTAL = "suggest_total"; + static final String SUGGEST_TIME = "suggest_time"; + static final String SUGGEST_TIME_IN_MILLIS = "suggest_time_in_millis"; + static final String SUGGEST_CURRENT = "suggest_current"; } public static SearchStats readSearchStats(StreamInput in) throws IOException { diff --git a/core/src/main/java/org/elasticsearch/index/shard/DocsStats.java b/core/src/main/java/org/elasticsearch/index/shard/DocsStats.java index 3ce99e4e98c..bfb95b426b1 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/DocsStats.java +++ b/core/src/main/java/org/elasticsearch/index/shard/DocsStats.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -88,8 +87,8 @@ public class DocsStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString DOCS = new XContentBuilderString("docs"); - static final XContentBuilderString COUNT = new XContentBuilderString("count"); - static final XContentBuilderString DELETED = new XContentBuilderString("deleted"); + static final String DOCS = "docs"; + static final String COUNT = "count"; + static final String DELETED = "deleted"; } } diff --git a/core/src/main/java/org/elasticsearch/index/shard/IndexingStats.java b/core/src/main/java/org/elasticsearch/index/shard/IndexingStats.java index beafbefddcd..97f9dd2b92f 100644 --- a/core/src/main/java/org/elasticsearch/index/shard/IndexingStats.java +++ b/core/src/main/java/org/elasticsearch/index/shard/IndexingStats.java @@ -27,7 +27,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; import java.util.HashMap; @@ -269,21 +268,21 @@ public class IndexingStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString INDEXING = new XContentBuilderString("indexing"); - static final XContentBuilderString TYPES = new XContentBuilderString("types"); - static final XContentBuilderString INDEX_TOTAL = new XContentBuilderString("index_total"); - static final XContentBuilderString INDEX_TIME = new XContentBuilderString("index_time"); - static final XContentBuilderString INDEX_TIME_IN_MILLIS = new XContentBuilderString("index_time_in_millis"); - static final XContentBuilderString INDEX_CURRENT = new XContentBuilderString("index_current"); - static final XContentBuilderString INDEX_FAILED = new XContentBuilderString("index_failed"); - static final XContentBuilderString DELETE_TOTAL = new XContentBuilderString("delete_total"); - static final XContentBuilderString DELETE_TIME = new XContentBuilderString("delete_time"); - static final XContentBuilderString DELETE_TIME_IN_MILLIS = new XContentBuilderString("delete_time_in_millis"); - static final XContentBuilderString DELETE_CURRENT = new XContentBuilderString("delete_current"); - static final XContentBuilderString NOOP_UPDATE_TOTAL = new XContentBuilderString("noop_update_total"); - static final XContentBuilderString IS_THROTTLED = new XContentBuilderString("is_throttled"); - static final XContentBuilderString THROTTLED_TIME_IN_MILLIS = new XContentBuilderString("throttle_time_in_millis"); - static final XContentBuilderString THROTTLED_TIME = new XContentBuilderString("throttle_time"); + static final String INDEXING = "indexing"; + static final String TYPES = "types"; + static final String INDEX_TOTAL = "index_total"; + static final String INDEX_TIME = "index_time"; + static final String INDEX_TIME_IN_MILLIS = "index_time_in_millis"; + static final String INDEX_CURRENT = "index_current"; + static final String INDEX_FAILED = "index_failed"; + static final String DELETE_TOTAL = "delete_total"; + static final String DELETE_TIME = "delete_time"; + static final String DELETE_TIME_IN_MILLIS = "delete_time_in_millis"; + static final String DELETE_CURRENT = "delete_current"; + static final String NOOP_UPDATE_TOTAL = "noop_update_total"; + static final String IS_THROTTLED = "is_throttled"; + static final String THROTTLED_TIME_IN_MILLIS = "throttle_time_in_millis"; + static final String THROTTLED_TIME = "throttle_time"; } public static IndexingStats readIndexingStats(StreamInput in) throws IOException { diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshot.java b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshot.java index 08af2843ce4..60b7ec2112e 100644 --- a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshot.java +++ b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshot.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.FromXContentBuilder; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.store.StoreFileMetaData; @@ -220,13 +219,13 @@ public class BlobStoreIndexShardSnapshot implements ToXContent, FromXContentBuil } static final class Fields { - static final XContentBuilderString NAME = new XContentBuilderString("name"); - static final XContentBuilderString PHYSICAL_NAME = new XContentBuilderString("physical_name"); - static final XContentBuilderString LENGTH = new XContentBuilderString("length"); - static final XContentBuilderString CHECKSUM = new XContentBuilderString("checksum"); - static final XContentBuilderString PART_SIZE = new XContentBuilderString("part_size"); - static final XContentBuilderString WRITTEN_BY = new XContentBuilderString("written_by"); - static final XContentBuilderString META_HASH = new XContentBuilderString("meta_hash"); + static final String NAME = "name"; + static final String PHYSICAL_NAME = "physical_name"; + static final String LENGTH = "length"; + static final String CHECKSUM = "checksum"; + static final String PART_SIZE = "part_size"; + static final String WRITTEN_BY = "written_by"; + static final String META_HASH = "meta_hash"; } /** @@ -426,13 +425,13 @@ public class BlobStoreIndexShardSnapshot implements ToXContent, FromXContentBuil } static final class Fields { - static final XContentBuilderString NAME = new XContentBuilderString("name"); - static final XContentBuilderString INDEX_VERSION = new XContentBuilderString("index_version"); - static final XContentBuilderString START_TIME = new XContentBuilderString("start_time"); - static final XContentBuilderString TIME = new XContentBuilderString("time"); - static final XContentBuilderString NUMBER_OF_FILES = new XContentBuilderString("number_of_files"); - static final XContentBuilderString TOTAL_SIZE = new XContentBuilderString("total_size"); - static final XContentBuilderString FILES = new XContentBuilderString("files"); + static final String NAME = "name"; + static final String INDEX_VERSION = "index_version"; + static final String START_TIME = "start_time"; + static final String TIME = "time"; + static final String NUMBER_OF_FILES = "number_of_files"; + static final String TOTAL_SIZE = "total_size"; + static final String FILES = "files"; } static final class ParseFields { diff --git a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java index 7b7a8dd9829..5b66d9b6f6f 100644 --- a/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java +++ b/core/src/main/java/org/elasticsearch/index/snapshots/blobstore/BlobStoreIndexShardSnapshots.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.xcontent.FromXContentBuilder; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.snapshots.blobstore.BlobStoreIndexShardSnapshot.FileInfo; @@ -149,8 +148,8 @@ public class BlobStoreIndexShardSnapshots implements Iterable, To } static final class Fields { - static final XContentBuilderString FILES = new XContentBuilderString("files"); - static final XContentBuilderString SNAPSHOTS = new XContentBuilderString("snapshots"); + static final String FILES = "files"; + static final String SNAPSHOTS = "snapshots"; } static final class ParseFields { diff --git a/core/src/main/java/org/elasticsearch/index/store/StoreStats.java b/core/src/main/java/org/elasticsearch/index/store/StoreStats.java index 0eb720456c5..d777d7b7830 100644 --- a/core/src/main/java/org/elasticsearch/index/store/StoreStats.java +++ b/core/src/main/java/org/elasticsearch/index/store/StoreStats.java @@ -26,7 +26,6 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -108,10 +107,10 @@ public class StoreStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString STORE = new XContentBuilderString("store"); - static final XContentBuilderString SIZE = new XContentBuilderString("size"); - static final XContentBuilderString SIZE_IN_BYTES = new XContentBuilderString("size_in_bytes"); - static final XContentBuilderString THROTTLE_TIME = new XContentBuilderString("throttle_time"); - static final XContentBuilderString THROTTLE_TIME_IN_MILLIS = new XContentBuilderString("throttle_time_in_millis"); + static final String STORE = "store"; + static final String SIZE = "size"; + static final String SIZE_IN_BYTES = "size_in_bytes"; + static final String THROTTLE_TIME = "throttle_time"; + static final String THROTTLE_TIME_IN_MILLIS = "throttle_time_in_millis"; } } diff --git a/core/src/main/java/org/elasticsearch/index/translog/TranslogStats.java b/core/src/main/java/org/elasticsearch/index/translog/TranslogStats.java index a4431b520cd..263a658c08d 100644 --- a/core/src/main/java/org/elasticsearch/index/translog/TranslogStats.java +++ b/core/src/main/java/org/elasticsearch/index/translog/TranslogStats.java @@ -23,7 +23,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -77,10 +76,10 @@ public class TranslogStats extends ToXContentToBytes implements Streamable { } static final class Fields { - static final XContentBuilderString TRANSLOG = new XContentBuilderString("translog"); - static final XContentBuilderString OPERATIONS = new XContentBuilderString("operations"); - static final XContentBuilderString SIZE = new XContentBuilderString("size"); - static final XContentBuilderString SIZE_IN_BYTES = new XContentBuilderString("size_in_bytes"); + static final String TRANSLOG = "translog"; + static final String OPERATIONS = "operations"; + static final String SIZE = "size"; + static final String SIZE_IN_BYTES = "size_in_bytes"; } @Override diff --git a/core/src/main/java/org/elasticsearch/index/warmer/WarmerStats.java b/core/src/main/java/org/elasticsearch/index/warmer/WarmerStats.java index 2e68d14cf50..233dbf4f5fe 100644 --- a/core/src/main/java/org/elasticsearch/index/warmer/WarmerStats.java +++ b/core/src/main/java/org/elasticsearch/index/warmer/WarmerStats.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -104,11 +103,11 @@ public class WarmerStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString WARMER = new XContentBuilderString("warmer"); - static final XContentBuilderString CURRENT = new XContentBuilderString("current"); - static final XContentBuilderString TOTAL = new XContentBuilderString("total"); - static final XContentBuilderString TOTAL_TIME = new XContentBuilderString("total_time"); - static final XContentBuilderString TOTAL_TIME_IN_MILLIS = new XContentBuilderString("total_time_in_millis"); + static final String WARMER = "warmer"; + static final String CURRENT = "current"; + static final String TOTAL = "total"; + static final String TOTAL_TIME = "total_time"; + static final String TOTAL_TIME_IN_MILLIS = "total_time_in_millis"; } @Override @@ -124,4 +123,4 @@ public class WarmerStats implements Streamable, ToXContent { out.writeVLong(total); out.writeVLong(totalTimeInMillis); } -} \ No newline at end of file +} diff --git a/core/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java b/core/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java index 237975f2899..f4736f0332e 100644 --- a/core/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java +++ b/core/src/main/java/org/elasticsearch/indices/NodeIndicesStats.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.index.Index; import org.elasticsearch.index.cache.query.QueryCacheStats; import org.elasticsearch.index.cache.request.RequestCacheStats; @@ -252,6 +251,6 @@ public class NodeIndicesStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString INDICES = new XContentBuilderString("indices"); + static final String INDICES = "indices"; } } diff --git a/core/src/main/java/org/elasticsearch/indices/breaker/AllCircuitBreakerStats.java b/core/src/main/java/org/elasticsearch/indices/breaker/AllCircuitBreakerStats.java index 693a6f5b453..09f0cd99001 100644 --- a/core/src/main/java/org/elasticsearch/indices/breaker/AllCircuitBreakerStats.java +++ b/core/src/main/java/org/elasticsearch/indices/breaker/AllCircuitBreakerStats.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -96,6 +95,6 @@ public class AllCircuitBreakerStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString BREAKERS = new XContentBuilderString("breakers"); + static final String BREAKERS = "breakers"; } } diff --git a/core/src/main/java/org/elasticsearch/indices/breaker/CircuitBreakerStats.java b/core/src/main/java/org/elasticsearch/indices/breaker/CircuitBreakerStats.java index 8d3043c9ccc..eca235711bb 100644 --- a/core/src/main/java/org/elasticsearch/indices/breaker/CircuitBreakerStats.java +++ b/core/src/main/java/org/elasticsearch/indices/breaker/CircuitBreakerStats.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; import java.util.Locale; @@ -119,11 +118,11 @@ public class CircuitBreakerStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString LIMIT = new XContentBuilderString("limit_size_in_bytes"); - static final XContentBuilderString LIMIT_HUMAN = new XContentBuilderString("limit_size"); - static final XContentBuilderString ESTIMATED = new XContentBuilderString("estimated_size_in_bytes"); - static final XContentBuilderString ESTIMATED_HUMAN = new XContentBuilderString("estimated_size"); - static final XContentBuilderString OVERHEAD = new XContentBuilderString("overhead"); - static final XContentBuilderString TRIPPED_COUNT = new XContentBuilderString("tripped"); + static final String LIMIT = "limit_size_in_bytes"; + static final String LIMIT_HUMAN = "limit_size"; + static final String ESTIMATED = "estimated_size_in_bytes"; + static final String ESTIMATED_HUMAN = "estimated_size"; + static final String OVERHEAD = "overhead"; + static final String TRIPPED_COUNT = "tripped"; } } diff --git a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java index 6eccf8f02db..326f5362b7e 100644 --- a/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java +++ b/core/src/main/java/org/elasticsearch/indices/recovery/RecoveryState.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.index.shard.ShardId; @@ -348,44 +347,44 @@ public class RecoveryState implements ToXContent, Streamable { } static final class Fields { - static final XContentBuilderString ID = new XContentBuilderString("id"); - static final XContentBuilderString TYPE = new XContentBuilderString("type"); - static final XContentBuilderString STAGE = new XContentBuilderString("stage"); - static final XContentBuilderString PRIMARY = new XContentBuilderString("primary"); - static final XContentBuilderString START_TIME = new XContentBuilderString("start_time"); - static final XContentBuilderString START_TIME_IN_MILLIS = new XContentBuilderString("start_time_in_millis"); - static final XContentBuilderString STOP_TIME = new XContentBuilderString("stop_time"); - static final XContentBuilderString STOP_TIME_IN_MILLIS = new XContentBuilderString("stop_time_in_millis"); - static final XContentBuilderString TOTAL_TIME = new XContentBuilderString("total_time"); - static final XContentBuilderString TOTAL_TIME_IN_MILLIS = new XContentBuilderString("total_time_in_millis"); - static final XContentBuilderString SOURCE = new XContentBuilderString("source"); - static final XContentBuilderString HOST = new XContentBuilderString("host"); - static final XContentBuilderString TRANSPORT_ADDRESS = new XContentBuilderString("transport_address"); - static final XContentBuilderString IP = new XContentBuilderString("ip"); - static final XContentBuilderString NAME = new XContentBuilderString("name"); - static final XContentBuilderString TARGET = new XContentBuilderString("target"); - static final XContentBuilderString INDEX = new XContentBuilderString("index"); - static final XContentBuilderString TRANSLOG = new XContentBuilderString("translog"); - static final XContentBuilderString TOTAL_ON_START = new XContentBuilderString("total_on_start"); - static final XContentBuilderString VERIFY_INDEX = new XContentBuilderString("verify_index"); - static final XContentBuilderString RECOVERED = new XContentBuilderString("recovered"); - static final XContentBuilderString RECOVERED_IN_BYTES = new XContentBuilderString("recovered_in_bytes"); - static final XContentBuilderString CHECK_INDEX_TIME = new XContentBuilderString("check_index_time"); - static final XContentBuilderString CHECK_INDEX_TIME_IN_MILLIS = new XContentBuilderString("check_index_time_in_millis"); - static final XContentBuilderString LENGTH = new XContentBuilderString("length"); - static final XContentBuilderString LENGTH_IN_BYTES = new XContentBuilderString("length_in_bytes"); - static final XContentBuilderString FILES = new XContentBuilderString("files"); - static final XContentBuilderString TOTAL = new XContentBuilderString("total"); - static final XContentBuilderString TOTAL_IN_BYTES = new XContentBuilderString("total_in_bytes"); - static final XContentBuilderString REUSED = new XContentBuilderString("reused"); - static final XContentBuilderString REUSED_IN_BYTES = new XContentBuilderString("reused_in_bytes"); - static final XContentBuilderString PERCENT = new XContentBuilderString("percent"); - static final XContentBuilderString DETAILS = new XContentBuilderString("details"); - static final XContentBuilderString SIZE = new XContentBuilderString("size"); - static final XContentBuilderString SOURCE_THROTTLE_TIME = new XContentBuilderString("source_throttle_time"); - static final XContentBuilderString SOURCE_THROTTLE_TIME_IN_MILLIS = new XContentBuilderString("source_throttle_time_in_millis"); - static final XContentBuilderString TARGET_THROTTLE_TIME = new XContentBuilderString("target_throttle_time"); - static final XContentBuilderString TARGET_THROTTLE_TIME_IN_MILLIS = new XContentBuilderString("target_throttle_time_in_millis"); + static final String ID = "id"; + static final String TYPE = "type"; + static final String STAGE = "stage"; + static final String PRIMARY = "primary"; + static final String START_TIME = "start_time"; + static final String START_TIME_IN_MILLIS = "start_time_in_millis"; + static final String STOP_TIME = "stop_time"; + static final String STOP_TIME_IN_MILLIS = "stop_time_in_millis"; + static final String TOTAL_TIME = "total_time"; + static final String TOTAL_TIME_IN_MILLIS = "total_time_in_millis"; + static final String SOURCE = "source"; + static final String HOST = "host"; + static final String TRANSPORT_ADDRESS = "transport_address"; + static final String IP = "ip"; + static final String NAME = "name"; + static final String TARGET = "target"; + static final String INDEX = "index"; + static final String TRANSLOG = "translog"; + static final String TOTAL_ON_START = "total_on_start"; + static final String VERIFY_INDEX = "verify_index"; + static final String RECOVERED = "recovered"; + static final String RECOVERED_IN_BYTES = "recovered_in_bytes"; + static final String CHECK_INDEX_TIME = "check_index_time"; + static final String CHECK_INDEX_TIME_IN_MILLIS = "check_index_time_in_millis"; + static final String LENGTH = "length"; + static final String LENGTH_IN_BYTES = "length_in_bytes"; + static final String FILES = "files"; + static final String TOTAL = "total"; + static final String TOTAL_IN_BYTES = "total_in_bytes"; + static final String REUSED = "reused"; + static final String REUSED_IN_BYTES = "reused_in_bytes"; + static final String PERCENT = "percent"; + static final String DETAILS = "details"; + static final String SIZE = "size"; + static final String SOURCE_THROTTLE_TIME = "source_throttle_time"; + static final String SOURCE_THROTTLE_TIME_IN_MILLIS = "source_throttle_time_in_millis"; + static final String TARGET_THROTTLE_TIME = "target_throttle_time"; + static final String TARGET_THROTTLE_TIME_IN_MILLIS = "target_throttle_time_in_millis"; } public static class Timer implements Streamable { diff --git a/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java b/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java index 55ce159f397..2ae27b92855 100644 --- a/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java +++ b/core/src/main/java/org/elasticsearch/monitor/fs/FsInfo.java @@ -26,7 +26,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; import java.util.Arrays; @@ -150,16 +149,16 @@ public class FsInfo implements Iterable, Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString PATH = new XContentBuilderString("path"); - static final XContentBuilderString MOUNT = new XContentBuilderString("mount"); - static final XContentBuilderString TYPE = new XContentBuilderString("type"); - static final XContentBuilderString TOTAL = new XContentBuilderString("total"); - static final XContentBuilderString TOTAL_IN_BYTES = new XContentBuilderString("total_in_bytes"); - static final XContentBuilderString FREE = new XContentBuilderString("free"); - static final XContentBuilderString FREE_IN_BYTES = new XContentBuilderString("free_in_bytes"); - static final XContentBuilderString AVAILABLE = new XContentBuilderString("available"); - static final XContentBuilderString AVAILABLE_IN_BYTES = new XContentBuilderString("available_in_bytes"); - static final XContentBuilderString SPINS = new XContentBuilderString("spins"); + static final String PATH = "path"; + static final String MOUNT = "mount"; + static final String TYPE = "type"; + static final String TOTAL = "total"; + static final String TOTAL_IN_BYTES = "total_in_bytes"; + static final String FREE = "free"; + static final String FREE_IN_BYTES = "free_in_bytes"; + static final String AVAILABLE = "available"; + static final String AVAILABLE_IN_BYTES = "available_in_bytes"; + static final String SPINS = "spins"; } @Override @@ -263,10 +262,10 @@ public class FsInfo implements Iterable, Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString FS = new XContentBuilderString("fs"); - static final XContentBuilderString TIMESTAMP = new XContentBuilderString("timestamp"); - static final XContentBuilderString DATA = new XContentBuilderString("data"); - static final XContentBuilderString TOTAL = new XContentBuilderString("total"); + static final String FS = "fs"; + static final String TIMESTAMP = "timestamp"; + static final String DATA = "data"; + static final String TOTAL = "total"; } @Override diff --git a/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java b/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java index d35497834f7..3e39edaa47c 100644 --- a/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java +++ b/core/src/main/java/org/elasticsearch/monitor/jvm/JvmInfo.java @@ -26,7 +26,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; import java.lang.management.GarbageCollectorMXBean; @@ -359,29 +358,29 @@ public class JvmInfo implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString JVM = new XContentBuilderString("jvm"); - static final XContentBuilderString PID = new XContentBuilderString("pid"); - static final XContentBuilderString VERSION = new XContentBuilderString("version"); - static final XContentBuilderString VM_NAME = new XContentBuilderString("vm_name"); - static final XContentBuilderString VM_VERSION = new XContentBuilderString("vm_version"); - static final XContentBuilderString VM_VENDOR = new XContentBuilderString("vm_vendor"); - static final XContentBuilderString START_TIME = new XContentBuilderString("start_time"); - static final XContentBuilderString START_TIME_IN_MILLIS = new XContentBuilderString("start_time_in_millis"); + static final String JVM = "jvm"; + static final String PID = "pid"; + static final String VERSION = "version"; + static final String VM_NAME = "vm_name"; + static final String VM_VERSION = "vm_version"; + static final String VM_VENDOR = "vm_vendor"; + static final String START_TIME = "start_time"; + static final String START_TIME_IN_MILLIS = "start_time_in_millis"; - static final XContentBuilderString MEM = new XContentBuilderString("mem"); - static final XContentBuilderString HEAP_INIT = new XContentBuilderString("heap_init"); - static final XContentBuilderString HEAP_INIT_IN_BYTES = new XContentBuilderString("heap_init_in_bytes"); - static final XContentBuilderString HEAP_MAX = new XContentBuilderString("heap_max"); - static final XContentBuilderString HEAP_MAX_IN_BYTES = new XContentBuilderString("heap_max_in_bytes"); - static final XContentBuilderString NON_HEAP_INIT = new XContentBuilderString("non_heap_init"); - static final XContentBuilderString NON_HEAP_INIT_IN_BYTES = new XContentBuilderString("non_heap_init_in_bytes"); - static final XContentBuilderString NON_HEAP_MAX = new XContentBuilderString("non_heap_max"); - static final XContentBuilderString NON_HEAP_MAX_IN_BYTES = new XContentBuilderString("non_heap_max_in_bytes"); - static final XContentBuilderString DIRECT_MAX = new XContentBuilderString("direct_max"); - static final XContentBuilderString DIRECT_MAX_IN_BYTES = new XContentBuilderString("direct_max_in_bytes"); - static final XContentBuilderString GC_COLLECTORS = new XContentBuilderString("gc_collectors"); - static final XContentBuilderString MEMORY_POOLS = new XContentBuilderString("memory_pools"); - static final XContentBuilderString USING_COMPRESSED_OOPS = new XContentBuilderString("using_compressed_ordinary_object_pointers"); + static final String MEM = "mem"; + static final String HEAP_INIT = "heap_init"; + static final String HEAP_INIT_IN_BYTES = "heap_init_in_bytes"; + static final String HEAP_MAX = "heap_max"; + static final String HEAP_MAX_IN_BYTES = "heap_max_in_bytes"; + static final String NON_HEAP_INIT = "non_heap_init"; + static final String NON_HEAP_INIT_IN_BYTES = "non_heap_init_in_bytes"; + static final String NON_HEAP_MAX = "non_heap_max"; + static final String NON_HEAP_MAX_IN_BYTES = "non_heap_max_in_bytes"; + static final String DIRECT_MAX = "direct_max"; + static final String DIRECT_MAX_IN_BYTES = "direct_max_in_bytes"; + static final String GC_COLLECTORS = "gc_collectors"; + static final String MEMORY_POOLS = "memory_pools"; + static final String USING_COMPRESSED_OOPS = "using_compressed_ordinary_object_pointers"; } public static JvmInfo readJvmInfo(StreamInput in) throws IOException { diff --git a/core/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java b/core/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java index c78ed608068..43b675f34a2 100644 --- a/core/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java +++ b/core/src/main/java/org/elasticsearch/monitor/jvm/JvmStats.java @@ -26,7 +26,6 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; import java.lang.management.BufferPoolMXBean; @@ -254,54 +253,54 @@ public class JvmStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString JVM = new XContentBuilderString("jvm"); - static final XContentBuilderString TIMESTAMP = new XContentBuilderString("timestamp"); - static final XContentBuilderString UPTIME = new XContentBuilderString("uptime"); - static final XContentBuilderString UPTIME_IN_MILLIS = new XContentBuilderString("uptime_in_millis"); + static final String JVM = "jvm"; + static final String TIMESTAMP = "timestamp"; + static final String UPTIME = "uptime"; + static final String UPTIME_IN_MILLIS = "uptime_in_millis"; - static final XContentBuilderString MEM = new XContentBuilderString("mem"); - static final XContentBuilderString HEAP_USED = new XContentBuilderString("heap_used"); - static final XContentBuilderString HEAP_USED_IN_BYTES = new XContentBuilderString("heap_used_in_bytes"); - static final XContentBuilderString HEAP_USED_PERCENT = new XContentBuilderString("heap_used_percent"); - static final XContentBuilderString HEAP_MAX = new XContentBuilderString("heap_max"); - static final XContentBuilderString HEAP_MAX_IN_BYTES = new XContentBuilderString("heap_max_in_bytes"); - static final XContentBuilderString HEAP_COMMITTED = new XContentBuilderString("heap_committed"); - static final XContentBuilderString HEAP_COMMITTED_IN_BYTES = new XContentBuilderString("heap_committed_in_bytes"); + static final String MEM = "mem"; + static final String HEAP_USED = "heap_used"; + static final String HEAP_USED_IN_BYTES = "heap_used_in_bytes"; + static final String HEAP_USED_PERCENT = "heap_used_percent"; + static final String HEAP_MAX = "heap_max"; + static final String HEAP_MAX_IN_BYTES = "heap_max_in_bytes"; + static final String HEAP_COMMITTED = "heap_committed"; + static final String HEAP_COMMITTED_IN_BYTES = "heap_committed_in_bytes"; - static final XContentBuilderString NON_HEAP_USED = new XContentBuilderString("non_heap_used"); - static final XContentBuilderString NON_HEAP_USED_IN_BYTES = new XContentBuilderString("non_heap_used_in_bytes"); - static final XContentBuilderString NON_HEAP_COMMITTED = new XContentBuilderString("non_heap_committed"); - static final XContentBuilderString NON_HEAP_COMMITTED_IN_BYTES = new XContentBuilderString("non_heap_committed_in_bytes"); + static final String NON_HEAP_USED = "non_heap_used"; + static final String NON_HEAP_USED_IN_BYTES = "non_heap_used_in_bytes"; + static final String NON_HEAP_COMMITTED = "non_heap_committed"; + static final String NON_HEAP_COMMITTED_IN_BYTES = "non_heap_committed_in_bytes"; - static final XContentBuilderString POOLS = new XContentBuilderString("pools"); - static final XContentBuilderString USED = new XContentBuilderString("used"); - static final XContentBuilderString USED_IN_BYTES = new XContentBuilderString("used_in_bytes"); - static final XContentBuilderString MAX = new XContentBuilderString("max"); - static final XContentBuilderString MAX_IN_BYTES = new XContentBuilderString("max_in_bytes"); - static final XContentBuilderString PEAK_USED = new XContentBuilderString("peak_used"); - static final XContentBuilderString PEAK_USED_IN_BYTES = new XContentBuilderString("peak_used_in_bytes"); - static final XContentBuilderString PEAK_MAX = new XContentBuilderString("peak_max"); - static final XContentBuilderString PEAK_MAX_IN_BYTES = new XContentBuilderString("peak_max_in_bytes"); + static final String POOLS = "pools"; + static final String USED = "used"; + static final String USED_IN_BYTES = "used_in_bytes"; + static final String MAX = "max"; + static final String MAX_IN_BYTES = "max_in_bytes"; + static final String PEAK_USED = "peak_used"; + static final String PEAK_USED_IN_BYTES = "peak_used_in_bytes"; + static final String PEAK_MAX = "peak_max"; + static final String PEAK_MAX_IN_BYTES = "peak_max_in_bytes"; - static final XContentBuilderString THREADS = new XContentBuilderString("threads"); - static final XContentBuilderString COUNT = new XContentBuilderString("count"); - static final XContentBuilderString PEAK_COUNT = new XContentBuilderString("peak_count"); + static final String THREADS = "threads"; + static final String COUNT = "count"; + static final String PEAK_COUNT = "peak_count"; - static final XContentBuilderString GC = new XContentBuilderString("gc"); - static final XContentBuilderString COLLECTORS = new XContentBuilderString("collectors"); - static final XContentBuilderString COLLECTION_COUNT = new XContentBuilderString("collection_count"); - static final XContentBuilderString COLLECTION_TIME = new XContentBuilderString("collection_time"); - static final XContentBuilderString COLLECTION_TIME_IN_MILLIS = new XContentBuilderString("collection_time_in_millis"); + static final String GC = "gc"; + static final String COLLECTORS = "collectors"; + static final String COLLECTION_COUNT = "collection_count"; + static final String COLLECTION_TIME = "collection_time"; + static final String COLLECTION_TIME_IN_MILLIS = "collection_time_in_millis"; - static final XContentBuilderString BUFFER_POOLS = new XContentBuilderString("buffer_pools"); - static final XContentBuilderString NAME = new XContentBuilderString("name"); - static final XContentBuilderString TOTAL_CAPACITY = new XContentBuilderString("total_capacity"); - static final XContentBuilderString TOTAL_CAPACITY_IN_BYTES = new XContentBuilderString("total_capacity_in_bytes"); + static final String BUFFER_POOLS = "buffer_pools"; + static final String NAME = "name"; + static final String TOTAL_CAPACITY = "total_capacity"; + static final String TOTAL_CAPACITY_IN_BYTES = "total_capacity_in_bytes"; - static final XContentBuilderString CLASSES = new XContentBuilderString("classes"); - static final XContentBuilderString CURRENT_LOADED_COUNT = new XContentBuilderString("current_loaded_count"); - static final XContentBuilderString TOTAL_LOADED_COUNT = new XContentBuilderString("total_loaded_count"); - static final XContentBuilderString TOTAL_UNLOADED_COUNT = new XContentBuilderString("total_unloaded_count"); + static final String CLASSES = "classes"; + static final String CURRENT_LOADED_COUNT = "current_loaded_count"; + static final String TOTAL_LOADED_COUNT = "total_loaded_count"; + static final String TOTAL_UNLOADED_COUNT = "total_unloaded_count"; } diff --git a/core/src/main/java/org/elasticsearch/monitor/os/OsInfo.java b/core/src/main/java/org/elasticsearch/monitor/os/OsInfo.java index d94447221c3..f0520358524 100644 --- a/core/src/main/java/org/elasticsearch/monitor/os/OsInfo.java +++ b/core/src/main/java/org/elasticsearch/monitor/os/OsInfo.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -68,14 +67,14 @@ public class OsInfo implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString OS = new XContentBuilderString("os"); - static final XContentBuilderString NAME = new XContentBuilderString("name"); - static final XContentBuilderString ARCH = new XContentBuilderString("arch"); - static final XContentBuilderString VERSION = new XContentBuilderString("version"); - static final XContentBuilderString REFRESH_INTERVAL = new XContentBuilderString("refresh_interval"); - static final XContentBuilderString REFRESH_INTERVAL_IN_MILLIS = new XContentBuilderString("refresh_interval_in_millis"); - static final XContentBuilderString AVAILABLE_PROCESSORS = new XContentBuilderString("available_processors"); - static final XContentBuilderString ALLOCATED_PROCESSORS = new XContentBuilderString("allocated_processors"); + static final String OS = "os"; + static final String NAME = "name"; + static final String ARCH = "arch"; + static final String VERSION = "version"; + static final String REFRESH_INTERVAL = "refresh_interval"; + static final String REFRESH_INTERVAL_IN_MILLIS = "refresh_interval_in_millis"; + static final String AVAILABLE_PROCESSORS = "available_processors"; + static final String ALLOCATED_PROCESSORS = "allocated_processors"; } @Override diff --git a/core/src/main/java/org/elasticsearch/monitor/os/OsStats.java b/core/src/main/java/org/elasticsearch/monitor/os/OsStats.java index 569f8825aa9..51302d7ae6b 100644 --- a/core/src/main/java/org/elasticsearch/monitor/os/OsStats.java +++ b/core/src/main/java/org/elasticsearch/monitor/os/OsStats.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; import java.util.Arrays; @@ -61,26 +60,26 @@ public class OsStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString OS = new XContentBuilderString("os"); - static final XContentBuilderString TIMESTAMP = new XContentBuilderString("timestamp"); - static final XContentBuilderString CPU = new XContentBuilderString("cpu"); - static final XContentBuilderString PERCENT = new XContentBuilderString("percent"); - static final XContentBuilderString LOAD_AVERAGE = new XContentBuilderString("load_average"); - static final XContentBuilderString LOAD_AVERAGE_1M = new XContentBuilderString("1m"); - static final XContentBuilderString LOAD_AVERAGE_5M = new XContentBuilderString("5m"); - static final XContentBuilderString LOAD_AVERAGE_15M = new XContentBuilderString("15m"); + static final String OS = "os"; + static final String TIMESTAMP = "timestamp"; + static final String CPU = "cpu"; + static final String PERCENT = "percent"; + static final String LOAD_AVERAGE = "load_average"; + static final String LOAD_AVERAGE_1M = new String("1m"); + static final String LOAD_AVERAGE_5M = new String("5m"); + static final String LOAD_AVERAGE_15M = new String("15m"); - static final XContentBuilderString MEM = new XContentBuilderString("mem"); - static final XContentBuilderString SWAP = new XContentBuilderString("swap"); - static final XContentBuilderString FREE = new XContentBuilderString("free"); - static final XContentBuilderString FREE_IN_BYTES = new XContentBuilderString("free_in_bytes"); - static final XContentBuilderString USED = new XContentBuilderString("used"); - static final XContentBuilderString USED_IN_BYTES = new XContentBuilderString("used_in_bytes"); - static final XContentBuilderString TOTAL = new XContentBuilderString("total"); - static final XContentBuilderString TOTAL_IN_BYTES = new XContentBuilderString("total_in_bytes"); + static final String MEM = "mem"; + static final String SWAP = "swap"; + static final String FREE = "free"; + static final String FREE_IN_BYTES = "free_in_bytes"; + static final String USED = "used"; + static final String USED_IN_BYTES = "used_in_bytes"; + static final String TOTAL = "total"; + static final String TOTAL_IN_BYTES = "total_in_bytes"; - static final XContentBuilderString FREE_PERCENT = new XContentBuilderString("free_percent"); - static final XContentBuilderString USED_PERCENT = new XContentBuilderString("used_percent"); + static final String FREE_PERCENT = "free_percent"; + static final String USED_PERCENT = "used_percent"; } @Override diff --git a/core/src/main/java/org/elasticsearch/monitor/process/ProcessInfo.java b/core/src/main/java/org/elasticsearch/monitor/process/ProcessInfo.java index 7d1ea03b085..cf9c9e63b87 100644 --- a/core/src/main/java/org/elasticsearch/monitor/process/ProcessInfo.java +++ b/core/src/main/java/org/elasticsearch/monitor/process/ProcessInfo.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -64,11 +63,11 @@ public class ProcessInfo implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString PROCESS = new XContentBuilderString("process"); - static final XContentBuilderString REFRESH_INTERVAL = new XContentBuilderString("refresh_interval"); - static final XContentBuilderString REFRESH_INTERVAL_IN_MILLIS = new XContentBuilderString("refresh_interval_in_millis"); - static final XContentBuilderString ID = new XContentBuilderString("id"); - static final XContentBuilderString MLOCKALL = new XContentBuilderString("mlockall"); + static final String PROCESS = "process"; + static final String REFRESH_INTERVAL = "refresh_interval"; + static final String REFRESH_INTERVAL_IN_MILLIS = "refresh_interval_in_millis"; + static final String ID = "id"; + static final String MLOCKALL = "mlockall"; } @Override diff --git a/core/src/main/java/org/elasticsearch/monitor/process/ProcessStats.java b/core/src/main/java/org/elasticsearch/monitor/process/ProcessStats.java index de447c98748..310cb215ae5 100644 --- a/core/src/main/java/org/elasticsearch/monitor/process/ProcessStats.java +++ b/core/src/main/java/org/elasticsearch/monitor/process/ProcessStats.java @@ -26,7 +26,6 @@ import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -65,19 +64,19 @@ public class ProcessStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString PROCESS = new XContentBuilderString("process"); - static final XContentBuilderString TIMESTAMP = new XContentBuilderString("timestamp"); - static final XContentBuilderString OPEN_FILE_DESCRIPTORS = new XContentBuilderString("open_file_descriptors"); - static final XContentBuilderString MAX_FILE_DESCRIPTORS = new XContentBuilderString("max_file_descriptors"); + static final String PROCESS = "process"; + static final String TIMESTAMP = "timestamp"; + static final String OPEN_FILE_DESCRIPTORS = "open_file_descriptors"; + static final String MAX_FILE_DESCRIPTORS = "max_file_descriptors"; - static final XContentBuilderString CPU = new XContentBuilderString("cpu"); - static final XContentBuilderString PERCENT = new XContentBuilderString("percent"); - static final XContentBuilderString TOTAL = new XContentBuilderString("total"); - static final XContentBuilderString TOTAL_IN_MILLIS = new XContentBuilderString("total_in_millis"); + static final String CPU = "cpu"; + static final String PERCENT = "percent"; + static final String TOTAL = "total"; + static final String TOTAL_IN_MILLIS = "total_in_millis"; - static final XContentBuilderString MEM = new XContentBuilderString("mem"); - static final XContentBuilderString TOTAL_VIRTUAL = new XContentBuilderString("total_virtual"); - static final XContentBuilderString TOTAL_VIRTUAL_IN_BYTES = new XContentBuilderString("total_virtual_in_bytes"); + static final String MEM = "mem"; + static final String TOTAL_VIRTUAL = "total_virtual"; + static final String TOTAL_VIRTUAL_IN_BYTES = "total_virtual_in_bytes"; } @Override diff --git a/core/src/main/java/org/elasticsearch/plugins/PluginInfo.java b/core/src/main/java/org/elasticsearch/plugins/PluginInfo.java index bd063b3312c..500861d8999 100644 --- a/core/src/main/java/org/elasticsearch/plugins/PluginInfo.java +++ b/core/src/main/java/org/elasticsearch/plugins/PluginInfo.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; import java.io.InputStream; @@ -39,11 +38,11 @@ public class PluginInfo implements Streamable, ToXContent { public static final String ES_PLUGIN_POLICY = "plugin-security.policy"; static final class Fields { - static final XContentBuilderString NAME = new XContentBuilderString("name"); - static final XContentBuilderString DESCRIPTION = new XContentBuilderString("description"); - static final XContentBuilderString URL = new XContentBuilderString("url"); - static final XContentBuilderString VERSION = new XContentBuilderString("version"); - static final XContentBuilderString CLASSNAME = new XContentBuilderString("classname"); + static final String NAME = "name"; + static final String DESCRIPTION = "description"; + static final String URL = "url"; + static final String VERSION = "version"; + static final String CLASSNAME = "classname"; } private String name; diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java index 720d19a7fe4..edce416072e 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/cluster/state/RestClusterStateAction.java @@ -30,7 +30,6 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; @@ -98,6 +97,6 @@ public class RestClusterStateAction extends BaseRestHandler { } static final class Fields { - static final XContentBuilderString CLUSTER_NAME = new XContentBuilderString("cluster_name"); + static final String CLUSTER_NAME = "cluster_name"; } } diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/get/RestGetAliasesAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/get/RestGetAliasesAction.java index d18b013efb2..cbebf08516d 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/get/RestGetAliasesAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/alias/get/RestGetAliasesAction.java @@ -30,7 +30,6 @@ import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; @@ -113,7 +112,7 @@ public class RestGetAliasesAction extends BaseRestHandler { static class Fields { - static final XContentBuilderString ALIASES = new XContentBuilderString("aliases"); + static final String ALIASES = "aliases"; } } diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/get/RestGetIndicesAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/get/RestGetIndicesAction.java index 4c307f4ba0e..f31c17d8b6e 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/get/RestGetIndicesAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/get/RestGetIndicesAction.java @@ -34,7 +34,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.xcontent.ToXContent.Params; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; @@ -155,9 +154,9 @@ public class RestGetIndicesAction extends BaseRestHandler { } static class Fields { - static final XContentBuilderString ALIASES = new XContentBuilderString("aliases"); - static final XContentBuilderString MAPPINGS = new XContentBuilderString("mappings"); - static final XContentBuilderString SETTINGS = new XContentBuilderString("settings"); + static final String ALIASES = "aliases"; + static final String MAPPINGS = "mappings"; + static final String SETTINGS = "settings"; } } diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java index 29012ba86fe..0da54bc4e75 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/mapping/get/RestGetMappingAction.java @@ -30,7 +30,6 @@ import org.elasticsearch.common.collect.ImmutableOpenMap; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexNotFoundException; import org.elasticsearch.indices.TypeMissingException; @@ -105,6 +104,6 @@ public class RestGetMappingAction extends BaseRestHandler { } static class Fields { - static final XContentBuilderString MAPPINGS = new XContentBuilderString("mappings"); + static final String MAPPINGS = "mappings"; } } diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/query/RestValidateQueryAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/query/RestValidateQueryAction.java index c0a209375b0..4ff7234b2ef 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/query/RestValidateQueryAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/validate/query/RestValidateQueryAction.java @@ -29,7 +29,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.rest.BaseRestHandler; @@ -131,9 +130,9 @@ public class RestValidateQueryAction extends BaseRestHandler { return new BytesRestResponse(OK, builder); } - private static final XContentBuilderString INDEX_FIELD = new XContentBuilderString("index"); - private static final XContentBuilderString VALID_FIELD = new XContentBuilderString("valid"); - private static final XContentBuilderString EXPLANATIONS_FIELD = new XContentBuilderString("explanations"); - private static final XContentBuilderString ERROR_FIELD = new XContentBuilderString("error"); - private static final XContentBuilderString EXPLANATION_FIELD = new XContentBuilderString("explanation"); + private static final String INDEX_FIELD = "index"; + private static final String VALID_FIELD = "valid"; + private static final String EXPLANATIONS_FIELD = "explanations"; + private static final String ERROR_FIELD = "error"; + private static final String EXPLANATION_FIELD = "explanation"; } diff --git a/core/src/main/java/org/elasticsearch/rest/action/bulk/RestBulkAction.java b/core/src/main/java/org/elasticsearch/rest/action/bulk/RestBulkAction.java index 4c8d3a85989..620418eb087 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/bulk/RestBulkAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/bulk/RestBulkAction.java @@ -30,7 +30,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; @@ -112,10 +111,10 @@ public class RestBulkAction extends BaseRestHandler { } static final class Fields { - static final XContentBuilderString ITEMS = new XContentBuilderString("items"); - static final XContentBuilderString ERRORS = new XContentBuilderString("errors"); - static final XContentBuilderString TOOK = new XContentBuilderString("took"); - static final XContentBuilderString INGEST_TOOK = new XContentBuilderString("ingest_took"); + static final String ITEMS = "items"; + static final String ERRORS = "errors"; + static final String TOOK = "took"; + static final String INGEST_TOOK = "ingest_took"; } } diff --git a/core/src/main/java/org/elasticsearch/rest/action/explain/RestExplainAction.java b/core/src/main/java/org/elasticsearch/rest/action/explain/RestExplainAction.java index 864cddc4ba0..a1fdc13437c 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/explain/RestExplainAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/explain/RestExplainAction.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.index.get.GetResult; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.indices.query.IndicesQueriesRegistry; @@ -131,15 +130,15 @@ public class RestExplainAction extends BaseRestHandler { } static class Fields { - static final XContentBuilderString _INDEX = new XContentBuilderString("_index"); - static final XContentBuilderString _TYPE = new XContentBuilderString("_type"); - static final XContentBuilderString _ID = new XContentBuilderString("_id"); - static final XContentBuilderString MATCHED = new XContentBuilderString("matched"); - static final XContentBuilderString EXPLANATION = new XContentBuilderString("explanation"); - static final XContentBuilderString VALUE = new XContentBuilderString("value"); - static final XContentBuilderString DESCRIPTION = new XContentBuilderString("description"); - static final XContentBuilderString DETAILS = new XContentBuilderString("details"); - static final XContentBuilderString GET = new XContentBuilderString("get"); + static final String _INDEX = "_index"; + static final String _TYPE = "_type"; + static final String _ID = "_id"; + static final String MATCHED = "matched"; + static final String EXPLANATION = "explanation"; + static final String VALUE = "value"; + static final String DESCRIPTION = "description"; + static final String DETAILS = "details"; + static final String GET = "get"; } } diff --git a/core/src/main/java/org/elasticsearch/rest/action/script/RestDeleteIndexedScriptAction.java b/core/src/main/java/org/elasticsearch/rest/action/script/RestDeleteIndexedScriptAction.java index 9009025d3a9..ce4cb9c057a 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/script/RestDeleteIndexedScriptAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/script/RestDeleteIndexedScriptAction.java @@ -24,7 +24,6 @@ import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.index.VersionType; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; @@ -82,10 +81,10 @@ public class RestDeleteIndexedScriptAction extends BaseRestHandler { } static final class Fields { - static final XContentBuilderString FOUND = new XContentBuilderString("found"); - static final XContentBuilderString _INDEX = new XContentBuilderString("_index"); - static final XContentBuilderString _TYPE = new XContentBuilderString("_type"); - static final XContentBuilderString _ID = new XContentBuilderString("_id"); - static final XContentBuilderString _VERSION = new XContentBuilderString("_version"); + static final String FOUND = "found"; + static final String _INDEX = "_index"; + static final String _TYPE = "_type"; + static final String _ID = "_id"; + static final String _VERSION = "_version"; } } diff --git a/core/src/main/java/org/elasticsearch/rest/action/script/RestGetIndexedScriptAction.java b/core/src/main/java/org/elasticsearch/rest/action/script/RestGetIndexedScriptAction.java index e2c4ff6373d..0ed1c309bc5 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/script/RestGetIndexedScriptAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/script/RestGetIndexedScriptAction.java @@ -24,7 +24,6 @@ import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.index.VersionType; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; @@ -54,7 +53,7 @@ public class RestGetIndexedScriptAction extends BaseRestHandler { } } - protected XContentBuilderString getScriptFieldName() { + protected String getScriptFieldName() { return Fields.SCRIPT; } @@ -87,10 +86,10 @@ public class RestGetIndexedScriptAction extends BaseRestHandler { } private static final class Fields { - private static final XContentBuilderString SCRIPT = new XContentBuilderString("script"); - private static final XContentBuilderString LANG = new XContentBuilderString("lang"); - private static final XContentBuilderString _ID = new XContentBuilderString("_id"); - private static final XContentBuilderString _VERSION = new XContentBuilderString("_version"); - private static final XContentBuilderString FOUND = new XContentBuilderString("found"); + private static final String SCRIPT = "script"; + private static final String LANG = "lang"; + private static final String _ID = "_id"; + private static final String _VERSION = "_version"; + private static final String FOUND = "found"; } } diff --git a/core/src/main/java/org/elasticsearch/rest/action/script/RestPutIndexedScriptAction.java b/core/src/main/java/org/elasticsearch/rest/action/script/RestPutIndexedScriptAction.java index f5a6f67517e..b0f1842d98a 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/script/RestPutIndexedScriptAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/script/RestPutIndexedScriptAction.java @@ -25,7 +25,6 @@ import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.index.VersionType; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; @@ -121,8 +120,8 @@ public class RestPutIndexedScriptAction extends BaseRestHandler { } static final class Fields { - static final XContentBuilderString _VERSION = new XContentBuilderString("_version"); - static final XContentBuilderString _ID = new XContentBuilderString("_id"); - static final XContentBuilderString CREATED = new XContentBuilderString("created"); + static final String _VERSION = "_version"; + static final String _ID = "_id"; + static final String CREATED = "created"; } } diff --git a/core/src/main/java/org/elasticsearch/rest/action/support/AcknowledgedRestListener.java b/core/src/main/java/org/elasticsearch/rest/action/support/AcknowledgedRestListener.java index a59dc3d47b8..2f5223d91df 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/support/AcknowledgedRestListener.java +++ b/core/src/main/java/org/elasticsearch/rest/action/support/AcknowledgedRestListener.java @@ -20,7 +20,6 @@ package org.elasticsearch.rest.action.support; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestResponse; @@ -55,6 +54,6 @@ public class AcknowledgedRestListener extends Re } static final class Fields { - static final XContentBuilderString ACKNOWLEDGED = new XContentBuilderString("acknowledged"); + static final String ACKNOWLEDGED = "acknowledged"; } } diff --git a/core/src/main/java/org/elasticsearch/rest/action/support/RestActions.java b/core/src/main/java/org/elasticsearch/rest/action/support/RestActions.java index 004f67a9dba..9ab523ba1e6 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/support/RestActions.java +++ b/core/src/main/java/org/elasticsearch/rest/action/support/RestActions.java @@ -29,7 +29,6 @@ import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.lucene.uid.Versions; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; @@ -65,11 +64,11 @@ public class RestActions { } static final class Fields { - static final XContentBuilderString _SHARDS = new XContentBuilderString("_shards"); - static final XContentBuilderString TOTAL = new XContentBuilderString("total"); - static final XContentBuilderString SUCCESSFUL = new XContentBuilderString("successful"); - static final XContentBuilderString FAILED = new XContentBuilderString("failed"); - static final XContentBuilderString FAILURES = new XContentBuilderString("failures"); + static final String _SHARDS = "_shards"; + static final String TOTAL = "total"; + static final String SUCCESSFUL = "successful"; + static final String FAILED = "failed"; + static final String FAILURES = "failures"; } public static void buildBroadcastShardsHeader(XContentBuilder builder, ToXContent.Params params, BroadcastResponse response) throws IOException { diff --git a/core/src/main/java/org/elasticsearch/rest/action/template/RestGetSearchTemplateAction.java b/core/src/main/java/org/elasticsearch/rest/action/template/RestGetSearchTemplateAction.java index 0e8aa357fcd..4c25d6166e0 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/template/RestGetSearchTemplateAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/template/RestGetSearchTemplateAction.java @@ -21,7 +21,6 @@ package org.elasticsearch.rest.action.template; import org.elasticsearch.client.Client; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.script.RestGetIndexedScriptAction; @@ -46,9 +45,9 @@ public class RestGetSearchTemplateAction extends RestGetIndexedScriptAction { } @Override - protected XContentBuilderString getScriptFieldName() { + protected String getScriptFieldName() { return TEMPLATE; } - private static final XContentBuilderString TEMPLATE = new XContentBuilderString("template"); + private static final String TEMPLATE = "template"; } diff --git a/core/src/main/java/org/elasticsearch/script/ScriptStats.java b/core/src/main/java/org/elasticsearch/script/ScriptStats.java index 0bad4b27de0..c08d220d572 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptStats.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptStats.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import java.io.IOException; @@ -75,8 +74,8 @@ public class ScriptStats implements Streamable, ToXContent { } static final class Fields { - static final XContentBuilderString SCRIPT_STATS = new XContentBuilderString("script"); - static final XContentBuilderString COMPILATIONS = new XContentBuilderString("compilations"); - static final XContentBuilderString CACHE_EVICTIONS = new XContentBuilderString("cache_evictions"); + static final String SCRIPT_STATS = "script"; + static final String COMPILATIONS = "compilations"; + static final String CACHE_EVICTIONS = "cache_evictions"; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregation.java b/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregation.java index 04b1026446f..744840b2adf 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregation.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregation.java @@ -26,7 +26,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.script.ScriptService; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregator; import org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorStreams; @@ -243,18 +242,18 @@ public abstract class InternalAggregation implements Aggregation, ToXContent, St * Common xcontent fields that are shared among addAggregation */ public static final class CommonFields { - public static final XContentBuilderString META = new XContentBuilderString("meta"); - public static final XContentBuilderString BUCKETS = new XContentBuilderString("buckets"); - public static final XContentBuilderString VALUE = new XContentBuilderString("value"); - public static final XContentBuilderString VALUES = new XContentBuilderString("values"); - public static final XContentBuilderString VALUE_AS_STRING = new XContentBuilderString("value_as_string"); - public static final XContentBuilderString DOC_COUNT = new XContentBuilderString("doc_count"); - public static final XContentBuilderString KEY = new XContentBuilderString("key"); - public static final XContentBuilderString KEY_AS_STRING = new XContentBuilderString("key_as_string"); - public static final XContentBuilderString FROM = new XContentBuilderString("from"); - public static final XContentBuilderString FROM_AS_STRING = new XContentBuilderString("from_as_string"); - public static final XContentBuilderString TO = new XContentBuilderString("to"); - public static final XContentBuilderString TO_AS_STRING = new XContentBuilderString("to_as_string"); + public static final String META = "meta"; + public static final String BUCKETS = "buckets"; + public static final String VALUE = "value"; + public static final String VALUES = "values"; + public static final String VALUE_AS_STRING = "value_as_string"; + public static final String DOC_COUNT = "doc_count"; + public static final String KEY = "key"; + public static final String KEY_AS_STRING = "key_as_string"; + public static final String FROM = "from"; + public static final String FROM_AS_STRING = "from_as_string"; + public static final String TO = "to"; + public static final String TO_AS_STRING = "to_as_string"; } } diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregations.java b/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregations.java index 9b23997b6d4..357886a69f6 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregations.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/InternalAggregations.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.search.aggregations.InternalAggregation.ReduceContext; import org.elasticsearch.search.aggregations.support.AggregationPath; @@ -164,7 +163,7 @@ public class InternalAggregations implements Aggregations, ToXContent, Streamabl /** The fields required to write this addAggregation to xcontent */ static class Fields { - public static final XContentBuilderString AGGREGATIONS = new XContentBuilderString("aggregations"); + public static final String AGGREGATIONS = "aggregations"; } @Override diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/InternalGeoCentroid.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/InternalGeoCentroid.java index 77d357352af..2798169b699 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/InternalGeoCentroid.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/geocentroid/InternalGeoCentroid.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.geo.GeoPoint; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.search.aggregations.AggregationStreams; import org.elasticsearch.search.aggregations.InternalAggregation; import org.elasticsearch.search.aggregations.metrics.InternalMetricsAggregation; @@ -147,7 +146,7 @@ public class InternalGeoCentroid extends InternalMetricsAggregation implements G } static class Fields { - public static final XContentBuilderString CENTROID = new XContentBuilderString("location"); + public static final String CENTROID = "location"; } @Override diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/InternalStats.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/InternalStats.java index ce8a492f3a3..6b98201898b 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/InternalStats.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/InternalStats.java @@ -21,7 +21,6 @@ package org.elasticsearch.search.aggregations.metrics.stats; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AggregationStreams; import org.elasticsearch.search.aggregations.InternalAggregation; @@ -191,15 +190,15 @@ public class InternalStats extends InternalNumericMetricsAggregation.MultiValue } static class Fields { - public static final XContentBuilderString COUNT = new XContentBuilderString("count"); - public static final XContentBuilderString MIN = new XContentBuilderString("min"); - public static final XContentBuilderString MIN_AS_STRING = new XContentBuilderString("min_as_string"); - public static final XContentBuilderString MAX = new XContentBuilderString("max"); - public static final XContentBuilderString MAX_AS_STRING = new XContentBuilderString("max_as_string"); - public static final XContentBuilderString AVG = new XContentBuilderString("avg"); - public static final XContentBuilderString AVG_AS_STRING = new XContentBuilderString("avg_as_string"); - public static final XContentBuilderString SUM = new XContentBuilderString("sum"); - public static final XContentBuilderString SUM_AS_STRING = new XContentBuilderString("sum_as_string"); + public static final String COUNT = "count"; + public static final String MIN = "min"; + public static final String MIN_AS_STRING = "min_as_string"; + public static final String MAX = "max"; + public static final String MAX_AS_STRING = "max_as_string"; + public static final String AVG = "avg"; + public static final String AVG_AS_STRING = "avg_as_string"; + public static final String SUM = "sum"; + public static final String SUM_AS_STRING = "sum_as_string"; } @Override diff --git a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/InternalExtendedStats.java b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/InternalExtendedStats.java index d2cb2fb8a51..eff72797b58 100644 --- a/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/InternalExtendedStats.java +++ b/core/src/main/java/org/elasticsearch/search/aggregations/metrics/stats/extended/InternalExtendedStats.java @@ -22,7 +22,6 @@ import org.elasticsearch.Version; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.search.DocValueFormat; import org.elasticsearch.search.aggregations.AggregationStreams; import org.elasticsearch.search.aggregations.InternalAggregation; @@ -172,16 +171,16 @@ public class InternalExtendedStats extends InternalStats implements ExtendedStat static class Fields { - public static final XContentBuilderString SUM_OF_SQRS = new XContentBuilderString("sum_of_squares"); - public static final XContentBuilderString SUM_OF_SQRS_AS_STRING = new XContentBuilderString("sum_of_squares_as_string"); - public static final XContentBuilderString VARIANCE = new XContentBuilderString("variance"); - public static final XContentBuilderString VARIANCE_AS_STRING = new XContentBuilderString("variance_as_string"); - public static final XContentBuilderString STD_DEVIATION = new XContentBuilderString("std_deviation"); - public static final XContentBuilderString STD_DEVIATION_AS_STRING = new XContentBuilderString("std_deviation_as_string"); - public static final XContentBuilderString STD_DEVIATION_BOUNDS = new XContentBuilderString("std_deviation_bounds"); - public static final XContentBuilderString STD_DEVIATION_BOUNDS_AS_STRING = new XContentBuilderString("std_deviation_bounds_as_string"); - public static final XContentBuilderString UPPER = new XContentBuilderString("upper"); - public static final XContentBuilderString LOWER = new XContentBuilderString("lower"); + public static final String SUM_OF_SQRS = "sum_of_squares"; + public static final String SUM_OF_SQRS_AS_STRING = "sum_of_squares_as_string"; + public static final String VARIANCE = "variance"; + public static final String VARIANCE_AS_STRING = "variance_as_string"; + public static final String STD_DEVIATION = "std_deviation"; + public static final String STD_DEVIATION_AS_STRING = "std_deviation_as_string"; + public static final String STD_DEVIATION_BOUNDS = "std_deviation_bounds"; + public static final String STD_DEVIATION_BOUNDS_AS_STRING = "std_deviation_bounds_as_string"; + public static final String UPPER = "upper"; + public static final String LOWER = "lower"; } diff --git a/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java b/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java index 4d232f507fa..628f409974e 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java +++ b/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHit.java @@ -33,7 +33,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.text.Text; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHitField; @@ -407,20 +406,20 @@ public class InternalSearchHit implements SearchHit { } public static class Fields { - static final XContentBuilderString _INDEX = new XContentBuilderString("_index"); - static final XContentBuilderString _TYPE = new XContentBuilderString("_type"); - static final XContentBuilderString _ID = new XContentBuilderString("_id"); - static final XContentBuilderString _VERSION = new XContentBuilderString("_version"); - static final XContentBuilderString _SCORE = new XContentBuilderString("_score"); - static final XContentBuilderString FIELDS = new XContentBuilderString("fields"); - static final XContentBuilderString HIGHLIGHT = new XContentBuilderString("highlight"); - static final XContentBuilderString SORT = new XContentBuilderString("sort"); - static final XContentBuilderString MATCHED_QUERIES = new XContentBuilderString("matched_queries"); - static final XContentBuilderString _EXPLANATION = new XContentBuilderString("_explanation"); - static final XContentBuilderString VALUE = new XContentBuilderString("value"); - static final XContentBuilderString DESCRIPTION = new XContentBuilderString("description"); - static final XContentBuilderString DETAILS = new XContentBuilderString("details"); - static final XContentBuilderString INNER_HITS = new XContentBuilderString("inner_hits"); + static final String _INDEX = "_index"; + static final String _TYPE = "_type"; + static final String _ID = "_id"; + static final String _VERSION = "_version"; + static final String _SCORE = "_score"; + static final String FIELDS = "fields"; + static final String HIGHLIGHT = "highlight"; + static final String SORT = "sort"; + static final String MATCHED_QUERIES = "matched_queries"; + static final String _EXPLANATION = "_explanation"; + static final String VALUE = "value"; + static final String DESCRIPTION = "description"; + static final String DETAILS = "details"; + static final String INNER_HITS = "inner_hits"; } @Override @@ -836,9 +835,9 @@ public class InternalSearchHit implements SearchHit { public static class Fields { - static final XContentBuilderString _NESTED = new XContentBuilderString("_nested"); - static final XContentBuilderString _NESTED_FIELD = new XContentBuilderString("field"); - static final XContentBuilderString _NESTED_OFFSET = new XContentBuilderString("offset"); + static final String _NESTED = "_nested"; + static final String _NESTED_FIELD = "field"; + static final String _NESTED_OFFSET = "offset"; } } diff --git a/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java b/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java index 09d11e1a1a3..592d4b0751e 100644 --- a/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java +++ b/core/src/main/java/org/elasticsearch/search/internal/InternalSearchHits.java @@ -23,7 +23,6 @@ import com.carrotsearch.hppc.IntObjectHashMap; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHits; import org.elasticsearch.search.SearchShardTarget; @@ -163,9 +162,9 @@ public class InternalSearchHits implements SearchHits { } static final class Fields { - static final XContentBuilderString HITS = new XContentBuilderString("hits"); - static final XContentBuilderString TOTAL = new XContentBuilderString("total"); - static final XContentBuilderString MAX_SCORE = new XContentBuilderString("max_score"); + static final String HITS = "hits"; + static final String TOTAL = "total"; + static final String MAX_SCORE = "max_score"; } @Override diff --git a/core/src/main/java/org/elasticsearch/search/suggest/Suggest.java b/core/src/main/java/org/elasticsearch/search/suggest/Suggest.java index 926ebaf35b0..35f70abf2cc 100644 --- a/core/src/main/java/org/elasticsearch/search/suggest/Suggest.java +++ b/core/src/main/java/org/elasticsearch/search/suggest/Suggest.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.text.Text; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry; import org.elasticsearch.search.suggest.Suggest.Suggestion.Entry.Option; @@ -47,7 +46,7 @@ import java.util.Map; */ public class Suggest implements Iterable>>, Streamable, ToXContent { - private static final XContentBuilderString NAME = new XContentBuilderString("suggest"); + private static final String NAME = "suggest"; private static final Comparator
    * */ -public final class ThreadContext implements Closeable, Writeable{ +public final class ThreadContext implements Closeable, Writeable { public static final String PREFIX = "request.headers"; public static final Setting DEFAULT_HEADERS_SETTING = Setting.groupSetting(PREFIX + ".", Property.NodeScope); @@ -132,19 +132,13 @@ public final class ThreadContext implements Closeable, Writeablenull if not present */ @@ -239,7 +233,7 @@ public final class ThreadContext implements Closeable, Writeable { + static final class ThreadContextStruct { private final Map headers; private final Map transientHeaders; @@ -309,17 +303,7 @@ public final class ThreadContext implements Closeable, Writeable defaultHeaders) throws IOException { + private void writeTo(StreamOutput out, Map defaultHeaders) throws IOException { final Map headers; if (defaultHeaders.isEmpty()) { headers = this.headers; diff --git a/core/src/test/java/org/elasticsearch/common/io/stream/BytesStreamsTests.java b/core/src/test/java/org/elasticsearch/common/io/stream/BytesStreamsTests.java index 7e4dd4f4e19..071ed5a7c66 100644 --- a/core/src/test/java/org/elasticsearch/common/io/stream/BytesStreamsTests.java +++ b/core/src/test/java/org/elasticsearch/common/io/stream/BytesStreamsTests.java @@ -367,11 +367,6 @@ public class BytesStreamsTests extends ESTestCase { @Override public void writeTo(StreamOutput out) throws IOException { } - - @Override - public Object readFrom(StreamInput in) throws IOException { - return null; - } }); StreamInput in = new NamedWriteableAwareStreamInput(StreamInput.wrap(out.bytes().toBytes()), namedWriteableRegistry); try { From 80288ad60c0c608634fbf9e70cfc5a6a7d21d04e Mon Sep 17 00:00:00 2001 From: Zachary Tong Date: Wed, 20 Apr 2016 16:10:56 -0400 Subject: [PATCH 109/561] Add `fingerprint` token filter and `fingerprint` analyzer Adds a `fingerprint` token filter which uses Lucene's FingerprintFilter, and a `fingerprint` analyzer that combines the Fingerprint filter with lowercasing, stop word removal and asciifolding. Closes #13325 --- .../ASCIIFoldingTokenFilterFactory.java | 6 +- .../index/analysis/AnalysisRegistry.java | 2 + .../index/analysis/FingerprintAnalyzer.java | 56 +++++++++++++++ .../analysis/FingerprintAnalyzerProvider.java | 60 ++++++++++++++++ .../FingerprintTokenFilterFactory.java | 69 +++++++++++++++++++ .../analysis/FingerprintAnalyzerTests.java | 68 ++++++++++++++++++ docs/reference/analysis/analyzers.asciidoc | 2 + .../analyzers/fingerprint-analyzer.asciidoc | 41 +++++++++++ docs/reference/analysis/tokenfilters.asciidoc | 2 + .../fingerprint-tokenfilter.asciidoc | 28 ++++++++ 10 files changed, 333 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/org/elasticsearch/index/analysis/FingerprintAnalyzer.java create mode 100644 core/src/main/java/org/elasticsearch/index/analysis/FingerprintAnalyzerProvider.java create mode 100644 core/src/main/java/org/elasticsearch/index/analysis/FingerprintTokenFilterFactory.java create mode 100644 core/src/test/java/org/elasticsearch/index/analysis/FingerprintAnalyzerTests.java create mode 100644 docs/reference/analysis/analyzers/fingerprint-analyzer.asciidoc create mode 100644 docs/reference/analysis/tokenfilters/fingerprint-tokenfilter.asciidoc diff --git a/core/src/main/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactory.java index 4638a37de17..2e6ba6377a9 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactory.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/ASCIIFoldingTokenFilterFactory.java @@ -21,6 +21,7 @@ package org.elasticsearch.index.analysis; import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilter; +import org.elasticsearch.common.ParseField; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; import org.elasticsearch.index.IndexSettings; @@ -29,11 +30,14 @@ import org.elasticsearch.index.IndexSettings; * Factory for ASCIIFoldingFilter. */ public class ASCIIFoldingTokenFilterFactory extends AbstractTokenFilterFactory { + public static ParseField PRESERVE_ORIGINAL = new ParseField("preserve_original"); + public static boolean DEFAULT_PRESERVE_ORIGINAL = false; + private final boolean preserveOriginal; public ASCIIFoldingTokenFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) { super(indexSettings, name, settings); - preserveOriginal = settings.getAsBoolean("preserve_original", false); + preserveOriginal = settings.getAsBoolean(PRESERVE_ORIGINAL.getPreferredName(), DEFAULT_PRESERVE_ORIGINAL); } @Override diff --git a/core/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java b/core/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java index 3c2d6bfb260..0f90760c771 100644 --- a/core/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java +++ b/core/src/main/java/org/elasticsearch/index/analysis/AnalysisRegistry.java @@ -258,6 +258,7 @@ public final class AnalysisRegistry implements Closeable { tokenFilters.put("apostrophe", ApostropheFilterFactory::new); tokenFilters.put("classic", ClassicFilterFactory::new); tokenFilters.put("decimal_digit", DecimalDigitFilterFactory::new); + tokenFilters.put("fingerprint", FingerprintTokenFilterFactory::new); } private void registerBuiltInAnalyzer(Map> analyzers) { @@ -304,6 +305,7 @@ public final class AnalysisRegistry implements Closeable { analyzers.put("swedish", SwedishAnalyzerProvider::new); analyzers.put("turkish", TurkishAnalyzerProvider::new); analyzers.put("thai", ThaiAnalyzerProvider::new); + analyzers.put("fingerprint", FingerprintAnalyzerProvider::new); } private Map buildMapping(boolean analyzer, String toBuild, IndexSettings settings, Map settingsMap, Map> providerMap, Map> defaultInstance) throws IOException { diff --git a/core/src/main/java/org/elasticsearch/index/analysis/FingerprintAnalyzer.java b/core/src/main/java/org/elasticsearch/index/analysis/FingerprintAnalyzer.java new file mode 100644 index 00000000000..66fdbeaeb39 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/index/analysis/FingerprintAnalyzer.java @@ -0,0 +1,56 @@ +/* + * 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.index.analysis; + +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.TokenStream; +import org.apache.lucene.analysis.Tokenizer; +import org.apache.lucene.analysis.core.LowerCaseFilter; +import org.apache.lucene.analysis.core.StopFilter; +import org.apache.lucene.analysis.miscellaneous.ASCIIFoldingFilter; +import org.apache.lucene.analysis.miscellaneous.FingerprintFilter; +import org.apache.lucene.analysis.standard.StandardTokenizer; +import org.apache.lucene.analysis.util.CharArraySet; + +/** OpenRefine Fingerprinting, which uses a Standard tokenizer and lowercase + stop + fingerprint + asciifolding filters */ +public final class FingerprintAnalyzer extends Analyzer { + private final char separator; + private final int maxOutputSize; + private final boolean preserveOriginal; + private final CharArraySet stopWords; + + public FingerprintAnalyzer(CharArraySet stopWords, char separator, int maxOutputSize, boolean preserveOriginal) { + this.separator = separator; + this.maxOutputSize = maxOutputSize; + this.preserveOriginal = preserveOriginal; + this.stopWords = stopWords; + } + + @Override + protected TokenStreamComponents createComponents(String s) { + final Tokenizer tokenizer = new StandardTokenizer(); + TokenStream stream = tokenizer; + stream = new LowerCaseFilter(stream); + stream = new StopFilter(stream, stopWords); + stream = new FingerprintFilter(stream, maxOutputSize, separator); + stream = new ASCIIFoldingFilter(stream, preserveOriginal); + return new TokenStreamComponents(tokenizer, stream); + } +} diff --git a/core/src/main/java/org/elasticsearch/index/analysis/FingerprintAnalyzerProvider.java b/core/src/main/java/org/elasticsearch/index/analysis/FingerprintAnalyzerProvider.java new file mode 100644 index 00000000000..897068cbf8b --- /dev/null +++ b/core/src/main/java/org/elasticsearch/index/analysis/FingerprintAnalyzerProvider.java @@ -0,0 +1,60 @@ +/* + * 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.index.analysis; + +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.util.CharArraySet; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; +import org.elasticsearch.index.IndexSettings; + + +/** + * Builds an OpenRefine Fingerprint analyzer. Uses the default settings from the various components + * (Standard Tokenizer and lowercase + stop + fingerprint + ascii-folding filters) + */ +public class FingerprintAnalyzerProvider extends AbstractIndexAnalyzerProvider { + + public static ParseField MAX_OUTPUT_SIZE = FingerprintTokenFilterFactory.MAX_OUTPUT_SIZE; + public static ParseField PRESERVE_ORIGINAL = ASCIIFoldingTokenFilterFactory.PRESERVE_ORIGINAL; + + public static int DEFAULT_MAX_OUTPUT_SIZE = FingerprintTokenFilterFactory.DEFAULT_MAX_OUTPUT_SIZE; + public static boolean DEFAULT_PRESERVE_ORIGINAL = ASCIIFoldingTokenFilterFactory.DEFAULT_PRESERVE_ORIGINAL; + public static CharArraySet DEFAULT_STOP_WORDS = CharArraySet.EMPTY_SET; + + private final FingerprintAnalyzer analyzer; + + public FingerprintAnalyzerProvider(IndexSettings indexSettings, Environment env, String name, Settings settings) { + super(indexSettings, name, settings); + + char separator = FingerprintTokenFilterFactory.parseSeparator(settings); + int maxOutputSize = settings.getAsInt(MAX_OUTPUT_SIZE.getPreferredName(),DEFAULT_MAX_OUTPUT_SIZE); + boolean preserveOriginal = settings.getAsBoolean(PRESERVE_ORIGINAL.getPreferredName(), DEFAULT_PRESERVE_ORIGINAL); + CharArraySet stopWords = Analysis.parseStopWords(env, settings, DEFAULT_STOP_WORDS); + + this.analyzer = new FingerprintAnalyzer(stopWords, separator, maxOutputSize, preserveOriginal); + } + + @Override + public FingerprintAnalyzer get() { + return analyzer; + } +} diff --git a/core/src/main/java/org/elasticsearch/index/analysis/FingerprintTokenFilterFactory.java b/core/src/main/java/org/elasticsearch/index/analysis/FingerprintTokenFilterFactory.java new file mode 100644 index 00000000000..9d41044abf7 --- /dev/null +++ b/core/src/main/java/org/elasticsearch/index/analysis/FingerprintTokenFilterFactory.java @@ -0,0 +1,69 @@ +/* + * 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.index.analysis; + +import org.apache.lucene.analysis.TokenStream; +import org.apache.lucene.analysis.miscellaneous.FingerprintFilter; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.env.Environment; +import org.elasticsearch.index.IndexSettings; + + +/** + * + */ +public class FingerprintTokenFilterFactory extends AbstractTokenFilterFactory { + + private final char separator; + private final int maxOutputSize; + + public static ParseField SEPARATOR = new ParseField("separator"); + public static ParseField MAX_OUTPUT_SIZE = new ParseField("max_output_size"); + + public static final char DEFAULT_SEPARATOR = ' '; + public static final int DEFAULT_MAX_OUTPUT_SIZE = 255; + + public FingerprintTokenFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) { + super(indexSettings, name, settings); + this.separator = parseSeparator(settings); + this.maxOutputSize = settings.getAsInt(MAX_OUTPUT_SIZE.getPreferredName(), + FingerprintTokenFilterFactory.DEFAULT_MAX_OUTPUT_SIZE); + } + + @Override + public TokenStream create(TokenStream tokenStream) { + TokenStream result = tokenStream; + result = new FingerprintFilter(result, maxOutputSize, separator); + return result; + } + + public static char parseSeparator(Settings settings) throws IllegalArgumentException { + String customSeparator = settings.get(SEPARATOR.getPreferredName()); + if (customSeparator == null) { + return FingerprintTokenFilterFactory.DEFAULT_SEPARATOR; + } else if (customSeparator.length() == 1) { + return customSeparator.charAt(0); + } + + throw new IllegalArgumentException("Setting [separator] must be a single, non-null character. [" + + customSeparator + "] was provided."); + } +} diff --git a/core/src/test/java/org/elasticsearch/index/analysis/FingerprintAnalyzerTests.java b/core/src/test/java/org/elasticsearch/index/analysis/FingerprintAnalyzerTests.java new file mode 100644 index 00000000000..0e4ed8f4fb7 --- /dev/null +++ b/core/src/test/java/org/elasticsearch/index/analysis/FingerprintAnalyzerTests.java @@ -0,0 +1,68 @@ +package org.elasticsearch.index.analysis; + +/* + * 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. + */ + +import org.apache.lucene.analysis.Analyzer; +import org.apache.lucene.analysis.util.CharArraySet; +import org.elasticsearch.test.ESTokenStreamTestCase; + +public class FingerprintAnalyzerTests extends ESTokenStreamTestCase { + + public void testFingerprint() throws Exception { + Analyzer a = new FingerprintAnalyzer(CharArraySet.EMPTY_SET, ' ', 255, false); + assertAnalyzesTo(a, "foo bar@baz Baz $ foo foo FOO. FoO", + new String[]{"bar baz foo"}); + } + + public void testReusableTokenStream() throws Exception { + Analyzer a = new FingerprintAnalyzer(CharArraySet.EMPTY_SET, ' ', 255, false); + assertAnalyzesTo(a, "foo bar baz Baz foo foo FOO. FoO", + new String[]{"bar baz foo"}); + assertAnalyzesTo(a, "xyz XYZ abc 123.2 abc", + new String[]{"123.2 abc xyz"}); + } + + public void testAsciifolding() throws Exception { + Analyzer a = new FingerprintAnalyzer(CharArraySet.EMPTY_SET, ' ', 255, false); + assertAnalyzesTo(a, "gödel escher bach", + new String[]{"bach escher godel"}); + } + + public void testPreserveOriginal() throws Exception { + Analyzer a = new FingerprintAnalyzer(CharArraySet.EMPTY_SET, ' ', 255, true); + assertAnalyzesTo(a, "gödel escher bach", + new String[]{"bach escher godel", "bach escher gödel"}); + } + + public void testLimit() throws Exception { + Analyzer a = new FingerprintAnalyzer(CharArraySet.EMPTY_SET, ' ', 3, false); + assertAnalyzesTo(a, "e d c b a", + new String[]{}); + + assertAnalyzesTo(a, "b a", + new String[]{"a b"}); + } + + public void testSeparator() throws Exception { + Analyzer a = new FingerprintAnalyzer(CharArraySet.EMPTY_SET, '_', 255, true); + assertAnalyzesTo(a, "b c a", + new String[]{"a_b_c"}); + } +} diff --git a/docs/reference/analysis/analyzers.asciidoc b/docs/reference/analysis/analyzers.asciidoc index 91e83b9a6b9..e062a179b96 100644 --- a/docs/reference/analysis/analyzers.asciidoc +++ b/docs/reference/analysis/analyzers.asciidoc @@ -79,5 +79,7 @@ include::analyzers/lang-analyzer.asciidoc[] include::analyzers/snowball-analyzer.asciidoc[] +include::analyzers/fingerprint-analyzer.asciidoc[] + include::analyzers/custom-analyzer.asciidoc[] diff --git a/docs/reference/analysis/analyzers/fingerprint-analyzer.asciidoc b/docs/reference/analysis/analyzers/fingerprint-analyzer.asciidoc new file mode 100644 index 00000000000..e0850077555 --- /dev/null +++ b/docs/reference/analysis/analyzers/fingerprint-analyzer.asciidoc @@ -0,0 +1,41 @@ +[[analysis-fingerprint-analyzer]] +=== Fingerprint Analyzer + +The `fingerprint` analyzer implements a +https://github.com/OpenRefine/OpenRefine/wiki/Clustering-In-Depth#fingerprint[fingerprinting algorithm] +which is used by the OpenRefine project to assist in clustering. + +The `fingerprint` analyzer is composed of a <>, and four +token filters (in this order): <>, <>, +<> and <>. + +Input text is lowercased, normalized to remove extended characters, sorted, deduplicated and +concatenated into a single token. If a stopword list is configured, stop words will +also be removed. For example, the sentence: + +____ +"Yes yes, Gödel said this sentence is consistent and." +____ + +will be transformed into the token: `"and consistent godel is said sentence this yes"` + + +Notice how the words are all lowercased, the umlaut in "gödel" has been normalized to "godel", +punctuation has been removed, and "yes" has been de-duplicated. + +The `fingerprint` analyzer has these configurable settings + +[cols="<,<",options="header",] +|======================================================================= +|Setting |Description +|`separator` | The character that separates the tokens after concatenation. +Defaults to a space. +|`max_output_size` | The maximum token size to emit. Defaults to `255`. See <> +|`preserve_original`| If true, emits both the original and folded version of + tokens that contain extended characters. Defaults to `false` +|`stopwords` | A list of stop words to use. Defaults to an empty list (`_none_`). +|`stopwords_path` | A path (either relative to `config` location, or absolute) to a stopwords + file configuration. Each stop word should be in its own "line" (separated + by a line break). The file must be UTF-8 encoded. +|======================================================================= + diff --git a/docs/reference/analysis/tokenfilters.asciidoc b/docs/reference/analysis/tokenfilters.asciidoc index ba460465e49..15a911b8ed9 100644 --- a/docs/reference/analysis/tokenfilters.asciidoc +++ b/docs/reference/analysis/tokenfilters.asciidoc @@ -86,3 +86,5 @@ include::tokenfilters/classic-tokenfilter.asciidoc[] include::tokenfilters/apostrophe-tokenfilter.asciidoc[] include::tokenfilters/decimal-digit-tokenfilter.asciidoc[] + +include::tokenfilters/fingerprint-tokenfilter.asciidoc[] \ No newline at end of file diff --git a/docs/reference/analysis/tokenfilters/fingerprint-tokenfilter.asciidoc b/docs/reference/analysis/tokenfilters/fingerprint-tokenfilter.asciidoc new file mode 100644 index 00000000000..6d90d72ecf0 --- /dev/null +++ b/docs/reference/analysis/tokenfilters/fingerprint-tokenfilter.asciidoc @@ -0,0 +1,28 @@ +[[analysis-fingerprint-tokenfilter]] +=== Fingerprint Token Filter + +The `fingerprint` token filter emits a single token which is useful for fingerprinting +a body of text, and/or providing a token that can be clustered on. It does this by +sorting the tokens, deduplicating and then concatenating them back into a single token. + +For example, the tokens `["the", "quick", "quick", "brown", "fox", "was", "very", "brown"]` will be +transformed into a single token: `"brown fox quick the very was"`. Notice how the tokens were sorted +alphabetically, and there is only one `"quick"`. + +The following are settings that can be set for a `fingerprint` token +filter type: + +[cols="<,<",options="header",] +|====================================================== +|Setting |Description +|`separator` |Defaults to a space. +|`max_output_size` |Defaults to `255`. +|====================================================== + +[[analysis-fingerprint-tokenfilter-max-size]] +==== Maximum token size + +Because a field may have many unique tokens, it is important to set a cutoff so that fields do not grow +too large. The `max_output_size` setting controls this behavior. If the concatenated fingerprint +grows larger than `max_output_size`, the token filter will exit and will not emit a token (e.g. the +field will be empty). From a6c0a813b5b820f81cd89e7e7f3c2be7135832f8 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 20 Apr 2016 16:57:56 -0400 Subject: [PATCH 110/561] Remove readFrom from ingest It isn't needed and will be removed from the interface declaring it. Relates to #17085 --- .../ingest/SimulateProcessorResult.java | 54 +++++++-------- .../org/elasticsearch/ingest/IngestStats.java | 69 +++++++++---------- .../ingest/PipelineConfiguration.java | 4 +- .../elasticsearch/ingest/core/IngestInfo.java | 40 +++++------ .../ingest/core/ProcessorInfo.java | 23 +++---- .../ingest/IngestStatsTests.java | 7 +- 6 files changed, 90 insertions(+), 107 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/ingest/SimulateProcessorResult.java b/core/src/main/java/org/elasticsearch/action/ingest/SimulateProcessorResult.java index 6a38434d4c0..ad915eaadab 100644 --- a/core/src/main/java/org/elasticsearch/action/ingest/SimulateProcessorResult.java +++ b/core/src/main/java/org/elasticsearch/action/ingest/SimulateProcessorResult.java @@ -34,17 +34,6 @@ public class SimulateProcessorResult implements Writeable, ToXContent { private final Stats totalStats; private final Map statsPerPipeline; + public IngestStats(Stats totalStats, Map statsPerPipeline) { + this.totalStats = totalStats; + this.statsPerPipeline = statsPerPipeline; + } + + /** + * Read from a stream. + */ public IngestStats(StreamInput in) throws IOException { this.totalStats = new Stats(in); int size = in.readVInt(); @@ -43,11 +51,17 @@ public class IngestStats implements Writeable, ToXContent { } } - public IngestStats(Stats totalStats, Map statsPerPipeline) { - this.totalStats = totalStats; - this.statsPerPipeline = statsPerPipeline; + @Override + public void writeTo(StreamOutput out) throws IOException { + totalStats.writeTo(out); + out.writeVLong(statsPerPipeline.size()); + for (Map.Entry entry : statsPerPipeline.entrySet()) { + out.writeString(entry.getKey()); + entry.getValue().writeTo(out); + } } + /** * @return The accumulated stats for all pipelines */ @@ -62,21 +76,6 @@ public class IngestStats implements Writeable, ToXContent { return statsPerPipeline; } - @Override - public IngestStats readFrom(StreamInput in) throws IOException { - return new IngestStats(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - totalStats.writeTo(out); - out.writeVLong(statsPerPipeline.size()); - for (Map.Entry entry : statsPerPipeline.entrySet()) { - out.writeString(entry.getKey()); - entry.getValue().writeTo(out); - } - } - @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject("ingest"); @@ -101,6 +100,16 @@ public class IngestStats implements Writeable, ToXContent { private final long ingestCurrent; private final long ingestFailedCount; + public Stats(long ingestCount, long ingestTimeInMillis, long ingestCurrent, long ingestFailedCount) { + this.ingestCount = ingestCount; + this.ingestTimeInMillis = ingestTimeInMillis; + this.ingestCurrent = ingestCurrent; + this.ingestFailedCount = ingestFailedCount; + } + + /** + * Read from a stream. + */ public Stats(StreamInput in) throws IOException { ingestCount = in.readVLong(); ingestTimeInMillis = in.readVLong(); @@ -108,11 +117,12 @@ public class IngestStats implements Writeable, ToXContent { ingestFailedCount = in.readVLong(); } - public Stats(long ingestCount, long ingestTimeInMillis, long ingestCurrent, long ingestFailedCount) { - this.ingestCount = ingestCount; - this.ingestTimeInMillis = ingestTimeInMillis; - this.ingestCurrent = ingestCurrent; - this.ingestFailedCount = ingestFailedCount; + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeVLong(ingestCount); + out.writeVLong(ingestTimeInMillis); + out.writeVLong(ingestCurrent); + out.writeVLong(ingestFailedCount); } /** @@ -144,19 +154,6 @@ public class IngestStats implements Writeable, ToXContent { return ingestFailedCount; } - @Override - public Stats readFrom(StreamInput in) throws IOException { - return new Stats(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeVLong(ingestCount); - out.writeVLong(ingestTimeInMillis); - out.writeVLong(ingestCurrent); - out.writeVLong(ingestFailedCount); - } - @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field("count", ingestCount); diff --git a/core/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java b/core/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java index 6272eee1cbf..a6bff3ff5cb 100644 --- a/core/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java +++ b/core/src/main/java/org/elasticsearch/ingest/PipelineConfiguration.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.ParseFieldMatcherSupplier; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -39,8 +38,7 @@ import java.util.function.BiFunction; /** * Encapsulates a pipeline's id and configuration as a blob */ -public final class PipelineConfiguration extends AbstractDiffable - implements Writeable, ToXContent { +public final class PipelineConfiguration extends AbstractDiffable implements ToXContent { final static PipelineConfiguration PROTOTYPE = new PipelineConfiguration(null, null); diff --git a/core/src/main/java/org/elasticsearch/ingest/core/IngestInfo.java b/core/src/main/java/org/elasticsearch/ingest/core/IngestInfo.java index d128732203f..efa425c9497 100644 --- a/core/src/main/java/org/elasticsearch/ingest/core/IngestInfo.java +++ b/core/src/main/java/org/elasticsearch/ingest/core/IngestInfo.java @@ -21,15 +21,11 @@ package org.elasticsearch.ingest.core; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.LinkedHashSet; import java.util.List; import java.util.Objects; import java.util.Set; @@ -39,29 +35,19 @@ public class IngestInfo implements Writeable, ToXContent { private final Set processors; - public IngestInfo(StreamInput in) throws IOException { - this(Collections.emptyList()); - final int size = in.readVInt(); - for (int i = 0; i < size; i++) { - processors.add(new ProcessorInfo(in)); - } - } - public IngestInfo(List processors) { this.processors = new TreeSet<>(processors); // we use a treeset here to have a test-able / predictable order } - public Iterable getProcessors() { - return processors; - } - - public boolean containsProcessor(String type) { - return processors.contains(new ProcessorInfo(type)); - } - - @Override - public IngestInfo readFrom(StreamInput in) throws IOException { - return new IngestInfo(in); + /** + * Read from a stream. + */ + public IngestInfo(StreamInput in) throws IOException { + processors = new TreeSet<>(); + final int size = in.readVInt(); + for (int i = 0; i < size; i++) { + processors.add(new ProcessorInfo(in)); + } } @Override @@ -72,6 +58,14 @@ public class IngestInfo implements Writeable, ToXContent { } } + public Iterable getProcessors() { + return processors; + } + + public boolean containsProcessor(String type) { + return processors.contains(new ProcessorInfo(type)); + } + @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject("ingest"); diff --git a/core/src/main/java/org/elasticsearch/ingest/core/ProcessorInfo.java b/core/src/main/java/org/elasticsearch/ingest/core/ProcessorInfo.java index f652b182919..984123427d9 100644 --- a/core/src/main/java/org/elasticsearch/ingest/core/ProcessorInfo.java +++ b/core/src/main/java/org/elasticsearch/ingest/core/ProcessorInfo.java @@ -21,7 +21,6 @@ package org.elasticsearch.ingest.core; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -32,12 +31,20 @@ public class ProcessorInfo implements Writeable, ToXContent, Comp private final String type; + public ProcessorInfo(String type) { + this.type = type; + } + + /** + * Read from a stream. + */ public ProcessorInfo(StreamInput input) throws IOException { type = input.readString(); } - public ProcessorInfo(String type) { - this.type = type; + @Override + public void writeTo(StreamOutput out) throws IOException { + out.writeString(this.type); } /** @@ -47,16 +54,6 @@ public class ProcessorInfo implements Writeable, ToXContent, Comp return type; } - @Override - public ProcessorInfo readFrom(StreamInput in) throws IOException { - return new ProcessorInfo(in); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - out.writeString(this.type); - } - @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); diff --git a/core/src/test/java/org/elasticsearch/ingest/IngestStatsTests.java b/core/src/test/java/org/elasticsearch/ingest/IngestStatsTests.java index e7064b7e449..119e94580ad 100644 --- a/core/src/test/java/org/elasticsearch/ingest/IngestStatsTests.java +++ b/core/src/test/java/org/elasticsearch/ingest/IngestStatsTests.java @@ -21,7 +21,6 @@ package org.elasticsearch.ingest; import org.elasticsearch.common.io.stream.BytesStreamOutput; import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.test.ESTestCase; import java.io.IOException; @@ -60,10 +59,10 @@ public class IngestStatsTests extends ESTestCase { assertEquals(leftStats.getIngestCurrent(), rightStats.getIngestCurrent()); } - private T serialize(Writeable writeable) throws IOException { + private IngestStats serialize(IngestStats stats) throws IOException { BytesStreamOutput out = new BytesStreamOutput(); - writeable.writeTo(out); + stats.writeTo(out); StreamInput in = StreamInput.wrap(out.bytes()); - return writeable.readFrom(in); + return new IngestStats(in); } } From 5e04bde791094d5cf66ae701843baf4f81c1413b Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Wed, 20 Apr 2016 16:06:19 +0100 Subject: [PATCH 111/561] [TEST] Adds tests for some missing coverage on dynamically created fields This adds some new tests to DocumentParserTests to make sure the DocumentParser behaves correctly when dynamically mapping fields. Especially testing that the dynamic setting works when dynamically mapping different field types. --- .../index/mapper/DocumentParserTests.java | 217 +++++++++++++++++- 1 file changed, 216 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java index 9319294c31d..0e53fcb8d7f 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java @@ -266,7 +266,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { assertNotNull(((ObjectMapper)barMapper).getMapper("baz")); } - public void testDynamicArrayWithTemplate() throws Exception { + public void testDynamicGeoPointArrayWithTemplate() throws Exception { DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startArray("dynamic_templates").startObject().startObject("georule") @@ -283,4 +283,219 @@ public class DocumentParserTests extends ESSingleNodeTestCase { ParsedDocument doc = mapper.parse("test", "type", "1", bytes); assertEquals(2, doc.rootDoc().getFields("foo").length); } + + public void testDynamicLongArrayWithTemplate() throws Exception { + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") + .startArray("dynamic_templates").startObject().startObject("georule") + .field("match", "foo*") + .startObject("mapping").field("type", "long").endObject() + .endObject().endObject().endArray().endObject().endObject().string(); + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); + + BytesReference bytes = XContentFactory.jsonBuilder() + .startObject().startArray("foo") + .value(0) + .value(1) + .endArray().endObject().bytes(); + ParsedDocument doc = mapper.parse("test", "type", "1", bytes); + assertEquals(4, doc.rootDoc().getFields("foo").length); + } + + public void testDynamicLongArray() throws Exception { + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") + .endObject().endObject().string(); + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); + + BytesReference bytes = XContentFactory.jsonBuilder() + .startObject().startArray("foo") + .value(0) + .value(1) + .endArray().endObject().bytes(); + ParsedDocument doc = mapper.parse("test", "type", "1", bytes); + assertEquals(4, doc.rootDoc().getFields("foo").length); + } + + public void testDynamicFalseLongArray() throws Exception { + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").field("dynamic", "false") + .endObject().endObject().string(); + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); + + BytesReference bytes = XContentFactory.jsonBuilder() + .startObject().startArray("foo") + .value(0) + .value(1) + .endArray().endObject().bytes(); + ParsedDocument doc = mapper.parse("test", "type", "1", bytes); + assertEquals(0, doc.rootDoc().getFields("foo").length); + } + + public void testDynamicStrictLongArray() throws Exception { + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").field("dynamic", "strict") + .endObject().endObject().string(); + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); + + BytesReference bytes = XContentFactory.jsonBuilder() + .startObject().startArray("foo") + .value(0) + .value(1) + .endArray().endObject().bytes(); + StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, + () -> mapper.parse("test", "type", "1", bytes)); + assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); + } + + public void testMappedGeoPointArray() throws Exception { + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") + .startObject("properties").startObject("foo").field("type", "geo_point") + .endObject().endObject().endObject().endObject().string(); + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); + + BytesReference bytes = XContentFactory.jsonBuilder() + .startObject().startArray("foo") + .startArray().value(0).value(0).endArray() + .startArray().value(1).value(1).endArray() + .endArray().endObject().bytes(); + ParsedDocument doc = mapper.parse("test", "type", "1", bytes); + assertEquals(2, doc.rootDoc().getFields("foo").length); + } + + public void testMappedLongArray() throws Exception { + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") + .startObject("properties").startObject("foo").field("type", "long") + .endObject().endObject().endObject().endObject().string(); + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); + + BytesReference bytes = XContentFactory.jsonBuilder() + .startObject().startArray("foo") + .value(0) + .value(1) + .endArray().endObject().bytes(); + ParsedDocument doc = mapper.parse("test", "type", "1", bytes); + assertEquals(4, doc.rootDoc().getFields("foo").length); + } + + public void testDynamicObjectWithTemplate() throws Exception { + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") + .startArray("dynamic_templates").startObject().startObject("georule") + .field("match", "foo*") + .startObject("mapping").field("type", "object") + .startObject("properties").startObject("bar").field("type", "keyword").endObject().endObject().endObject() + .endObject().endObject().endArray().endObject().endObject().string(); + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); + + BytesReference bytes = XContentFactory.jsonBuilder() + .startObject().startObject("foo") + .field("bar", "baz") + .endObject().endObject().bytes(); + ParsedDocument doc = mapper.parse("test", "type", "1", bytes); + assertEquals(2, doc.rootDoc().getFields("foo.bar").length); + } + + public void testDynamicFalseObject() throws Exception { + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").field("dynamic", "false") + .endObject().endObject().string(); + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); + + BytesReference bytes = XContentFactory.jsonBuilder() + .startObject().startObject("foo") + .field("bar", "baz") + .endObject().endObject().bytes(); + ParsedDocument doc = mapper.parse("test", "type", "1", bytes); + assertEquals(0, doc.rootDoc().getFields("foo.bar").length); + } + + public void testDynamicStrictObject() throws Exception { + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").field("dynamic", "strict") + .endObject().endObject().string(); + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); + + BytesReference bytes = XContentFactory.jsonBuilder() + .startObject().startObject("foo") + .field("bar", "baz") + .endObject().endObject().bytes(); + StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, + () -> mapper.parse("test", "type", "1", bytes)); + assertEquals("mapping set to strict, dynamic introduction of [foo] within [type] is not allowed", exception.getMessage()); + } + + public void testDynamicFalseValue() throws Exception { + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").field("dynamic", "false") + .endObject().endObject().string(); + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); + + BytesReference bytes = XContentFactory.jsonBuilder() + .startObject() + .field("bar", "baz") + .endObject().bytes(); + ParsedDocument doc = mapper.parse("test", "type", "1", bytes); + assertEquals(0, doc.rootDoc().getFields("bar").length); + } + + public void testDynamicStrictValue() throws Exception { + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").field("dynamic", "strict") + .endObject().endObject().string(); + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); + + BytesReference bytes = XContentFactory.jsonBuilder() + .startObject() + .field("bar", "baz") + .endObject().bytes(); + StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, + () -> mapper.parse("test", "type", "1", bytes)); + assertEquals("mapping set to strict, dynamic introduction of [bar] within [type] is not allowed", exception.getMessage()); + } + + public void testDynamicFalseNull() throws Exception { + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").field("dynamic", "false") + .endObject().endObject().string(); + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); + + BytesReference bytes = XContentFactory.jsonBuilder() + .startObject() + .field("bar", (String) null) + .endObject().bytes(); + ParsedDocument doc = mapper.parse("test", "type", "1", bytes); + assertEquals(0, doc.rootDoc().getFields("bar").length); + } + + public void testDynamicStrictNull() throws Exception { + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").field("dynamic", "strict") + .endObject().endObject().string(); + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); + + BytesReference bytes = XContentFactory.jsonBuilder() + .startObject() + .field("bar", (String) null) + .endObject().bytes(); + StrictDynamicMappingException exception = expectThrows(StrictDynamicMappingException.class, + () -> mapper.parse("test", "type", "1", bytes)); + assertEquals("mapping set to strict, dynamic introduction of [bar] within [type] is not allowed", exception.getMessage()); + } + + public void testMappedNullValue() throws Exception { + DocumentMapperParser mapperParser = createIndex("test").mapperService().documentMapperParser(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") + .startObject("properties").startObject("foo").field("type", "long") + .endObject().endObject().endObject().endObject().string(); + DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); + + BytesReference bytes = XContentFactory.jsonBuilder() + .startObject().field("foo", (Long) null) + .endObject().bytes(); + ParsedDocument doc = mapper.parse("test", "type", "1", bytes); + assertEquals(0, doc.rootDoc().getFields("foo").length); + } } From 9eb242a5fedfe10af8dc208e63f952a4917c5af9 Mon Sep 17 00:00:00 2001 From: Jun Ohtani Date: Fri, 8 Apr 2016 01:58:10 +0900 Subject: [PATCH 112/561] Analyze API : Rename filters/token_filters/char_filter to filter/token_filter/char_filter Closes #15189 --- .../indices/analyze/RestAnalyzeAction.java | 8 +-- .../analyze/RestAnalyzeActionTests.java | 52 ++++++++++++++++++- docs/reference/indices/analyze.asciidoc | 16 +++--- .../migration/migrate_5_0/rest.asciidoc | 5 ++ .../test/analysis_icu/10_basic.yaml | 6 +-- .../test/analysis_kuromoji/10_basic.yaml | 6 +-- .../test/analysis_stempel/10_basic.yaml | 2 +- .../rest-api-spec/api/indices.analyze.json | 4 +- .../test/indices.analyze/10_analyze.yaml | 10 ++-- 9 files changed, 83 insertions(+), 26 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/analyze/RestAnalyzeAction.java b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/analyze/RestAnalyzeAction.java index a3d0cc84559..75caea19856 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/admin/indices/analyze/RestAnalyzeAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/admin/indices/analyze/RestAnalyzeAction.java @@ -53,8 +53,8 @@ public class RestAnalyzeAction extends BaseRestHandler { public static final ParseField TEXT = new ParseField("text"); public static final ParseField FIELD = new ParseField("field"); public static final ParseField TOKENIZER = new ParseField("tokenizer"); - public static final ParseField TOKEN_FILTERS = new ParseField("token_filters", "filters"); - public static final ParseField CHAR_FILTERS = new ParseField("char_filters"); + public static final ParseField TOKEN_FILTERS = new ParseField("filter", "token_filter"); + public static final ParseField CHAR_FILTERS = new ParseField("char_filter"); public static final ParseField EXPLAIN = new ParseField("explain"); public static final ParseField ATTRIBUTES = new ParseField("attributes"); } @@ -78,8 +78,8 @@ public class RestAnalyzeAction extends BaseRestHandler { analyzeRequest.analyzer(request.param("analyzer")); analyzeRequest.field(request.param("field")); analyzeRequest.tokenizer(request.param("tokenizer")); - analyzeRequest.tokenFilters(request.paramAsStringArray("token_filters", request.paramAsStringArray("filters", analyzeRequest.tokenFilters()))); - analyzeRequest.charFilters(request.paramAsStringArray("char_filters", analyzeRequest.charFilters())); + analyzeRequest.tokenFilters(request.paramAsStringArray("filter", request.paramAsStringArray("token_filter", analyzeRequest.tokenFilters()))); + analyzeRequest.charFilters(request.paramAsStringArray("char_filter", analyzeRequest.charFilters())); analyzeRequest.explain(request.paramAsBoolean("explain", false)); analyzeRequest.attributes(request.paramAsStringArray("attributes", analyzeRequest.attributes())); diff --git a/core/src/test/java/org/elasticsearch/rest/action/admin/indices/analyze/RestAnalyzeActionTests.java b/core/src/test/java/org/elasticsearch/rest/action/admin/indices/analyze/RestAnalyzeActionTests.java index 34e8315372b..8541b5785c8 100644 --- a/core/src/test/java/org/elasticsearch/rest/action/admin/indices/analyze/RestAnalyzeActionTests.java +++ b/core/src/test/java/org/elasticsearch/rest/action/admin/indices/analyze/RestAnalyzeActionTests.java @@ -37,7 +37,7 @@ public class RestAnalyzeActionTests extends ESTestCase { .startObject() .field("text", "THIS IS A TEST") .field("tokenizer", "keyword") - .array("filters", "lowercase") + .array("filter", "lowercase") .endObject().bytes(); AnalyzeRequest analyzeRequest = new AnalyzeRequest("for test"); @@ -94,5 +94,55 @@ public class RestAnalyzeActionTests extends ESTestCase { } } + public void testDeprecatedParamException() throws Exception { + BytesReference content = XContentFactory.jsonBuilder() + .startObject() + .field("text", "THIS IS A TEST") + .field("tokenizer", "keyword") + .array("filters", "lowercase") + .endObject().bytes(); + + AnalyzeRequest analyzeRequest = new AnalyzeRequest("for test"); + + try { + RestAnalyzeAction.buildFromContent(content, analyzeRequest, new ParseFieldMatcher(Settings.EMPTY)); + } catch (Exception e) { + assertThat(e, instanceOf(IllegalArgumentException.class)); + assertThat(e.getMessage(), startsWith("Unknown parameter [filters]")); + } + + content = XContentFactory.jsonBuilder() + .startObject() + .field("text", "THIS IS A TEST") + .field("tokenizer", "keyword") + .array("token_filters", "lowercase") + .endObject().bytes(); + + analyzeRequest = new AnalyzeRequest("for test"); + + try { + RestAnalyzeAction.buildFromContent(content, analyzeRequest, new ParseFieldMatcher(Settings.EMPTY)); + } catch (Exception e) { + assertThat(e, instanceOf(IllegalArgumentException.class)); + assertThat(e.getMessage(), startsWith("Unknown parameter [token_filters]")); + } + + content = XContentFactory.jsonBuilder() + .startObject() + .field("text", "THIS IS A TEST") + .field("tokenizer", "keyword") + .array("char_filters", "lowercase") + .endObject().bytes(); + + analyzeRequest = new AnalyzeRequest("for test"); + + try { + RestAnalyzeAction.buildFromContent(content, analyzeRequest, new ParseFieldMatcher(Settings.EMPTY)); + } catch (Exception e) { + assertThat(e, instanceOf(IllegalArgumentException.class)); + assertThat(e.getMessage(), startsWith("Unknown parameter [char_filters]")); + } + + } } diff --git a/docs/reference/indices/analyze.asciidoc b/docs/reference/indices/analyze.asciidoc index 1e8cd77ef09..47d73b7d3dc 100644 --- a/docs/reference/indices/analyze.asciidoc +++ b/docs/reference/indices/analyze.asciidoc @@ -28,7 +28,7 @@ curl -XGET 'localhost:9200/_analyze' -d ' -------------------------------------------------- Or by building a custom transient analyzer out of tokenizers, -token filters and char filters. Token filters can use the shorter 'filters' +token filters and char filters. Token filters can use the shorter 'filter' parameter name: [source,js] @@ -36,19 +36,21 @@ parameter name: curl -XGET 'localhost:9200/_analyze' -d ' { "tokenizer" : "keyword", - "filters" : ["lowercase"], + "filter" : ["lowercase"], "text" : "this is a test" }' curl -XGET 'localhost:9200/_analyze' -d ' { "tokenizer" : "keyword", - "token_filters" : ["lowercase"], - "char_filters" : ["html_strip"], + "token_filter" : ["lowercase"], + "char_filter" : ["html_strip"], "text" : "this is a test" }' -------------------------------------------------- +deprecated[5.0.0, Use `filter`/`token_filter`/`char_filter` instead of `filters`/`token_filters`/`char_filters`] + It can also run against a specific index: [source,js] @@ -90,7 +92,7 @@ All parameters can also supplied as request parameters. For example: [source,js] -------------------------------------------------- -curl -XGET 'localhost:9200/_analyze?tokenizer=keyword&filters=lowercase&text=this+is+a+test' +curl -XGET 'localhost:9200/_analyze?tokenizer=keyword&filter=lowercase&text=this+is+a+test' -------------------------------------------------- For backwards compatibility, we also accept the text parameter as the body of the request, @@ -98,7 +100,7 @@ provided it doesn't start with `{` : [source,js] -------------------------------------------------- -curl -XGET 'localhost:9200/_analyze?tokenizer=keyword&token_filters=lowercase&char_filters=html_strip' -d 'this is a test' +curl -XGET 'localhost:9200/_analyze?tokenizer=keyword&token_filter=lowercase&char_filter=html_strip' -d 'this is a test' -------------------------------------------------- === Explain Analyze @@ -113,7 +115,7 @@ experimental[The format of the additional detail information is experimental and GET test/_analyze { "tokenizer" : "standard", - "token_filters" : ["snowball"], + "token_filter" : ["snowball"], "text" : "detailed output", "explain" : true, "attributes" : ["keyword"] <1> diff --git a/docs/reference/migration/migrate_5_0/rest.asciidoc b/docs/reference/migration/migrate_5_0/rest.asciidoc index 439fab4d994..c6b3a4228c4 100644 --- a/docs/reference/migration/migrate_5_0/rest.asciidoc +++ b/docs/reference/migration/migrate_5_0/rest.asciidoc @@ -47,3 +47,8 @@ been added to the `jvm.options` file: Note that this option is provided solely for migration purposes and will be removed in Elasticsearch 6.0.0. + +==== Analyze API changes + +The deprecated `filters`/`token_filters`/`char_filters` parameter has been +renamed `filter`/`token_filter`/`char_filter`. diff --git a/plugins/analysis-icu/src/test/resources/rest-api-spec/test/analysis_icu/10_basic.yaml b/plugins/analysis-icu/src/test/resources/rest-api-spec/test/analysis_icu/10_basic.yaml index 4497cb7f2cb..64fbbcadf7d 100644 --- a/plugins/analysis-icu/src/test/resources/rest-api-spec/test/analysis_icu/10_basic.yaml +++ b/plugins/analysis-icu/src/test/resources/rest-api-spec/test/analysis_icu/10_basic.yaml @@ -12,7 +12,7 @@ "Normalization filter": - do: indices.analyze: - filters: icu_normalizer + filter: icu_normalizer text: Foo Bar Ruß tokenizer: keyword - length: { tokens: 1 } @@ -21,7 +21,7 @@ "Normalization charfilter": - do: indices.analyze: - char_filters: icu_normalizer + char_filter: icu_normalizer text: Foo Bar Ruß tokenizer: keyword - length: { tokens: 1 } @@ -30,7 +30,7 @@ "Folding filter": - do: indices.analyze: - filters: icu_folding + filter: icu_folding text: Foo Bar résumé tokenizer: keyword - length: { tokens: 1 } diff --git a/plugins/analysis-kuromoji/src/test/resources/rest-api-spec/test/analysis_kuromoji/10_basic.yaml b/plugins/analysis-kuromoji/src/test/resources/rest-api-spec/test/analysis_kuromoji/10_basic.yaml index 92c6527fe6a..42df558567d 100644 --- a/plugins/analysis-kuromoji/src/test/resources/rest-api-spec/test/analysis_kuromoji/10_basic.yaml +++ b/plugins/analysis-kuromoji/src/test/resources/rest-api-spec/test/analysis_kuromoji/10_basic.yaml @@ -31,7 +31,7 @@ indices.analyze: text: 飲み tokenizer: kuromoji_tokenizer - filters: kuromoji_baseform + filter: kuromoji_baseform - length: { tokens: 1 } - match: { tokens.0.token: 飲む } --- @@ -40,7 +40,7 @@ indices.analyze: text: 寿司 tokenizer: kuromoji_tokenizer - filters: kuromoji_readingform + filter: kuromoji_readingform - length: { tokens: 1 } - match: { tokens.0.token: スシ } --- @@ -49,6 +49,6 @@ indices.analyze: text: サーバー tokenizer: kuromoji_tokenizer - filters: kuromoji_stemmer + filter: kuromoji_stemmer - length: { tokens: 1 } - match: { tokens.0.token: サーバ } diff --git a/plugins/analysis-stempel/src/test/resources/rest-api-spec/test/analysis_stempel/10_basic.yaml b/plugins/analysis-stempel/src/test/resources/rest-api-spec/test/analysis_stempel/10_basic.yaml index 3dc825290f4..f87f00b7922 100644 --- a/plugins/analysis-stempel/src/test/resources/rest-api-spec/test/analysis_stempel/10_basic.yaml +++ b/plugins/analysis-stempel/src/test/resources/rest-api-spec/test/analysis_stempel/10_basic.yaml @@ -5,7 +5,7 @@ indices.analyze: text: studenci tokenizer: keyword - filters: polish_stem + filter: polish_stem - length: { tokens: 1 } - match: { tokens.0.token: student } --- diff --git a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.analyze.json b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.analyze.json index c3dc0a18b45..881382ffa00 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/api/indices.analyze.json +++ b/rest-api-spec/src/main/resources/rest-api-spec/api/indices.analyze.json @@ -16,7 +16,7 @@ "type" : "string", "description" : "The name of the analyzer to use" }, - "char_filters": { + "char_filter": { "type" : "list", "description" : "A comma-separated list of character filters to use for the analysis" }, @@ -24,7 +24,7 @@ "type" : "string", "description" : "Use the analyzer configured for this field (instead of passing the analyzer name)" }, - "filters": { + "filter": { "type" : "list", "description" : "A comma-separated list of filters to use for the analysis" }, diff --git a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.analyze/10_analyze.yaml b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.analyze/10_analyze.yaml index 93ffe0d5db1..10dc63cd109 100644 --- a/rest-api-spec/src/main/resources/rest-api-spec/test/indices.analyze/10_analyze.yaml +++ b/rest-api-spec/src/main/resources/rest-api-spec/test/indices.analyze/10_analyze.yaml @@ -17,7 +17,7 @@ setup: "Tokenizer and filter": - do: indices.analyze: - filters: lowercase + filter: lowercase text: Foo Bar tokenizer: keyword - length: { tokens: 1 } @@ -52,7 +52,7 @@ setup: "JSON in Body": - do: indices.analyze: - body: { "text": "Foo Bar", "filters": ["lowercase"], "tokenizer": keyword } + body: { "text": "Foo Bar", "filter": ["lowercase"], "tokenizer": keyword } - length: {tokens: 1 } - match: { tokens.0.token: foo bar } --- @@ -60,14 +60,14 @@ setup: - do: indices.analyze: text: Foo Bar - body: { "text": "Bar Foo", "filters": ["lowercase"], "tokenizer": keyword } + body: { "text": "Bar Foo", "filter": ["lowercase"], "tokenizer": keyword } - length: {tokens: 1 } - match: { tokens.0.token: bar foo } --- "Array text": - do: indices.analyze: - body: { "text": ["Foo Bar", "Baz"], "filters": ["lowercase"], "tokenizer": keyword } + body: { "text": ["Foo Bar", "Baz"], "filter": ["lowercase"], "tokenizer": keyword } - length: {tokens: 2 } - match: { tokens.0.token: foo bar } - match: { tokens.1.token: baz } @@ -85,7 +85,7 @@ setup: "Detail output spcified attribute": - do: indices.analyze: - body: {"text": "This is troubled", "char_filters": ["html_strip"], "filters": ["snowball"], "tokenizer": standard, "explain": true, "attributes": ["keyword"]} + body: {"text": "This is troubled", "char_filter": ["html_strip"], "filter": ["snowball"], "tokenizer": standard, "explain": true, "attributes": ["keyword"]} - length: { detail.charfilters: 1 } - length: { detail.tokenizer.tokens: 3 } - length: { detail.tokenfilters.0.tokens: 3 } From 233fe86ee4ba3ee3dec83d331da99ade01dceae9 Mon Sep 17 00:00:00 2001 From: Isabel Drost-Fromm Date: Thu, 21 Apr 2016 12:40:29 +0200 Subject: [PATCH 113/561] Makes Script type writeable Used to be Streamable. Left-over of the PROTOTYPE related refactoring by @nik9000 Closes #17753 --- .../action/search/SearchRequest.java | 4 +- .../action/update/UpdateRequest.java | 2 +- .../index/query/ScriptQueryBuilder.java | 2 +- .../ScriptScoreFunctionBuilder.java | 2 +- .../java/org/elasticsearch/script/Script.java | 44 ++++--------------- .../org/elasticsearch/script/Template.java | 20 +++------ .../heuristics/ScriptHeuristic.java | 2 +- .../scripted/InternalScriptedMetric.java | 2 +- .../ScriptedMetricAggregatorBuilder.java | 16 +++---- .../BucketScriptPipelineAggregator.java | 2 +- ...BucketScriptPipelineAggregatorBuilder.java | 2 +- .../BucketSelectorPipelineAggregator.java | 2 +- ...cketSelectorPipelineAggregatorBuilder.java | 2 +- .../ValuesSourceAggregatorBuilder.java | 2 +- .../search/builder/SearchSourceBuilder.java | 2 +- .../internal/ShardSearchLocalRequest.java | 4 +- .../search/sort/ScriptSortBuilder.java | 2 +- .../AbstractBulkIndexByScrollRequest.java | 4 +- 18 files changed, 42 insertions(+), 74 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/action/search/SearchRequest.java b/core/src/main/java/org/elasticsearch/action/search/SearchRequest.java index b844e368328..a0ea18c2965 100644 --- a/core/src/main/java/org/elasticsearch/action/search/SearchRequest.java +++ b/core/src/main/java/org/elasticsearch/action/search/SearchRequest.java @@ -326,7 +326,7 @@ public class SearchRequest extends ActionRequest implements Indic indicesOptions = IndicesOptions.readIndicesOptions(in); requestCache = in.readOptionalBoolean(); - template = in.readOptionalStreamable(Template::new); + template = in.readOptionalWriteable(Template::new); } @Override @@ -357,6 +357,6 @@ public class SearchRequest extends ActionRequest implements Indic out.writeStringArray(types); indicesOptions.writeIndicesOptions(out); out.writeOptionalBoolean(requestCache); - out.writeOptionalStreamable(template); + out.writeOptionalWriteable(template); } } diff --git a/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java b/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java index 0877ea1c66b..31f219fd4c7 100644 --- a/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java +++ b/core/src/main/java/org/elasticsearch/action/update/UpdateRequest.java @@ -727,7 +727,7 @@ public class UpdateRequest extends InstanceShardOperationRequest routing = in.readOptionalString(); parent = in.readOptionalString(); if (in.readBoolean()) { - script = Script.readScript(in); + script = new Script(in); } retryOnConflict = in.readVInt(); refresh = in.readBoolean(); diff --git a/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java index 65be61d672b..8ff254b3462 100644 --- a/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/ScriptQueryBuilder.java @@ -68,7 +68,7 @@ public class ScriptQueryBuilder extends AbstractQueryBuilder */ public ScriptQueryBuilder(StreamInput in) throws IOException { super(in); - script = Script.readScript(in); + script = new Script(in); } @Override diff --git a/core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java b/core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java index 51555425596..a33a9c14fb7 100644 --- a/core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreFunctionBuilder.java @@ -65,7 +65,7 @@ public class ScriptScoreFunctionBuilder extends ScoreFunctionBuilder { - /** - * A {@link Supplier} implementation for use when reading a {@link Script} - * using {@link StreamInput#readOptionalStreamable(Supplier)} - */ - public static final Supplier