Search in sources :

Example 21 with CompressedXContent

use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.

the class DocumentMapperMergeTests method testMergeObjectDynamic.

public void testMergeObjectDynamic() throws Exception {
    DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
    String objectMapping = XContentFactory.jsonBuilder().startObject().startObject("type1").endObject().endObject().string();
    DocumentMapper mapper = parser.parse("type1", new CompressedXContent(objectMapping));
    assertNull(mapper.root().dynamic());
    String withDynamicMapping = XContentFactory.jsonBuilder().startObject().startObject("type1").field("dynamic", "false").endObject().endObject().string();
    DocumentMapper withDynamicMapper = parser.parse("type1", new CompressedXContent(withDynamicMapping));
    assertThat(withDynamicMapper.root().dynamic(), equalTo(ObjectMapper.Dynamic.FALSE));
    DocumentMapper merged = mapper.merge(withDynamicMapper.mapping(), false);
    assertThat(merged.root().dynamic(), equalTo(ObjectMapper.Dynamic.FALSE));
}
Also used : DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser)

Example 22 with CompressedXContent

use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.

the class DocumentMapperMergeTests method testMergeSearchAnalyzer.

public void testMergeSearchAnalyzer() throws Exception {
    DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
    String mapping1 = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "text").field("analyzer", "standard").field("search_analyzer", "whitespace").endObject().endObject().endObject().endObject().string();
    String mapping2 = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "text").field("analyzer", "standard").field("search_analyzer", "keyword").endObject().endObject().endObject().endObject().string();
    DocumentMapper existing = parser.parse("type", new CompressedXContent(mapping1));
    DocumentMapper changed = parser.parse("type", new CompressedXContent(mapping2));
    assertThat(((NamedAnalyzer) existing.mappers().getMapper("field").fieldType().searchAnalyzer()).name(), equalTo("whitespace"));
    DocumentMapper merged = existing.merge(changed.mapping(), false);
    assertThat(((NamedAnalyzer) merged.mappers().getMapper("field").fieldType().searchAnalyzer()).name(), equalTo("keyword"));
}
Also used : DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser)

Example 23 with CompressedXContent

use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.

the class DocumentMapperMergeTests method test1Merge.

public void test1Merge() throws Exception {
    String stage1Mapping = XContentFactory.jsonBuilder().startObject().startObject("person").startObject("properties").startObject("name").field("type", "text").endObject().endObject().endObject().endObject().string();
    DocumentMapperParser parser = createIndex("test").mapperService().documentMapperParser();
    DocumentMapper stage1 = parser.parse("person", new CompressedXContent(stage1Mapping));
    String stage2Mapping = XContentFactory.jsonBuilder().startObject().startObject("person").startObject("properties").startObject("name").field("type", "text").endObject().startObject("age").field("type", "integer").endObject().startObject("obj1").startObject("properties").startObject("prop1").field("type", "integer").endObject().endObject().endObject().endObject().endObject().endObject().string();
    DocumentMapper stage2 = parser.parse("person", new CompressedXContent(stage2Mapping));
    DocumentMapper merged = stage1.merge(stage2.mapping(), false);
    // stage1 mapping should not have been modified
    assertThat(stage1.mappers().smartNameFieldMapper("age"), nullValue());
    assertThat(stage1.mappers().smartNameFieldMapper("obj1.prop1"), nullValue());
    // but merged should
    assertThat(merged.mappers().smartNameFieldMapper("age"), notNullValue());
    assertThat(merged.mappers().smartNameFieldMapper("obj1.prop1"), notNullValue());
}
Also used : DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString) DocumentMapperParser(org.elasticsearch.index.mapper.DocumentMapperParser)

Example 24 with CompressedXContent

use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.

the class BinaryFieldMapperTests method testStoredValue.

public void testStoredValue() throws IOException {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "binary").field("store", true).endObject().endObject().endObject().endObject().string();
    DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
    // case 1: a simple binary value
    final byte[] binaryValue1 = new byte[100];
    binaryValue1[56] = 1;
    // case 2: a value that looks compressed: this used to fail in 1.x
    BytesStreamOutput out = new BytesStreamOutput();
    try (StreamOutput compressed = CompressorFactory.COMPRESSOR.streamOutput(out)) {
        new BytesArray(binaryValue1).writeTo(compressed);
    }
    final byte[] binaryValue2 = BytesReference.toBytes(out.bytes());
    assertTrue(CompressorFactory.isCompressed(new BytesArray(binaryValue2)));
    for (byte[] value : Arrays.asList(binaryValue1, binaryValue2)) {
        ParsedDocument doc = mapper.parse("test", "type", "id", XContentFactory.jsonBuilder().startObject().field("field", value).endObject().bytes());
        BytesRef indexedValue = doc.rootDoc().getBinaryValue("field");
        assertEquals(new BytesRef(value), indexedValue);
        FieldMapper fieldMapper = mapper.mappers().smartNameFieldMapper("field");
        Object originalValue = fieldMapper.fieldType().valueForDisplay(indexedValue);
        assertEquals(new BytesArray(value), originalValue);
    }
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString) StreamOutput(org.elasticsearch.common.io.stream.StreamOutput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) BytesStreamOutput(org.elasticsearch.common.io.stream.BytesStreamOutput) BytesRef(org.apache.lucene.util.BytesRef)

Example 25 with CompressedXContent

use of org.elasticsearch.common.compress.CompressedXContent in project elasticsearch by elastic.

the class BinaryFieldMapperTests method testDefaultMapping.

public void testDefaultMapping() throws Exception {
    String mapping = XContentFactory.jsonBuilder().startObject().startObject("type").startObject("properties").startObject("field").field("type", "binary").endObject().endObject().endObject().endObject().string();
    DocumentMapper mapper = createIndex("test").mapperService().documentMapperParser().parse("type", new CompressedXContent(mapping));
    FieldMapper fieldMapper = mapper.mappers().smartNameFieldMapper("field");
    assertThat(fieldMapper, instanceOf(BinaryFieldMapper.class));
    assertThat(fieldMapper.fieldType().stored(), equalTo(false));
}
Also used : CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Matchers.containsString(org.hamcrest.Matchers.containsString)

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