From bdee8c263206880924cf841fb6be0d5c338a60f5 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Tue, 24 May 2016 13:37:32 +0200 Subject: [PATCH] Disable XContent auto closing of object and arrays --- .../node/tasks/list/ListTasksResponse.java | 1 + .../common/xcontent/XContentBuilder.java | 2 +- .../common/xcontent/cbor/CborXContent.java | 3 + .../common/xcontent/json/JsonXContent.java | 2 + .../xcontent/json/JsonXContentGenerator.java | 4 + .../common/xcontent/smile/SmileXContent.java | 3 + .../fieldstats/RestFieldStatsAction.java | 2 + .../elasticsearch/script/ScriptMetaData.java | 1 + .../common/xcontent/BaseXContentTestCase.java | 25 ++++ .../builder/XContentBuilderTests.java | 24 ++++ .../org/elasticsearch/get/GetActionIT.java | 2 +- .../index/mapper/DocumentParserTests.java | 6 +- .../index/mapper/DynamicMappingTests.java | 49 ++++---- .../mapper/boost/FieldLevelBoostTests.java | 55 +++++---- .../mapper/compound/CompoundTypesTests.java | 3 + .../copyto/CopyToMapperIntegrationIT.java | 3 +- .../mapper/multifield/MultiFieldTests.java | 1 + .../mapper/nested/NestedMappingTests.java | 14 +-- .../mapper/simple/SimpleMapperTests.java | 2 +- ...gFieldMapperPositionIncrementGapTests.java | 2 + .../timestamp/TimestampMappingTests.java | 6 +- .../index/mapper/ttl/TTLMappingTests.java | 4 +- .../update/UpdateMappingOnClusterIT.java | 2 +- .../query/MoreLikeThisQueryBuilderTests.java | 1 + .../index/similarity/SimilarityTests.java | 1 + .../aggregations/AggregatorParsingTests.java | 110 +++++++++--------- .../aggregations/bucket/ParentIdAggIT.java | 1 + .../search/highlight/HighlighterSearchIT.java | 3 +- .../search/morelikethis/MoreLikeThisIT.java | 17 +-- .../search/query/SearchQueryIT.java | 3 +- .../suggest/ContextSuggestSearch2xIT.java | 2 + .../completion/GeoContextMappingTests.java | 31 ++--- .../similarity/SimilarityIT.java | 1 + .../timestamp/SimpleTimestampIT.java | 2 +- .../org/elasticsearch/ttl/SimpleTTLIT.java | 2 +- .../messy/tests/EquivalenceTests.java | 38 +++--- .../messy/tests/SearchFieldsTests.java | 35 ++++-- .../percolator/MultiPercolatorIT.java | 2 +- .../percolator/PercolatorIT.java | 1 + .../percolator/PercolatorQuerySearchIT.java | 48 ++++---- .../SimpleAttachmentMapperTests.java | 1 + .../index/mapper/size/SizeMappingIT.java | 2 +- 42 files changed, 308 insertions(+), 209 deletions(-) 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 446ae3affb7..bad4001e211 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 @@ -192,6 +192,7 @@ public class ListTasksResponse extends BaseTasksResponse implements ToXContent { builder.endObject(); builder.endObject(); } + builder.endObject(); } else if ("parents".equals(groupBy)) { builder.startObject("tasks"); for (TaskGroup group : getTaskGroups()) { 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 3fa182e3727..2891ca2608c 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/XContentBuilder.java @@ -781,7 +781,7 @@ public final class XContentBuilder implements BytesStream, Releasable { try { generator.close(); } catch (IOException e) { - // ignore + throw new IllegalStateException("failed to close the XContentBuilder", e); } } diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/cbor/CborXContent.java b/core/src/main/java/org/elasticsearch/common/xcontent/cbor/CborXContent.java index bc2bc81a2c0..1670810511a 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/cbor/CborXContent.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/cbor/CborXContent.java @@ -20,6 +20,7 @@ package org.elasticsearch.common.xcontent.cbor; import com.fasterxml.jackson.core.JsonEncoding; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.dataformat.cbor.CBORFactory; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.bytes.BytesReference; @@ -50,6 +51,8 @@ public class CborXContent implements XContent { static { cborFactory = new CBORFactory(); cborFactory.configure(CBORFactory.Feature.FAIL_ON_SYMBOL_HASH_OVERFLOW, false); // this trips on many mappings now... + // Do not automatically close unclosed objects/arrays in com.fasterxml.jackson.dataformat.cbor.CBORGenerator#close() method + cborFactory.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false); cborXContent = new CborXContent(); } diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContent.java b/core/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContent.java index f991a462f3b..13cacc41538 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContent.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/json/JsonXContent.java @@ -73,6 +73,8 @@ public class JsonXContent implements XContent { jsonFactory.configure(JsonGenerator.Feature.QUOTE_FIELD_NAMES, true); jsonFactory.configure(JsonParser.Feature.ALLOW_COMMENTS, true); jsonFactory.configure(JsonFactory.Feature.FAIL_ON_SYMBOL_HASH_OVERFLOW, false); // this trips on many mappings now... + // Do not automatically close unclosed objects/arrays in com.fasterxml.jackson.core.json.UTF8JsonGenerator#close() method + jsonFactory.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false); jsonXContent = new JsonXContent(); } 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 e74ab01bd6a..462288f688a 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 @@ -389,6 +389,10 @@ public class JsonXContentGenerator implements XContentGenerator { if (generator.isClosed()) { return; } + JsonStreamContext context = generator.getOutputContext(); + if ((context != null) && (context.inRoot() == false)) { + throw new IOException("unclosed object or array found"); + } if (writeLineFeedAtEnd) { flush(); generator.writeRaw(LF); diff --git a/core/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContent.java b/core/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContent.java index fc12e40f5a3..3a104056b09 100644 --- a/core/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContent.java +++ b/core/src/main/java/org/elasticsearch/common/xcontent/smile/SmileXContent.java @@ -20,6 +20,7 @@ package org.elasticsearch.common.xcontent.smile; import com.fasterxml.jackson.core.JsonEncoding; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.dataformat.smile.SmileFactory; import com.fasterxml.jackson.dataformat.smile.SmileGenerator; import org.elasticsearch.common.bytes.BytesReference; @@ -51,6 +52,8 @@ public class SmileXContent implements XContent { smileFactory = new SmileFactory(); smileFactory.configure(SmileGenerator.Feature.ENCODE_BINARY_AS_7BIT, false); // for now, this is an overhead, might make sense for web sockets smileFactory.configure(SmileFactory.Feature.FAIL_ON_SYMBOL_HASH_OVERFLOW, false); // this trips on many mappings now... + // Do not automatically close unclosed objects/arrays in com.fasterxml.jackson.dataformat.smile.SmileGenerator#close() method + smileFactory.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false); smileXContent = new SmileXContent(); } diff --git a/core/src/main/java/org/elasticsearch/rest/action/fieldstats/RestFieldStatsAction.java b/core/src/main/java/org/elasticsearch/rest/action/fieldstats/RestFieldStatsAction.java index c2dc3220ec8..744a76e7352 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/fieldstats/RestFieldStatsAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/fieldstats/RestFieldStatsAction.java @@ -99,7 +99,9 @@ public class RestFieldStatsAction extends BaseRestHandler { for (Map.Entry entry : response.getConflicts().entrySet()) { builder.field(entry.getKey(), entry.getValue()); } + builder.endObject(); } + builder.endObject(); return new BytesRestResponse(RestStatus.OK, builder); } }); diff --git a/core/src/main/java/org/elasticsearch/script/ScriptMetaData.java b/core/src/main/java/org/elasticsearch/script/ScriptMetaData.java index 84b4da4b818..5c0f8cee04c 100644 --- a/core/src/main/java/org/elasticsearch/script/ScriptMetaData.java +++ b/core/src/main/java/org/elasticsearch/script/ScriptMetaData.java @@ -94,6 +94,7 @@ public final class ScriptMetaData implements MetaData.Custom { // because the parsers current location is already beyond the beginning we need to add a START_OBJECT: builder.startObject(); builder.copyCurrentStructure(parser); + builder.endObject(); break; } return builder.string(); diff --git a/core/src/test/java/org/elasticsearch/common/xcontent/BaseXContentTestCase.java b/core/src/test/java/org/elasticsearch/common/xcontent/BaseXContentTestCase.java index 1b917263b79..b4ddd4ab589 100644 --- a/core/src/test/java/org/elasticsearch/common/xcontent/BaseXContentTestCase.java +++ b/core/src/test/java/org/elasticsearch/common/xcontent/BaseXContentTestCase.java @@ -27,6 +27,8 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; +import static org.hamcrest.Matchers.equalTo; + public abstract class BaseXContentTestCase extends ESTestCase { public abstract XContentType xcontentType(); @@ -41,6 +43,29 @@ public abstract class BaseXContentTestCase extends ESTestCase { assertEquals(xcontentType(), XContentFactory.xContentType(data)); } + public void testMissingEndObject() throws IOException { + IOException e = expectThrows(IOException.class, () -> { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + try (XContentGenerator generator = xcontentType().xContent().createGenerator(os)) { + generator.writeStartObject(); + generator.writeFieldName("foo"); + generator.writeNumber(2L); + } + }); + assertEquals(e.getMessage(), "unclosed object or array found"); + } + + public void testMissingEndArray() throws IOException { + IOException e = expectThrows(IOException.class, () -> { + ByteArrayOutputStream os = new ByteArrayOutputStream(); + try (XContentGenerator generator = xcontentType().xContent().createGenerator(os)) { + generator.writeStartArray(); + generator.writeNumber(2L); + } + }); + assertEquals(e.getMessage(), "unclosed object or array found"); + } + public void testRawField() throws Exception { for (boolean useStream : new boolean[] {false, true}) { for (XContentType xcontentType : XContentType.values()) { diff --git a/core/src/test/java/org/elasticsearch/common/xcontent/builder/XContentBuilderTests.java b/core/src/test/java/org/elasticsearch/common/xcontent/builder/XContentBuilderTests.java index 42695959bbe..34944e713bd 100644 --- a/core/src/test/java/org/elasticsearch/common/xcontent/builder/XContentBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/common/xcontent/builder/XContentBuilderTests.java @@ -363,4 +363,28 @@ public class XContentBuilderTests extends ESTestCase { assertThat(e.getMessage(), equalTo("field name cannot be null")); } } + + public void testMissingEndObject() throws IOException { + IllegalStateException e = expectThrows(IllegalStateException.class, () -> { + try (XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()))) { + builder.startObject(); + builder.field("foo", true); + } + }); + assertThat(e.getMessage(), equalTo("failed to close the XContentBuilder")); + assertThat(e.getCause().getMessage(), equalTo("unclosed object or array found")); + } + + public void testMissingEndArray() throws IOException { + IllegalStateException e = expectThrows(IllegalStateException.class, () -> { + try (XContentBuilder builder = XContentFactory.contentBuilder(randomFrom(XContentType.values()))) { + builder.startObject(); + builder.startArray("foo"); + builder.value(0); + builder.value(1); + } + }); + assertThat(e.getMessage(), equalTo("failed to close the XContentBuilder")); + assertThat(e.getCause().getMessage(), equalTo("unclosed object or array found")); + } } diff --git a/core/src/test/java/org/elasticsearch/get/GetActionIT.java b/core/src/test/java/org/elasticsearch/get/GetActionIT.java index 88c70b3dc3e..8c4b699cbff 100644 --- a/core/src/test/java/org/elasticsearch/get/GetActionIT.java +++ b/core/src/test/java/org/elasticsearch/get/GetActionIT.java @@ -627,7 +627,7 @@ public class GetActionIT extends ESIntegTestCase { .startObject("field4").field("type", "text").field("store", true) .endObject().endObject() .endObject().endObject() - .endObject().endObject() + .endObject().endObject().endObject() .endObject().endObject().endObject())); BytesReference source = jsonBuilder().startObject() 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 197ac9ec55e..058b1bd5360 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DocumentParserTests.java @@ -109,7 +109,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .field("type", "object") .field("dynamic", true) .startObject("properties") - .endObject().endObject().endObject().endObject().string(); + .endObject().endObject().endObject().endObject().endObject().string(); DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); BytesReference bytes = XContentFactory.jsonBuilder() .startObject().startObject("foo") @@ -129,7 +129,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .field("type", "object") .field("dynamic", true) .startObject("properties") - .endObject().endObject().endObject().endObject().string(); + .endObject().endObject().endObject().endObject().endObject().string(); DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); BytesReference bytes = XContentFactory.jsonBuilder() .startObject().startObject("foo").startObject("bar") @@ -148,7 +148,7 @@ public class DocumentParserTests extends ESSingleNodeTestCase { .startObject("foo") .field("type", "object") .startObject("properties") - .endObject().endObject().endObject().endObject().string(); + .endObject().endObject().endObject().endObject().endObject().string(); DocumentMapper mapper = mapperParser.parse("type", new CompressedXContent(mapping)); BytesReference bytes = XContentFactory.jsonBuilder() .startObject().startObject("foo") diff --git a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java index af96bc503c0..c44ea296f73 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/DynamicMappingTests.java @@ -65,6 +65,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { .startObject() .field("field1", "value1") .field("field2", "value2") + .endObject() .bytes()); assertThat(doc.rootDoc().get("field1"), equalTo("value1")); @@ -85,6 +86,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { .startObject() .field("field1", "value1") .field("field2", "value2") + .endObject() .bytes()); assertThat(doc.rootDoc().get("field1"), equalTo("value1")); @@ -102,27 +104,21 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)); - try { - defaultMapper.parse("test", "type", "1", jsonBuilder() - .startObject() - .field("field1", "value1") - .field("field2", "value2") - .bytes()); - fail(); - } catch (StrictDynamicMappingException e) { - // all is well - } + StrictDynamicMappingException e = expectThrows(StrictDynamicMappingException.class, () -> defaultMapper.parse("test", "type", "1", jsonBuilder() + .startObject() + .field("field1", "value1") + .field("field2", "value2") + .endObject() + .bytes())); + assertThat(e.getMessage(), equalTo("mapping set to strict, dynamic introduction of [field2] within [type] is not allowed")); - try { - defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder() + e = expectThrows(StrictDynamicMappingException.class, () -> defaultMapper.parse("test", "type", "1", XContentFactory.jsonBuilder() .startObject() .field("field1", "value1") .field("field2", (String) null) - .bytes()); - fail(); - } catch (StrictDynamicMappingException e) { - // all is well - } + .endObject() + .bytes())); + assertThat(e.getMessage(), equalTo("mapping set to strict, dynamic introduction of [field2] within [type] is not allowed")); } public void testDynamicFalseWithInnerObjectButDynamicSetOnRoot() throws IOException { @@ -142,6 +138,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { .field("field1", "value1") .field("field2", "value2") .endObject() + .endObject() .bytes()); assertThat(doc.rootDoc().get("obj1.field1"), equalTo("value1")); @@ -160,17 +157,15 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)); - try { + StrictDynamicMappingException e = expectThrows(StrictDynamicMappingException.class, () -> defaultMapper.parse("test", "type", "1", jsonBuilder() .startObject().startObject("obj1") .field("field1", "value1") .field("field2", "value2") .endObject() - .bytes()); - fail(); - } catch (StrictDynamicMappingException e) { - // all is well - } + .endObject() + .bytes())); + assertThat(e.getMessage(), equalTo("mapping set to strict, dynamic introduction of [field2] within [obj1] is not allowed")); } public void testDynamicMappingOnEmptyString() throws Exception { @@ -220,7 +215,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { DocumentMapperParser parser = indexService.mapperService().documentMapperParser(); String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("foo").field("type", "text").endObject().endObject() - .endObject().string(); + .endObject().endObject().string(); DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); Mapper update = parse(mapper, parser, XContentFactory.jsonBuilder().startObject().field("foo", "bar").endObject()); @@ -263,7 +258,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { // every new field introduction runs in linear time with the total number of fields String mapping = XContentFactory.jsonBuilder().startObject().startObject("type") .startObject("properties").startObject("foo").field("type", "text").endObject().endObject() - .endObject().string(); + .endObject().endObject().string(); DocumentMapper mapper = parser.parse("type", new CompressedXContent(mapping)); assertEquals(mapping, serialize(mapper)); @@ -283,7 +278,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { .endObject() .endObject() .endObject() - .endObject().endObject().string(), serialize(update)); + .endObject().endObject().endObject().string(), serialize(update)); } public void testIntroduceTwoFields() throws Exception { @@ -318,7 +313,7 @@ public class DynamicMappingTests extends ESSingleNodeTestCase { .endObject() .endObject() .endObject() - .endObject().endObject().string(), serialize(update)); + .endObject().endObject().endObject().string(), serialize(update)); } public void testObject() throws Exception { diff --git a/core/src/test/java/org/elasticsearch/index/mapper/boost/FieldLevelBoostTests.java b/core/src/test/java/org/elasticsearch/index/mapper/boost/FieldLevelBoostTests.java index 90121e66ea8..9405a23eb03 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/boost/FieldLevelBoostTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/boost/FieldLevelBoostTests.java @@ -37,6 +37,7 @@ import java.util.Collection; import static org.hamcrest.Matchers.closeTo; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; /** */ @@ -59,6 +60,7 @@ public class FieldLevelBoostTests extends ESSingleNodeTestCase { .startObject("float_field").field("type", "float").startObject("norms").field("enabled", true).endObject().endObject() .startObject("long_field").field("type", "long").startObject("norms").field("enabled", true).endObject().endObject() .startObject("short_field").field("type", "short").startObject("norms").field("enabled", true).endObject().endObject() + .endObject().endObject().endObject() .string(); DocumentMapper docMapper = createIndex("test", BW_SETTINGS).mapperService().documentMapperParser().parse("person", new CompressedXContent(mapping)); @@ -71,6 +73,7 @@ public class FieldLevelBoostTests extends ESSingleNodeTestCase { .startObject("float_field").field("boost", 7.0).field("value", 40.0).endObject() .startObject("long_field").field("boost", 8.0).field("value", 50).endObject() .startObject("short_field").field("boost", 9.0).field("value", 60).endObject() + .endObject() .bytes(); Document doc = docMapper.parse("test", "person", "1", json).rootDoc(); @@ -109,6 +112,7 @@ public class FieldLevelBoostTests extends ESSingleNodeTestCase { .startObject("float_field").field("type", "float").field("boost", "7.0").endObject() .startObject("long_field").field("type", "long").field("boost", "8.0").endObject() .startObject("short_field").field("type", "short").field("boost", "9.0").endObject() + .endObject().endObject().endObject() .string(); { @@ -122,6 +126,7 @@ public class FieldLevelBoostTests extends ESSingleNodeTestCase { .field("float_field", 40.0) .field("long_field", 50) .field("short_field", 60) + .endObject() .bytes(); Document doc = docMapper.parse("test", "person", "1", json).rootDoc(); @@ -161,6 +166,7 @@ public class FieldLevelBoostTests extends ESSingleNodeTestCase { .field("float_field", 40.0) .field("long_field", 50) .field("short_field", 60) + .endObject() .bytes(); Document doc = docMapper.parse("test", "person", "1", json).rootDoc(); @@ -200,79 +206,80 @@ public class FieldLevelBoostTests extends ESSingleNodeTestCase { .startObject("float_field").field("type", "float").startObject("norms").field("enabled", true).endObject().endObject() .startObject("long_field").field("type", "long").startObject("norms").field("enabled", true).endObject().endObject() .startObject("short_field").field("type", "short").startObject("norms").field("enabled", true).endObject().endObject() + .endObject().endObject().endObject() .string(); DocumentMapper docMapper = createIndex("test", BW_SETTINGS).mapperService().documentMapperParser().parse("person", new CompressedXContent(mapping)); try { docMapper.parse("test", "person", "1", XContentFactory.jsonBuilder().startObject() .startObject("str_field").field("foo", "bar") - .endObject().bytes()).rootDoc(); + .endObject().endObject().bytes()).rootDoc(); fail(); - } catch (MapperParsingException ex) { - // Expected + } catch (Exception ex) { + assertThat(ex, instanceOf(MapperParsingException.class)); } try { docMapper.parse("test", "person", "1", XContentFactory.jsonBuilder().startObject() .startObject("int_field").field("foo", "bar") - .endObject().bytes()).rootDoc(); + .endObject().endObject().bytes()).rootDoc(); fail(); - } catch (MapperParsingException ex) { - // Expected + } catch (Exception ex) { + assertThat(ex, instanceOf(MapperParsingException.class)); } try { docMapper.parse("test", "person", "1", XContentFactory.jsonBuilder().startObject() .startObject("byte_field").field("foo", "bar") - .endObject().bytes()).rootDoc(); + .endObject().endObject().bytes()).rootDoc(); fail(); - } catch (MapperParsingException ex) { - // Expected + } catch (Exception ex) { + assertThat(ex, instanceOf(MapperParsingException.class)); } try { docMapper.parse("test", "person", "1", XContentFactory.jsonBuilder().startObject() .startObject("date_field").field("foo", "bar") - .endObject().bytes()).rootDoc(); + .endObject().endObject().bytes()).rootDoc(); fail(); - } catch (MapperParsingException ex) { - // Expected + } catch (Exception ex) { + assertThat(ex, instanceOf(MapperParsingException.class)); } try { docMapper.parse("test", "person", "1", XContentFactory.jsonBuilder().startObject() .startObject("double_field").field("foo", "bar") - .endObject().bytes()).rootDoc(); + .endObject().endObject().bytes()).rootDoc(); fail(); - } catch (MapperParsingException ex) { - // Expected + } catch (Exception ex) { + assertThat(ex, instanceOf(MapperParsingException.class)); } try { docMapper.parse("test", "person", "1", XContentFactory.jsonBuilder().startObject() .startObject("float_field").field("foo", "bar") - .endObject().bytes()).rootDoc(); + .endObject().endObject().bytes()).rootDoc(); fail(); - } catch (MapperParsingException ex) { - // Expected + } catch (Exception ex) { + assertThat(ex, instanceOf(MapperParsingException.class)); } try { docMapper.parse("test", "person", "1", XContentFactory.jsonBuilder().startObject() .startObject("long_field").field("foo", "bar") - .endObject().bytes()).rootDoc(); + .endObject().endObject().bytes()).rootDoc(); fail(); - } catch (MapperParsingException ex) { - // Expected + } catch (Exception ex) { + assertThat(ex, instanceOf(MapperParsingException.class)); } try { docMapper.parse("test", "person", "1", XContentFactory.jsonBuilder().startObject() .startObject("short_field").field("foo", "bar") - .endObject().bytes()).rootDoc(); + .endObject().endObject().bytes()).rootDoc(); fail(); - } catch (MapperParsingException ex) { - // Expected + } catch (Exception ex) { + assertThat(ex, instanceOf(MapperParsingException.class)); } } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/compound/CompoundTypesTests.java b/core/src/test/java/org/elasticsearch/index/mapper/compound/CompoundTypesTests.java index ea66eaa4c5c..79ede4a80cb 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/compound/CompoundTypesTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/compound/CompoundTypesTests.java @@ -57,6 +57,7 @@ public class CompoundTypesTests extends ESSingleNodeTestCase { .startObject() .field("field1", "value1") .field("field2", "value2") + .endObject() .bytes()); assertThat(doc.rootDoc().get("field1"), equalTo("value1")); @@ -67,6 +68,7 @@ public class CompoundTypesTests extends ESSingleNodeTestCase { .startObject() .startObject("field1").field("value", "value1").field("boost", 2.0f).endObject() .field("field2", "value2") + .endObject() .bytes()); assertThat(doc.rootDoc().get("field1"), equalTo("value1")); @@ -77,6 +79,7 @@ public class CompoundTypesTests extends ESSingleNodeTestCase { .startObject() .field("field1", "value1") .field("field2", "value2") + .endObject() .bytes()); assertThat(doc.rootDoc().get("field1"), equalTo("value1")); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/copyto/CopyToMapperIntegrationIT.java b/core/src/test/java/org/elasticsearch/index/mapper/copyto/CopyToMapperIntegrationIT.java index fa98f2a45c4..a65aae4ab20 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/copyto/CopyToMapperIntegrationIT.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/copyto/CopyToMapperIntegrationIT.java @@ -106,7 +106,8 @@ public class CopyToMapperIntegrationIT extends ESIntegTestCase { .field("copy_to", "{name}_raw").endObject() .endObject().endObject() - .endArray(); + .endArray() + .endObject().endObject(); } } diff --git a/core/src/test/java/org/elasticsearch/index/mapper/multifield/MultiFieldTests.java b/core/src/test/java/org/elasticsearch/index/mapper/multifield/MultiFieldTests.java index 70af77513ab..f08e94d243e 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/multifield/MultiFieldTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/multifield/MultiFieldTests.java @@ -241,6 +241,7 @@ public class MultiFieldTests extends ESSingleNodeTestCase { .endObject() .endObject() .endObject() + .endObject() .endObject(); MapperService mapperService = createIndex("test").mapperService(); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/nested/NestedMappingTests.java b/core/src/test/java/org/elasticsearch/index/mapper/nested/NestedMappingTests.java index 1b5245624ce..ddae147a802 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/nested/NestedMappingTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/nested/NestedMappingTests.java @@ -117,7 +117,7 @@ public class NestedMappingTests extends ESSingleNodeTestCase { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") .startObject("nested1").field("type", "nested").startObject("properties") .startObject("nested2").field("type", "nested") - .endObject().endObject() + .endObject().endObject().endObject() .endObject().endObject().endObject().string(); DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)); @@ -168,7 +168,7 @@ public class NestedMappingTests extends ESSingleNodeTestCase { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") .startObject("nested1").field("type", "nested").startObject("properties") .startObject("nested2").field("type", "nested").field("include_in_parent", true) - .endObject().endObject() + .endObject().endObject().endObject() .endObject().endObject().endObject().string(); DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)); @@ -219,7 +219,7 @@ public class NestedMappingTests extends ESSingleNodeTestCase { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") .startObject("nested1").field("type", "nested").field("include_in_parent", true).startObject("properties") .startObject("nested2").field("type", "nested").field("include_in_parent", true) - .endObject().endObject() + .endObject().endObject().endObject() .endObject().endObject().endObject().string(); DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)); @@ -270,7 +270,7 @@ public class NestedMappingTests extends ESSingleNodeTestCase { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") .startObject("nested1").field("type", "nested").startObject("properties") .startObject("nested2").field("type", "nested").field("include_in_root", true) - .endObject().endObject() + .endObject().endObject().endObject() .endObject().endObject().endObject().string(); DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)); @@ -321,7 +321,7 @@ public class NestedMappingTests extends ESSingleNodeTestCase { String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") .startObject("nested1").field("type", "nested").field("dynamic", "strict").startObject("properties") .startObject("field1").field("type", "text") - .endObject().endObject() + .endObject().endObject().endObject() .endObject().endObject().endObject().string(); DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)); @@ -355,7 +355,7 @@ public class NestedMappingTests extends ESSingleNodeTestCase { return XContentFactory.jsonBuilder().startObject().startObject(type).startObject("properties") .startObject("nested1").field("type", "nested").startObject("properties") .startObject("nested2").field("type", "nested") - .endObject().endObject() + .endObject().endObject().endObject() .endObject().endObject().endObject().string(); } catch (IOException e) { throw new UncheckedIOException(e); @@ -390,7 +390,7 @@ public class NestedMappingTests extends ESSingleNodeTestCase { mapperService.merge("type2", new CompressedXContent(mapping.apply("type2")), MergeReason.MAPPING_UPDATE, false); // adding new fields from different type is not ok String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type3").startObject("properties").startObject("nested3") - .field("type", "nested").startObject("properties").endObject().endObject().endObject().endObject().string(); + .field("type", "nested").startObject("properties").endObject().endObject().endObject().endObject().endObject().string(); try { mapperService.merge("type3", new CompressedXContent(mapping2), MergeReason.MAPPING_UPDATE, false); fail("Expected IllegalArgumentException"); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/simple/SimpleMapperTests.java b/core/src/test/java/org/elasticsearch/index/mapper/simple/SimpleMapperTests.java index c6e6d69662a..0f9733c44bb 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/simple/SimpleMapperTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/simple/SimpleMapperTests.java @@ -125,7 +125,7 @@ public class SimpleMapperTests extends ESSingleNodeTestCase { DocumentMapperParser mapperParser = indexService.mapperService().documentMapperParser(); String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties") .startObject("foo.bar").field("type", "text").endObject() - .endObject().endObject().string(); + .endObject().endObject().endObject().string(); try { mapperParser.parse("type", new CompressedXContent(mapping)); fail("Mapping parse should have failed"); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/string/StringFieldMapperPositionIncrementGapTests.java b/core/src/test/java/org/elasticsearch/index/mapper/string/StringFieldMapperPositionIncrementGapTests.java index 680f0732f1f..91a926805bf 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/string/StringFieldMapperPositionIncrementGapTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/string/StringFieldMapperPositionIncrementGapTests.java @@ -136,6 +136,7 @@ public class StringFieldMapperPositionIncrementGapTests extends ESSingleNodeTest XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("properties").startObject("string"); mapping.field("type", "string"); mapping.field("position_increment_gap", positionIncrementGap); + mapping.endObject().endObject().endObject(); client().admin().indices().prepareCreate("test") .setSettings(Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, Version.V_2_3_0).build()) .addMapping("test", mapping) @@ -151,6 +152,7 @@ public class StringFieldMapperPositionIncrementGapTests extends ESSingleNodeTest XContentBuilder mapping = XContentFactory.jsonBuilder().startObject().startObject("properties").startObject("string"); mapping.field("type", "string"); mapping.field("analyzer", analyzer); + mapping.endObject().endObject().endObject(); client().admin().indices().prepareCreate("test") .addMapping("test", mapping) .setSettings(settings) diff --git a/core/src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java b/core/src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java index a0794325bdf..14d86290db4 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/timestamp/TimestampMappingTests.java @@ -69,7 +69,7 @@ public class TimestampMappingTests extends ESSingleNodeTestCase { } public void testSimpleDisabled() throws Exception { - String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().string(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string(); DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)); BytesReference source = XContentFactory.jsonBuilder() .startObject() @@ -104,8 +104,8 @@ public class TimestampMappingTests extends ESSingleNodeTestCase { version = randomVersion(random()); } while (version.before(Version.V_2_0_0_beta1)); for (String mapping : Arrays.asList( - XContentFactory.jsonBuilder().startObject().startObject("type").endObject().string(), - XContentFactory.jsonBuilder().startObject().startObject("type").startObject("_timestamp").endObject().endObject().string())) { + XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string(), + XContentFactory.jsonBuilder().startObject().startObject("type").startObject("_timestamp").endObject().endObject().endObject().string())) { DocumentMapper docMapper = createIndex("test", Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, version).build()).mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)); assertThat(docMapper.timestampFieldMapper().enabled(), equalTo(TimestampFieldMapper.Defaults.ENABLED.enabled)); assertThat(docMapper.timestampFieldMapper().fieldType().stored(), equalTo(version.onOrAfter(Version.V_2_0_0_beta1))); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/ttl/TTLMappingTests.java b/core/src/test/java/org/elasticsearch/index/mapper/ttl/TTLMappingTests.java index 2d28b699944..fe057045882 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/ttl/TTLMappingTests.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/ttl/TTLMappingTests.java @@ -44,7 +44,7 @@ import static org.hamcrest.Matchers.notNullValue; public class TTLMappingTests extends ESSingleNodeTestCase { public void testSimpleDisabled() throws Exception { - String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().string(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string(); DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)); BytesReference source = XContentFactory.jsonBuilder() .startObject() @@ -74,7 +74,7 @@ public class TTLMappingTests extends ESSingleNodeTestCase { } public void testDefaultValues() throws Exception { - String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().string(); + String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").endObject().endObject().string(); DocumentMapper docMapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping)); assertThat(docMapper.TTLFieldMapper().enabled(), equalTo(TTLFieldMapper.Defaults.ENABLED_STATE.enabled)); assertThat(docMapper.TTLFieldMapper().fieldType().stored(), equalTo(TTLFieldMapper.Defaults.TTL_FIELD_TYPE.stored())); diff --git a/core/src/test/java/org/elasticsearch/index/mapper/update/UpdateMappingOnClusterIT.java b/core/src/test/java/org/elasticsearch/index/mapper/update/UpdateMappingOnClusterIT.java index 600f84b5f5f..ed20cdb7e35 100644 --- a/core/src/test/java/org/elasticsearch/index/mapper/update/UpdateMappingOnClusterIT.java +++ b/core/src/test/java/org/elasticsearch/index/mapper/update/UpdateMappingOnClusterIT.java @@ -125,7 +125,7 @@ public class UpdateMappingOnClusterIT extends ESIntegTestCase { } public void testDocValuesInvalidMappingOnUpdate() throws Exception { - String mapping = jsonBuilder().startObject().startObject(TYPE).startObject("properties").startObject("text").field("type", "text").endObject().endObject().endObject().string(); + String mapping = jsonBuilder().startObject().startObject(TYPE).startObject("properties").startObject("text").field("type", "text").endObject().endObject().endObject().endObject().string(); prepareCreate(INDEX).addMapping(TYPE, mapping).get(); String mappingUpdate = jsonBuilder().startObject().startObject(TYPE).startObject("_all").startObject("fielddata").field("format", "doc_values").endObject().endObject().endObject().endObject().string(); GetMappingsResponse mappingsBeforeUpdateResponse = client().admin().indices().prepareGetMappings(INDEX).addTypes(TYPE).get(); diff --git a/core/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java index e4b0a6893ac..91a42d70809 100644 --- a/core/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilderTests.java @@ -121,6 +121,7 @@ public class MoreLikeThisQueryBuilderTests extends AbstractQueryTestCase indexingRequests = new ArrayList<>(); diff --git a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SearchFieldsTests.java b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SearchFieldsTests.java index 8cecbf2c787..4e3accfdc06 100644 --- a/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SearchFieldsTests.java +++ b/modules/lang-groovy/src/test/java/org/elasticsearch/messy/tests/SearchFieldsTests.java @@ -484,15 +484,32 @@ public class SearchFieldsTests extends ESIntegTestCase { public void testGetFieldsComplexField() throws Exception { client().admin().indices().prepareCreate("my-index") .setSettings(Settings.builder().put("index.refresh_interval", -1)) - .addMapping("my-type2", jsonBuilder().startObject().startObject("my-type2").startObject("properties") - .startObject("field1").field("type", "object").startObject("properties") - .startObject("field2").field("type", "object").startObject("properties") - .startObject("field3").field("type", "object").startObject("properties") - .startObject("field4").field("type", "text").field("store", true) - .endObject().endObject() - .endObject().endObject() - .endObject().endObject() - .endObject().endObject().endObject()) + .addMapping("my-type2", jsonBuilder() + .startObject() + .startObject("my-type2") + .startObject("properties") + .startObject("field1") + .field("type", "object") + .startObject("properties") + .startObject("field2") + .field("type", "object") + .startObject("properties") + .startObject("field3") + .field("type", "object") + .startObject("properties") + .startObject("field4") + .field("type", "text") + .field("store", true) + .endObject() + .endObject() + .endObject() + .endObject() + .endObject() + .endObject() + .endObject() + .endObject() + .endObject() + .endObject()) .get(); BytesReference source = jsonBuilder().startObject() diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/MultiPercolatorIT.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/MultiPercolatorIT.java index efa6ecee59a..c45af9c089b 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/MultiPercolatorIT.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/MultiPercolatorIT.java @@ -235,7 +235,7 @@ public class MultiPercolatorIT extends ESIntegTestCase { } client().prepareIndex(INDEX_NAME, "type", "1") - .setSource(jsonBuilder().startObject().field("field", "a")) + .setSource(jsonBuilder().startObject().field("field", "a").endObject()) .execute().actionGet(); refresh(); diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorIT.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorIT.java index e4b318f5d39..ed9b65130a9 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorIT.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorIT.java @@ -1489,6 +1489,7 @@ public class PercolatorIT extends ESIntegTestCase { XContentBuilder doc = jsonBuilder(); doc.startObject(); doc.field("some_unnested_field", "value"); + doc.endObject(); PercolateResponse response = preparePercolate(client()).setPercolateDoc(new PercolateSourceBuilder.DocBuilder().setDoc(doc)).setIndices(INDEX_NAME).setDocumentType("company").get(); assertNoFailures(response); } diff --git a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java index aba81575b37..a277549f48e 100644 --- a/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java +++ b/modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchIT.java @@ -61,32 +61,32 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { ); client().prepareIndex("test", "queries", "1") - .setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject()) - .get(); + .setSource(jsonBuilder().startObject().field("query", matchAllQuery()).endObject()) + .get(); client().prepareIndex("test", "queries", "2") - .setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "value")).endObject()) - .get(); + .setSource(jsonBuilder().startObject().field("query", matchQuery("field1", "value")).endObject()) + .get(); client().prepareIndex("test", "queries", "3") - .setSource(jsonBuilder().startObject().field("query", boolQuery() - .must(matchQuery("field1", "value")) - .must(matchQuery("field2", "value")) - ).endObject()).get(); + .setSource(jsonBuilder().startObject().field("query", boolQuery() + .must(matchQuery("field1", "value")) + .must(matchQuery("field2", "value")) + ).endObject()).get(); client().admin().indices().prepareRefresh().get(); BytesReference source = jsonBuilder().startObject().endObject().bytes(); logger.info("percolating empty doc"); SearchResponse response = client().prepareSearch() - .setQuery(new PercolateQueryBuilder("query", "type", source)) - .get(); + .setQuery(new PercolateQueryBuilder("query", "type", source)) + .get(); assertHitCount(response, 1); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); source = jsonBuilder().startObject().field("field1", "value").endObject().bytes(); logger.info("percolating doc with 1 field"); response = client().prepareSearch() - .setQuery(new PercolateQueryBuilder("query", "type", source)) - .addSort("_uid", SortOrder.ASC) - .get(); + .setQuery(new PercolateQueryBuilder("query", "type", source)) + .addSort("_uid", SortOrder.ASC) + .get(); assertHitCount(response, 2); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); assertThat(response.getHits().getAt(1).getId(), equalTo("2")); @@ -94,9 +94,9 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { source = jsonBuilder().startObject().field("field1", "value").field("field2", "value").endObject().bytes(); logger.info("percolating doc with 2 fields"); response = client().prepareSearch() - .setQuery(new PercolateQueryBuilder("query", "type", source)) - .addSort("_uid", SortOrder.ASC) - .get(); + .setQuery(new PercolateQueryBuilder("query", "type", source)) + .addSort("_uid", SortOrder.ASC) + .get(); assertHitCount(response, 3); assertThat(response.getHits().getAt(0).getId(), equalTo("1")); assertThat(response.getHits().getAt(1).getId(), equalTo("2")); @@ -314,6 +314,7 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { .endObject() .endObject() .endObject() + .endObject() .endObject().endObject()) ); } @@ -327,12 +328,13 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { .addMapping("doc_type", "field", "type=keyword") .addMapping("query_type", jsonBuilder().startObject().startObject("query_type").startObject("properties") .startObject("object_field") - .field("type", "object") - .startObject("properties") - .startObject(queryFieldName) - .field("type", "percolator") - .endObject() - .endObject() + .field("type", "object") + .startObject("properties") + .startObject(queryFieldName) + .field("type", "percolator") + .endObject() + .endObject() + .endObject() .endObject() .endObject().endObject()) ); @@ -344,7 +346,7 @@ public class PercolatorQuerySearchIT extends ESSingleNodeTestCase { client().prepareIndex("test2", "query_type", "1") .setSource(jsonBuilder().startObject().startObject("object_field") .field(queryFieldName, matchQuery("field", "value")) - .endObject().endObject()) + .endObject().endObject()) .get(); client().admin().indices().prepareRefresh().get(); diff --git a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/SimpleAttachmentMapperTests.java b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/SimpleAttachmentMapperTests.java index fd5f480700c..8c86800e52b 100644 --- a/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/SimpleAttachmentMapperTests.java +++ b/plugins/mapper-attachments/src/test/java/org/elasticsearch/mapper/attachments/SimpleAttachmentMapperTests.java @@ -113,6 +113,7 @@ public class SimpleAttachmentMapperTests extends AttachmentUnitTestCase { .endObject() .endObject() .endObject() + .endObject() .endObject(); byte[] mapping = mappingBuilder.bytes().toBytes(); diff --git a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java index 996ac964a38..b6c341c0601 100644 --- a/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java +++ b/plugins/mapper-size/src/test/java/org/elasticsearch/index/mapper/size/SizeMappingIT.java @@ -56,7 +56,7 @@ public class SizeMappingIT extends ESIntegTestCase { assertSizeMappingEnabled(index, type, true); // update some field in the mapping - XContentBuilder updateMappingBuilder = jsonBuilder().startObject().startObject("properties").startObject("otherField").field("type", "text").endObject().endObject(); + XContentBuilder updateMappingBuilder = jsonBuilder().startObject().startObject("properties").startObject("otherField").field("type", "text").endObject().endObject().endObject(); PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping(index).setType(type).setSource(updateMappingBuilder).get(); assertAcked(putMappingResponse);