Search in sources :

Example 21 with FieldMapper

use of org.elasticsearch.index.mapper.FieldMapper in project elasticsearch by elastic.

the class CategoryContextMappingTests method testIndexingWithContextList.

public void testIndexingWithContextList() throws Exception {
    String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").startArray("contexts").startObject().field("name", "ctx").field("type", "category").endObject().endArray().endObject().endObject().endObject().endObject().string();
    DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
    FieldMapper fieldMapper = defaultMapper.mappers().getMapper("completion");
    MappedFieldType completionFieldType = fieldMapper.fieldType();
    ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", jsonBuilder().startObject().startObject("completion").array("input", "suggestion5", "suggestion6", "suggestion7").startObject("contexts").array("ctx", "ctx1", "ctx2", "ctx3").endObject().field("weight", 5).endObject().endObject().bytes());
    IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
    assertContextSuggestFields(fields, 3);
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) MappedFieldType(org.elasticsearch.index.mapper.MappedFieldType) FieldMapper(org.elasticsearch.index.mapper.FieldMapper)

Example 22 with FieldMapper

use of org.elasticsearch.index.mapper.FieldMapper in project elasticsearch by elastic.

the class DynamicTemplatesTests method testSimpleWithXContentTraverse.

public void testSimpleWithXContentTraverse() throws Exception {
    String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-mapping.json");
    IndexService index = createIndex("test");
    client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping, XContentType.JSON).get();
    DocumentMapper docMapper = index.mapperService().documentMapper("person");
    byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/simple/test-data.json");
    ParsedDocument parsedDoc = docMapper.parse("test", "person", "1", new BytesArray(json));
    client().admin().indices().preparePutMapping("test").setType("person").setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
    docMapper = index.mapperService().documentMapper("person");
    Document doc = parsedDoc.rootDoc();
    IndexableField f = doc.getField("name");
    assertThat(f.name(), equalTo("name"));
    assertThat(f.binaryValue(), equalTo(new BytesRef("some name")));
    assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
    assertThat(f.fieldType().tokenized(), equalTo(false));
    FieldMapper fieldMapper = docMapper.mappers().getMapper("name");
    assertNotNull(fieldMapper);
    f = doc.getField("multi1");
    assertThat(f.name(), equalTo("multi1"));
    assertThat(f.stringValue(), equalTo("multi 1"));
    assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
    assertThat(f.fieldType().tokenized(), equalTo(true));
    fieldMapper = docMapper.mappers().getMapper("multi1");
    assertNotNull(fieldMapper);
    f = doc.getField("multi1.org");
    assertThat(f.name(), equalTo("multi1.org"));
    assertThat(f.binaryValue(), equalTo(new BytesRef("multi 1")));
    assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
    assertThat(f.fieldType().tokenized(), equalTo(false));
    fieldMapper = docMapper.mappers().getMapper("multi1.org");
    assertNotNull(fieldMapper);
    f = doc.getField("multi2");
    assertThat(f.name(), equalTo("multi2"));
    assertThat(f.stringValue(), equalTo("multi 2"));
    assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
    assertThat(f.fieldType().tokenized(), equalTo(true));
    fieldMapper = docMapper.mappers().getMapper("multi2");
    assertNotNull(fieldMapper);
    f = doc.getField("multi2.org");
    assertThat(f.name(), equalTo("multi2.org"));
    assertThat(f.binaryValue(), equalTo(new BytesRef("multi 2")));
    assertNotSame(IndexOptions.NONE, f.fieldType().indexOptions());
    assertThat(f.fieldType().tokenized(), equalTo(false));
    fieldMapper = docMapper.mappers().getMapper("multi2.org");
    assertNotNull(fieldMapper);
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) BytesArray(org.elasticsearch.common.bytes.BytesArray) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) Document(org.elasticsearch.index.mapper.ParseContext.Document) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) FieldMapper(org.elasticsearch.index.mapper.FieldMapper) BytesRef(org.apache.lucene.util.BytesRef)

Example 23 with FieldMapper

use of org.elasticsearch.index.mapper.FieldMapper in project elasticsearch by elastic.

the class PathMatchDynamicTemplateTests method testSimple.

public void testSimple() throws Exception {
    String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/pathmatch/test-mapping.json");
    IndexService index = createIndex("test");
    client().admin().indices().preparePutMapping("test").setType("person").setSource(mapping, XContentType.JSON).get();
    DocumentMapper docMapper = index.mapperService().documentMapper("person");
    byte[] json = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/dynamictemplate/pathmatch/test-data.json");
    ParsedDocument parsedDoc = docMapper.parse("test", "person", "1", new BytesArray(json));
    client().admin().indices().preparePutMapping("test").setType("person").setSource(parsedDoc.dynamicMappingsUpdate().toString(), XContentType.JSON).get();
    docMapper = index.mapperService().documentMapper("person");
    Document doc = parsedDoc.rootDoc();
    IndexableField f = doc.getField("name");
    assertThat(f.name(), equalTo("name"));
    assertThat(f.stringValue(), equalTo("top_level"));
    assertThat(f.fieldType().stored(), equalTo(false));
    FieldMapper fieldMapper = docMapper.mappers().getMapper("name");
    assertThat(fieldMapper.fieldType().stored(), equalTo(false));
    f = doc.getField("obj1.name");
    assertThat(f.name(), equalTo("obj1.name"));
    assertThat(f.fieldType().stored(), equalTo(true));
    fieldMapper = docMapper.mappers().getMapper("obj1.name");
    assertThat(fieldMapper.fieldType().stored(), equalTo(true));
    f = doc.getField("obj1.obj2.name");
    assertThat(f.name(), equalTo("obj1.obj2.name"));
    assertThat(f.fieldType().stored(), equalTo(false));
    fieldMapper = docMapper.mappers().getMapper("obj1.obj2.name");
    assertThat(fieldMapper.fieldType().stored(), equalTo(false));
    // verify more complex path_match expressions
    fieldMapper = docMapper.mappers().getMapper("obj3.obj4.prop1");
    assertNotNull(fieldMapper);
}
Also used : IndexableField(org.apache.lucene.index.IndexableField) BytesArray(org.elasticsearch.common.bytes.BytesArray) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) IndexService(org.elasticsearch.index.IndexService) DocumentMapper(org.elasticsearch.index.mapper.DocumentMapper) Document(org.elasticsearch.index.mapper.ParseContext.Document) ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) FieldMapper(org.elasticsearch.index.mapper.FieldMapper)

Aggregations

FieldMapper (org.elasticsearch.index.mapper.FieldMapper)23 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)15 IndexableField (org.apache.lucene.index.IndexableField)12 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)12 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)9 MappedFieldType (org.elasticsearch.index.mapper.MappedFieldType)8 IOException (java.io.IOException)4 Analyzer (org.apache.lucene.analysis.Analyzer)4 Encoder (org.apache.lucene.search.highlight.Encoder)4 BytesRef (org.apache.lucene.util.BytesRef)4 BytesArray (org.elasticsearch.common.bytes.BytesArray)4 IndexService (org.elasticsearch.index.IndexService)4 Document (org.elasticsearch.index.mapper.ParseContext.Document)4 FetchPhaseExecutionException (org.elasticsearch.search.fetch.FetchPhaseExecutionException)4 FetchSubPhase (org.elasticsearch.search.fetch.FetchSubPhase)4 SearchContext (org.elasticsearch.search.internal.SearchContext)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)2 IndexSearcher (org.apache.lucene.search.IndexSearcher)2