Search in sources :

Example 11 with CompressedXContent

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

Example 12 with CompressedXContent

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"));
    }
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 13 with CompressedXContent

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"));
    }
}
Also used : MapperParsingException(org.elasticsearch.index.mapper.MapperParsingException) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 14 with CompressedXContent

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());
}
Also used : Version(org.elasticsearch.Version) IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) QueryShardContext(org.elasticsearch.index.query.QueryShardContext) Matchers.containsString(org.hamcrest.Matchers.containsString) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser) Settings(org.elasticsearch.common.settings.Settings)

Example 15 with CompressedXContent

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

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