Disable XContent auto closing of object and arrays
This commit is contained in:
parent
de6b4f35b1
commit
bdee8c2632
|
@ -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()) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -99,7 +99,9 @@ public class RestFieldStatsAction extends BaseRestHandler {
|
|||
for (Map.Entry<String, String> entry : response.getConflicts().entrySet()) {
|
||||
builder.field(entry.getKey(), entry.getValue());
|
||||
}
|
||||
builder.endObject();
|
||||
}
|
||||
builder.endObject();
|
||||
return new BytesRestResponse(RestStatus.OK, builder);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -106,7 +106,8 @@ public class CopyToMapperIntegrationIT extends ESIntegTestCase {
|
|||
.field("copy_to", "{name}_raw").endObject()
|
||||
.endObject().endObject()
|
||||
|
||||
.endArray();
|
||||
.endArray()
|
||||
.endObject().endObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -241,6 +241,7 @@ public class MultiFieldTests extends ESSingleNodeTestCase {
|
|||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject();
|
||||
|
||||
MapperService mapperService = createIndex("test").mapperService();
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -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()));
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -121,6 +121,7 @@ public class MoreLikeThisQueryBuilderTests extends AbstractQueryTestCase<MoreLik
|
|||
for (String field : randomFields) {
|
||||
doc.field(field, randomAsciiOfLength(10));
|
||||
}
|
||||
doc.endObject();
|
||||
} catch (IOException e) {
|
||||
throw new ElasticsearchException("Unable to generate random artificial doc!");
|
||||
}
|
||||
|
|
|
@ -240,6 +240,7 @@ public class SimilarityTests extends ESSingleNodeTestCase {
|
|||
.field("type", "text")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().string();
|
||||
Settings settings = Settings.builder()
|
||||
.put(IndexMetaData.SETTING_VERSION_CREATED, VersionUtils.randomVersionBetween(random(), Version.V_2_0_0, Version.V_2_2_0))
|
||||
|
|
|
@ -225,25 +225,26 @@ public class AggregatorParsingTests extends ESTestCase {
|
|||
public void testTwoAggs() throws Exception {
|
||||
String source = JsonXContent.contentBuilder()
|
||||
.startObject()
|
||||
.startObject("by_date")
|
||||
.startObject("date_histogram")
|
||||
.field("field", "timestamp")
|
||||
.field("interval", "month")
|
||||
.endObject()
|
||||
.startObject("aggs")
|
||||
.startObject("tag_count")
|
||||
.startObject("cardinality")
|
||||
.field("field", "tag")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.startObject("aggs") // 2nd "aggs": illegal
|
||||
.startObject("tag_count2")
|
||||
.startObject("cardinality")
|
||||
.field("field", "tag")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.startObject("by_date")
|
||||
.startObject("date_histogram")
|
||||
.field("field", "timestamp")
|
||||
.field("interval", "month")
|
||||
.endObject()
|
||||
.startObject("aggs")
|
||||
.startObject("tag_count")
|
||||
.startObject("cardinality")
|
||||
.field("field", "tag")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.startObject("aggs") // 2nd "aggs": illegal
|
||||
.startObject("tag_count2")
|
||||
.startObject("cardinality")
|
||||
.field("field", "tag")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().string();
|
||||
try {
|
||||
XContentParser parser = XContentFactory.xContent(source).createParser(source);
|
||||
|
@ -274,14 +275,15 @@ public class AggregatorParsingTests extends ESTestCase {
|
|||
|
||||
String source = JsonXContent.contentBuilder()
|
||||
.startObject()
|
||||
.startObject(name)
|
||||
.startObject("filter")
|
||||
.startObject("range")
|
||||
.startObject("stock")
|
||||
.field("gt", 0)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.startObject(name)
|
||||
.startObject("filter")
|
||||
.startObject("range")
|
||||
.startObject("stock")
|
||||
.field("gt", 0)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().string();
|
||||
try {
|
||||
XContentParser parser = XContentFactory.xContent(source).createParser(source);
|
||||
|
@ -323,19 +325,20 @@ public class AggregatorParsingTests extends ESTestCase {
|
|||
public void testMissingName() throws Exception {
|
||||
String source = JsonXContent.contentBuilder()
|
||||
.startObject()
|
||||
.startObject("by_date")
|
||||
.startObject("date_histogram")
|
||||
.field("field", "timestamp")
|
||||
.field("interval", "month")
|
||||
.endObject()
|
||||
.startObject("aggs")
|
||||
// the aggregation name is missing
|
||||
//.startObject("tag_count")
|
||||
.startObject("cardinality")
|
||||
.field("field", "tag")
|
||||
.endObject()
|
||||
//.endObject()
|
||||
.endObject()
|
||||
.startObject("by_date")
|
||||
.startObject("date_histogram")
|
||||
.field("field", "timestamp")
|
||||
.field("interval", "month")
|
||||
.endObject()
|
||||
.startObject("aggs")
|
||||
// the aggregation name is missing
|
||||
//.startObject("tag_count")
|
||||
.startObject("cardinality")
|
||||
.field("field", "tag")
|
||||
.endObject()
|
||||
//.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().string();
|
||||
try {
|
||||
XContentParser parser = XContentFactory.xContent(source).createParser(source);
|
||||
|
@ -351,19 +354,20 @@ public class AggregatorParsingTests extends ESTestCase {
|
|||
public void testMissingType() throws Exception {
|
||||
String source = JsonXContent.contentBuilder()
|
||||
.startObject()
|
||||
.startObject("by_date")
|
||||
.startObject("date_histogram")
|
||||
.field("field", "timestamp")
|
||||
.field("interval", "month")
|
||||
.endObject()
|
||||
.startObject("aggs")
|
||||
.startObject("tag_count")
|
||||
// the aggregation type is missing
|
||||
//.startObject("cardinality")
|
||||
.field("field", "tag")
|
||||
//.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.startObject("by_date")
|
||||
.startObject("date_histogram")
|
||||
.field("field", "timestamp")
|
||||
.field("interval", "month")
|
||||
.endObject()
|
||||
.startObject("aggs")
|
||||
.startObject("tag_count")
|
||||
// the aggregation type is missing
|
||||
//.startObject("cardinality")
|
||||
.field("field", "tag")
|
||||
//.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().string();
|
||||
try {
|
||||
XContentParser parser = XContentFactory.xContent(source).createParser(source);
|
||||
|
|
|
@ -40,6 +40,7 @@ public class ParentIdAggIT extends ESIntegTestCase {
|
|||
.startObject("_parent")
|
||||
.field("type", "parenttype")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject();
|
||||
assertAcked(prepareCreate("testidx").addMapping("childtype", mapping));
|
||||
client().prepareIndex("testidx", "childtype").setSource(jsonBuilder().startObject().field("num", 1).endObject()).setParent("p1").get();
|
||||
|
|
|
@ -199,6 +199,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
.field("type", "text")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject())
|
||||
.setSettings(Settings.builder()
|
||||
.put(indexSettings())
|
||||
|
@ -828,7 +829,7 @@ public class HighlighterSearchIT extends ESIntegTestCase {
|
|||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()));
|
||||
.endObject().endObject().endObject()));
|
||||
ensureGreen();
|
||||
|
||||
index("test", "type1", "1",
|
||||
|
|
|
@ -179,7 +179,7 @@ public class MoreLikeThisIT extends ESIntegTestCase {
|
|||
.endObject().endObject().string();
|
||||
client().admin().indices().prepareCreate("foo").addMapping("bar", mapping).execute().actionGet();
|
||||
client().prepareIndex("foo", "bar", "1")
|
||||
.setSource(jsonBuilder().startObject().startObject("foo").field("bar", "boz").endObject())
|
||||
.setSource(jsonBuilder().startObject().startObject("foo").field("bar", "boz").endObject().endObject())
|
||||
.execute().actionGet();
|
||||
client().admin().indices().prepareRefresh("foo").execute().actionGet();
|
||||
assertThat(ensureGreen(), equalTo(ClusterHealthStatus.GREEN));
|
||||
|
@ -204,7 +204,7 @@ public class MoreLikeThisIT extends ESIntegTestCase {
|
|||
ensureGreen();
|
||||
|
||||
client().prepareIndex("foo", "bar", "1")
|
||||
.setSource(jsonBuilder().startObject().startObject("foo").field("bar", "boz").endObject())
|
||||
.setSource(jsonBuilder().startObject().startObject("foo").field("bar", "boz").endObject().endObject())
|
||||
.setRouting("2")
|
||||
.execute().actionGet();
|
||||
client().admin().indices().prepareRefresh("foo").execute().actionGet();
|
||||
|
@ -227,7 +227,7 @@ public class MoreLikeThisIT extends ESIntegTestCase {
|
|||
ensureGreen();
|
||||
|
||||
client().prepareIndex("foo", "bar", "1")
|
||||
.setSource(jsonBuilder().startObject().startObject("foo").field("bar", "boz").endObject())
|
||||
.setSource(jsonBuilder().startObject().startObject("foo").field("bar", "boz").endObject().endObject())
|
||||
.setRouting("4000")
|
||||
.execute().actionGet();
|
||||
client().admin().indices().prepareRefresh("foo").execute().actionGet();
|
||||
|
@ -522,17 +522,6 @@ public class MoreLikeThisIT extends ESIntegTestCase {
|
|||
assertSearchResponse(response);
|
||||
assertHitCount(response, 0);
|
||||
|
||||
logger.info("Checking when document is malformed ...");
|
||||
XContentBuilder malformedDoc = jsonBuilder().startObject();
|
||||
mltQuery = moreLikeThisQuery(null, new Item[] {new Item("test", "type1", malformedDoc)})
|
||||
.minTermFreq(0)
|
||||
.minDocFreq(0)
|
||||
.minimumShouldMatch("0%");
|
||||
response = client().prepareSearch("test").setTypes("type1")
|
||||
.setQuery(mltQuery).get();
|
||||
assertSearchResponse(response);
|
||||
assertHitCount(response, 0);
|
||||
|
||||
logger.info("Checking the document matches otherwise ...");
|
||||
XContentBuilder normalDoc = jsonBuilder()
|
||||
.startObject()
|
||||
|
|
|
@ -1711,7 +1711,8 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|||
public void testAllDisabledButQueried() throws Exception {
|
||||
createIndex("myindex");
|
||||
assertAcked(client().admin().indices().preparePutMapping("myindex").setType("mytype").setSource(
|
||||
jsonBuilder().startObject().startObject("mytype").startObject("_all").field("enabled", false)));
|
||||
jsonBuilder().startObject().startObject("mytype").startObject("_all").field("enabled", false)
|
||||
.endObject().endObject().endObject()));
|
||||
client().prepareIndex("myindex", "mytype").setId("1").setSource("bar", "foo").setRefresh(true).get();
|
||||
SearchResponse response = client().prepareSearch("myindex").setQuery(matchQuery("_all", "foo")).get();
|
||||
assertNoFailures(response);
|
||||
|
|
|
@ -193,6 +193,7 @@ public class ContextSuggestSearch2xIT extends ESIntegTestCase {
|
|||
.field("type", "geo")
|
||||
.field("precision", precision)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().endObject()
|
||||
.endObject().endObject();
|
||||
|
||||
|
@ -212,6 +213,7 @@ public class ContextSuggestSearch2xIT extends ESIntegTestCase {
|
|||
.field("type", "geo")
|
||||
.field("precision", precision)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject().endObject()
|
||||
.endObject().endObject();
|
||||
assertAcked(client().admin().indices().preparePutMapping(INDEX).setType(TYPE).setSource(mapping.string()).get());
|
||||
|
|
|
@ -142,21 +142,22 @@ public class GeoContextMappingTests extends ESSingleNodeTestCase {
|
|||
MappedFieldType completionFieldType = fieldMapper.fieldType();
|
||||
ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("completion")
|
||||
.field("input", "suggestion5", "suggestion6", "suggestion7")
|
||||
.startObject("contexts")
|
||||
.startArray("ctx")
|
||||
.startObject()
|
||||
.field("lat", 43.6624803)
|
||||
.field("lon", -79.3863353)
|
||||
.endObject()
|
||||
.startObject()
|
||||
.field("lat", 43.6624718)
|
||||
.field("lon", -79.3873227)
|
||||
.endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.field("weight", 5)
|
||||
.startObject("completion")
|
||||
.field("input", "suggestion5", "suggestion6", "suggestion7")
|
||||
.startObject("contexts")
|
||||
.startArray("ctx")
|
||||
.startObject()
|
||||
.field("lat", 43.6624803)
|
||||
.field("lon", -79.3863353)
|
||||
.endObject()
|
||||
.startObject()
|
||||
.field("lat", 43.6624718)
|
||||
.field("lon", -79.3873227)
|
||||
.endObject()
|
||||
.endArray()
|
||||
.endObject()
|
||||
.field("weight", 5)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.bytes());
|
||||
IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
|
||||
|
|
|
@ -47,6 +47,7 @@ public class SimilarityIT extends ESIntegTestCase {
|
|||
.startObject("field2")
|
||||
.field("similarity", "classic")
|
||||
.field("type", "text")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject())
|
||||
|
|
|
@ -102,7 +102,7 @@ public class SimpleTimestampIT extends ESIntegTestCase {
|
|||
assertTimestampMappingEnabled(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);
|
||||
|
||||
|
|
|
@ -214,7 +214,7 @@ public class SimpleTTLIT extends ESIntegTestCase {
|
|||
assertTTLMappingEnabled(index, type);
|
||||
|
||||
// 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);
|
||||
|
||||
|
|
|
@ -184,25 +184,27 @@ public class EquivalenceTests extends ESIntegTestCase {
|
|||
final IntHashSet valuesSet = new IntHashSet();
|
||||
cluster().wipeIndices("idx");
|
||||
prepareCreate("idx")
|
||||
.addMapping("type", jsonBuilder().startObject()
|
||||
.startObject("type")
|
||||
.startObject("properties")
|
||||
.startObject("string_values")
|
||||
.field("type", "keyword")
|
||||
.startObject("fields")
|
||||
.startObject("doc_values")
|
||||
.field("type", "keyword")
|
||||
.field("index", false)
|
||||
.addMapping("type", jsonBuilder()
|
||||
.startObject()
|
||||
.startObject("type")
|
||||
.startObject("properties")
|
||||
.startObject("string_values")
|
||||
.field("type", "keyword")
|
||||
.startObject("fields")
|
||||
.startObject("doc_values")
|
||||
.field("type", "keyword")
|
||||
.field("index", false)
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.startObject("long_values")
|
||||
.field("type", "long")
|
||||
.endObject()
|
||||
.startObject("double_values")
|
||||
.field("type", "double")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.startObject("long_values")
|
||||
.field("type", "long")
|
||||
.endObject()
|
||||
.startObject("double_values")
|
||||
.field("type", "double")
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()).execute().actionGet();
|
||||
|
||||
List<IndexRequestBuilder> indexingRequests = new ArrayList<>();
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -113,6 +113,7 @@ public class SimpleAttachmentMapperTests extends AttachmentUnitTestCase {
|
|||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject()
|
||||
.endObject();
|
||||
|
||||
byte[] mapping = mappingBuilder.bytes().toBytes();
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue