use of org.elasticsearch.index.IndexService in project elasticsearch by elastic.
the class DocumentParserTests method testNoDocumentSent.
public void testNoDocumentSent() throws Exception {
IndexService indexService = createIndex("test");
DocumentMapper docMapper = new DocumentMapper.Builder(new RootObjectMapper.Builder("person").add(new ObjectMapper.Builder("name").add(new TextFieldMapper.Builder("first").store(true).index(false))), indexService.mapperService()).build(indexService.mapperService());
BytesReference json = new BytesArray("".getBytes(StandardCharsets.UTF_8));
try {
docMapper.parse("test", "person", "1", json).rootDoc();
fail("this point is never reached");
} catch (MapperParsingException e) {
assertThat(e.getMessage(), equalTo("failed to parse, document is empty"));
}
}
use of org.elasticsearch.index.IndexService 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.index.IndexService 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.index.IndexService in project elasticsearch by elastic.
the class MapperServiceTests method testMergeWithMap.
public void testMergeWithMap() throws Throwable {
IndexService indexService1 = createIndex("index1");
MapperService mapperService = indexService1.mapperService();
Map<String, Map<String, Object>> mappings = new HashMap<>();
mappings.put(MapperService.DEFAULT_MAPPING, MapperService.parseMapping(xContentRegistry(), "{}"));
MapperException e = expectThrows(MapperParsingException.class, () -> mapperService.merge(mappings, MergeReason.MAPPING_UPDATE, false));
assertThat(e.getMessage(), startsWith("Failed to parse mapping [" + MapperService.DEFAULT_MAPPING + "]: "));
mappings.clear();
mappings.put("type1", MapperService.parseMapping(xContentRegistry(), "{}"));
e = expectThrows(MapperParsingException.class, () -> mapperService.merge(mappings, MergeReason.MAPPING_UPDATE, false));
assertThat(e.getMessage(), startsWith("Failed to parse mapping [type1]: "));
}
use of org.elasticsearch.index.IndexService in project elasticsearch by elastic.
the class MapperServiceTests method testIndexIntoDefaultMapping.
public void testIndexIntoDefaultMapping() throws Throwable {
// 1. test implicit index creation
ExecutionException e = expectThrows(ExecutionException.class, () -> {
client().prepareIndex("index1", MapperService.DEFAULT_MAPPING, "1").setSource("{}", XContentType.JSON).execute().get();
});
Throwable throwable = ExceptionsHelper.unwrapCause(e.getCause());
if (throwable instanceof IllegalArgumentException) {
assertEquals("It is forbidden to index into the default mapping [_default_]", throwable.getMessage());
} else {
throw e;
}
// 2. already existing index
IndexService indexService = createIndex("index2");
e = expectThrows(ExecutionException.class, () -> {
client().prepareIndex("index1", MapperService.DEFAULT_MAPPING, "2").setSource().execute().get();
});
throwable = ExceptionsHelper.unwrapCause(e.getCause());
if (throwable instanceof IllegalArgumentException) {
assertEquals("It is forbidden to index into the default mapping [_default_]", throwable.getMessage());
} else {
throw e;
}
assertFalse(indexService.mapperService().hasMapping(MapperService.DEFAULT_MAPPING));
}
Aggregations