Search in sources :

Example 91 with CompressedXContent

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"));
}
Also used : IndexService(org.elasticsearch.index.IndexService) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 92 with CompressedXContent

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);
}
Also used : IndexService(org.elasticsearch.index.IndexService) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent)

Example 93 with CompressedXContent

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"));
}
Also used : XContentFactory(org.elasticsearch.common.xcontent.XContentFactory) KeywordFieldType(org.elasticsearch.index.mapper.KeywordFieldMapper.KeywordFieldType) ESSingleNodeTestCase(org.elasticsearch.test.ESSingleNodeTestCase) Arrays(java.util.Arrays) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NumberFieldType(org.elasticsearch.index.mapper.NumberFieldMapper.NumberFieldType) XContentType(org.elasticsearch.common.xcontent.XContentType) IndexService(org.elasticsearch.index.IndexService) IOException(java.io.IOException) HashMap(java.util.HashMap) Function(java.util.function.Function) Matchers.startsWith(org.hamcrest.Matchers.startsWith) BytesArray(org.elasticsearch.common.bytes.BytesArray) UncheckedIOException(java.io.UncheckedIOException) HashSet(java.util.HashSet) ExecutionException(java.util.concurrent.ExecutionException) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) ExceptionsHelper(org.elasticsearch.ExceptionsHelper) Settings(org.elasticsearch.common.settings.Settings) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Map(java.util.Map) MergeReason(org.elasticsearch.index.mapper.MapperService.MergeReason) Collections(java.util.Collections) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 94 with CompressedXContent

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."));
    }
}
Also used : CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 95 with CompressedXContent

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());
}
Also used : CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IOException(java.io.IOException)

Aggregations

CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)366 Matchers.containsString (org.hamcrest.Matchers.containsString)223 IndexableField (org.apache.lucene.index.IndexableField)75 BytesReference (org.elasticsearch.common.bytes.BytesReference)62 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)51 IndexService (org.elasticsearch.index.IndexService)49 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)46 Settings (org.elasticsearch.common.settings.Settings)25 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)19 BytesRef (org.apache.lucene.util.BytesRef)18 BytesArray (org.elasticsearch.common.bytes.BytesArray)16 MapperParsingException (org.elasticsearch.index.mapper.MapperParsingException)16 IOException (java.io.IOException)15 DocumentMapperParser (org.elasticsearch.index.mapper.DocumentMapperParser)15 Map (java.util.Map)13 Document (org.elasticsearch.index.mapper.ParseContext.Document)13 MapperService (org.elasticsearch.index.mapper.MapperService)12 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)10 IndexTemplateMetadata (org.elasticsearch.cluster.metadata.IndexTemplateMetadata)9 FieldMapper (org.elasticsearch.index.mapper.FieldMapper)9