use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class MapperServiceTests method testAllEnabled.
public void testAllEnabled() throws Exception {
IndexService indexService = createIndex("test");
assertFalse(indexService.mapperService().allEnabled());
CompressedXContent enabledAll = new CompressedXContent(XContentFactory.jsonBuilder().startObject().startObject("_all").field("enabled", true).endObject().endObject().bytes());
CompressedXContent disabledAll = new CompressedXContent(XContentFactory.jsonBuilder().startObject().startObject("_all").field("enabled", false).endObject().endObject().bytes());
Exception e = expectThrows(MapperParsingException.class, () -> indexService.mapperService().merge(MapperService.DEFAULT_MAPPING, enabledAll, MergeReason.MAPPING_UPDATE, random().nextBoolean()));
assertThat(e.getMessage(), containsString("[_all] is disabled in 6.0"));
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class MapperServiceTests method testOtherDocumentMappersOnlyUpdatedWhenChangingFieldType.
public void testOtherDocumentMappersOnlyUpdatedWhenChangingFieldType() throws IOException {
IndexService indexService = createIndex("test");
CompressedXContent simpleMapping = new CompressedXContent(XContentFactory.jsonBuilder().startObject().startObject("properties").startObject("field").field("type", "text").endObject().endObject().endObject().bytes());
indexService.mapperService().merge("type1", simpleMapping, MergeReason.MAPPING_UPDATE, true);
DocumentMapper documentMapper = indexService.mapperService().documentMapper("type1");
indexService.mapperService().merge("type2", simpleMapping, MergeReason.MAPPING_UPDATE, true);
assertSame(indexService.mapperService().documentMapper("type1"), documentMapper);
CompressedXContent normsDisabledMapping = new CompressedXContent(XContentFactory.jsonBuilder().startObject().startObject("properties").startObject("field").field("type", "text").field("norms", false).endObject().endObject().endObject().bytes());
indexService.mapperService().merge("type3", normsDisabledMapping, MergeReason.MAPPING_UPDATE, true);
assertNotSame(indexService.mapperService().documentMapper("type1"), documentMapper);
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class MapperServiceTests method testTotalFieldsExceedsLimit.
public void testTotalFieldsExceedsLimit() throws Throwable {
Function<String, String> mapping = type -> {
try {
return XContentFactory.jsonBuilder().startObject().startObject(type).startObject("properties").startObject("field1").field("type", "keyword").endObject().endObject().endObject().endObject().string();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
};
createIndex("test1").mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_UPDATE, false);
//set total number of fields to 1 to trigger an exception
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> {
createIndex("test2", Settings.builder().put(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey(), 1).build()).mapperService().merge("type", new CompressedXContent(mapping.apply("type")), MergeReason.MAPPING_UPDATE, false);
});
assertTrue(e.getMessage(), e.getMessage().contains("Limit of total fields [1] in index [test2] has been exceeded"));
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class MultiFieldCopyToMapperTests method testExceptionForCopyToInMultiFields.
public void testExceptionForCopyToInMultiFields() throws IOException {
XContentBuilder mapping = createMappinmgWithCopyToInMultiField();
// first check that for newer versions we throw exception if copy_to is found withing multi field
MapperService mapperService = MapperTestUtils.newMapperService(xContentRegistry(), createTempDir(), Settings.EMPTY);
try {
mapperService.parse("type", new CompressedXContent(mapping.string()), true);
fail("Parsing should throw an exception because the mapping contains a copy_to in a multi field");
} catch (MapperParsingException e) {
assertThat(e.getMessage(), equalTo("copy_to in multi fields is not allowed. Found the copy_to in field [c] which is within a multi field."));
}
}
use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.
the class MultiFieldIncludeInAllMapperTests method testExceptionForIncludeInAllInMultiFields.
public void testExceptionForIncludeInAllInMultiFields() throws IOException {
XContentBuilder mapping = createMappingWithIncludeInAllInMultiField();
// first check that for newer versions we throw exception if include_in_all is found withing multi field
MapperService mapperService = MapperTestUtils.newMapperService(xContentRegistry(), createTempDir(), Settings.EMPTY);
Exception e = expectThrows(MapperParsingException.class, () -> mapperService.parse("type", new CompressedXContent(mapping.string()), true));
assertEquals("include_in_all in multi fields is not allowed. Found the include_in_all in field [c] which is within a multi field.", e.getMessage());
}
Aggregations