use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class PercolatorFieldMapperTests method addQueryMapping.
private void addQueryMapping() throws Exception {
typeName = randomAsciiOfLength(4);
fieldName = randomAsciiOfLength(4);
String percolatorMapper = XContentFactory.jsonBuilder().startObject().startObject(typeName).startObject("properties").startObject(fieldName).field("type", "percolator").endObject().endObject().endObject().endObject().string();
mapperService.merge(typeName, new CompressedXContent(percolatorMapper), MapperService.MergeReason.MAPPING_UPDATE, true);
fieldType = (PercolatorFieldMapper.FieldType) mapperService.fullName(fieldName);
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class Murmur3FieldMapperTests method testDocValuesSettingNotAllowed.
public void testDocValuesSettingNotAllowed() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "murmur3").field("doc_values", false).endObject().endObject().endObject().endObject().string();
try {
parser.parse("type", new CompressedXContent(mapping));
fail("expected a mapper parsing exception");
} catch (MapperParsingException e) {
assertTrue(e.getMessage().contains("Setting [doc_values] cannot be modified"));
}
// even setting to the default is not allowed, the setting is invalid
mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "murmur3").field("doc_values", true).endObject().endObject().endObject().endObject().string();
try {
parser.parse("type", new CompressedXContent(mapping));
fail("expected a mapper parsing exception");
} catch (MapperParsingException e) {
assertTrue(e.getMessage().contains("Setting [doc_values] cannot be modified"));
}
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class Murmur3FieldMapperTests method testIndexSettingNotAllowed.
public void testIndexSettingNotAllowed() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "murmur3").field("index", "not_analyzed").endObject().endObject().endObject().endObject().string();
try {
parser.parse("type", new CompressedXContent(mapping));
fail("expected a mapper parsing exception");
} catch (MapperParsingException e) {
assertTrue(e.getMessage().contains("Setting [index] cannot be modified"));
}
// even setting to the default is not allowed, the setting is invalid
mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "murmur3").field("index", "no").endObject().endObject().endObject().endObject().string();
try {
parser.parse("type", new CompressedXContent(mapping));
fail("expected a mapper parsing exception");
} catch (MapperParsingException e) {
assertTrue(e.getMessage().contains("Setting [index] cannot be modified"));
}
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class Murmur3FieldMapperTests method testEmptyName.
public void testEmptyName() throws Exception {
String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("").field("type", "murmur3").endObject().endObject().endObject().endObject().string();
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> parser.parse("type", new CompressedXContent(mapping)));
assertThat(e.getMessage(), containsString("name cannot be empty string"));
// before 5.x
Version oldVersion = VersionUtils.randomVersionBetween(getRandom(), Version.V_2_0_0, Version.V_2_3_5);
Settings oldIndexSettings = Settings.builder().put(IndexMetaData.SETTING_VERSION_CREATED, oldVersion).build();
IndexService indexService2x = createIndex("test_old", oldIndexSettings);
Supplier<QueryShardContext> queryShardContext = () -> {
return indexService2x.newQueryShardContext(0, null, () -> {
throw new UnsupportedOperationException();
});
};
DocumentMapperParser parser = new DocumentMapperParser(indexService2x.getIndexSettings(), indexService2x.mapperService(), indexService2x.getIndexAnalyzers(), indexService2x.xContentRegistry(), indexService2x.similarityService(), mapperRegistry, queryShardContext);
DocumentMapper defaultMapper = parser.parse("type", new CompressedXContent(mapping));
assertEquals(mapping, defaultMapper.mappingSource().string());
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class SizeMappingTests method testThatDisablingWorksWhenMerging.
public void testThatDisablingWorksWhenMerging() throws Exception {
IndexService service = createIndex("test", Settings.EMPTY, "type", "_size", "enabled=true");
DocumentMapper docMapper = service.mapperService().documentMapper("type");
assertThat(docMapper.metadataMapper(SizeFieldMapper.class).enabled(), is(true));
String disabledMapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("_size").field("enabled", false).endObject().endObject().endObject().string();
docMapper = service.mapperService().merge("type", new CompressedXContent(disabledMapping), MapperService.MergeReason.MAPPING_UPDATE, false);
assertThat(docMapper.metadataMapper(SizeFieldMapper.class).enabled(), is(false));
}
Aggregations