Search in sources :

Example 1 with ParsedDocument

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

the class IndexingSlowLog method postIndex.

@Override
public void postIndex(ShardId shardId, Engine.Index indexOperation, Engine.IndexResult result) {
    if (result.hasFailure() == false) {
        final ParsedDocument doc = indexOperation.parsedDoc();
        final long tookInNanos = result.getTook();
        if (indexWarnThreshold >= 0 && tookInNanos > indexWarnThreshold) {
            indexLogger.warn("{}", new SlowLogParsedDocumentPrinter(index, doc, tookInNanos, reformat, maxSourceCharsToLog));
        } else if (indexInfoThreshold >= 0 && tookInNanos > indexInfoThreshold) {
            indexLogger.info("{}", new SlowLogParsedDocumentPrinter(index, doc, tookInNanos, reformat, maxSourceCharsToLog));
        } else if (indexDebugThreshold >= 0 && tookInNanos > indexDebugThreshold) {
            indexLogger.debug("{}", new SlowLogParsedDocumentPrinter(index, doc, tookInNanos, reformat, maxSourceCharsToLog));
        } else if (indexTraceThreshold >= 0 && tookInNanos > indexTraceThreshold) {
            indexLogger.trace("{}", new SlowLogParsedDocumentPrinter(index, doc, tookInNanos, reformat, maxSourceCharsToLog));
        }
    }
}
Also used : ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument)

Example 2 with ParsedDocument

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

the class TermVectorsService method parseDocument.

private static ParsedDocument parseDocument(IndexShard indexShard, String index, String type, BytesReference doc, XContentType xContentType) {
    MapperService mapperService = indexShard.mapperService();
    DocumentMapperForType docMapper = mapperService.documentMapperWithAutoCreate(type);
    ParsedDocument parsedDocument = docMapper.getDocumentMapper().parse(source(index, type, "_id_for_tv_api", doc, xContentType));
    if (docMapper.getMapping() != null) {
        parsedDocument.addDynamicMappingsUpdate(docMapper.getMapping());
    }
    return parsedDocument;
}
Also used : ParsedDocument(org.elasticsearch.index.mapper.ParsedDocument) DocumentMapperForType(org.elasticsearch.index.mapper.DocumentMapperForType) MapperService(org.elasticsearch.index.mapper.MapperService)

Example 3 with ParsedDocument

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

the class CategoryContextMappingTests method testIndexingWithMultipleContexts.

public void testIndexingWithMultipleContexts() 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().startObject().field("name", "type").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();
    XContentBuilder builder = jsonBuilder().startObject().startArray("completion").startObject().array("input", "suggestion5", "suggestion6", "suggestion7").field("weight", 5).startObject("contexts").array("ctx", "ctx1", "ctx2", "ctx3").array("type", "typr3", "ftg").endObject().endObject().endArray().endObject();
    ParsedDocument parsedDocument = defaultMapper.parse("test", "type1", "1", builder.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) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder)

Example 4 with ParsedDocument

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

the class CategoryContextMappingTests method testIndexingWithNoContexts.

public void testIndexingWithNoContexts() 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().startArray("completion").startObject().array("input", "suggestion1", "suggestion2").field("weight", 3).endObject().startObject().array("input", "suggestion3", "suggestion4").field("weight", 4).endObject().startObject().array("input", "suggestion5", "suggestion6", "suggestion7").field("weight", 5).endObject().endArray().endObject().bytes());
    IndexableField[] fields = parsedDocument.rootDoc().getFields(completionFieldType.name());
    assertContextSuggestFields(fields, 7);
}
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 5 with ParsedDocument

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

the class GeoContextMappingTests 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", "geo").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").startArray("ctx").startObject().field("lat", 43.6624803).field("lon", -79.3863353).endObject().startObject().field("lat", 43.6624718).field("lon", -79.3873227).endObject().endArray().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)

Aggregations

ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)211 Test (org.junit.Test)85 LongPoint (org.apache.lucene.document.LongPoint)59 BytesArray (org.elasticsearch.common.bytes.BytesArray)58 Matchers.containsString (org.hamcrest.Matchers.containsString)57 Store (org.elasticsearch.index.store.Store)52 Searcher (org.elasticsearch.index.engine.Engine.Searcher)46 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)35 IOException (java.io.IOException)32 AtomicLong (java.util.concurrent.atomic.AtomicLong)31 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)31 IndexableField (org.apache.lucene.index.IndexableField)30 Term (org.apache.lucene.index.Term)28 TopDocs (org.apache.lucene.search.TopDocs)28 NumericDocValuesField (org.apache.lucene.document.NumericDocValuesField)27 Index (org.elasticsearch.index.Index)27 UncheckedIOException (java.io.UncheckedIOException)26 Field (org.apache.lucene.document.Field)26 TextField (org.apache.lucene.document.TextField)26 ArrayList (java.util.ArrayList)25