Java Code Examples for org.elasticsearch.index.mapper.DocumentMapper#typeText()

The following examples show how to use org.elasticsearch.index.mapper.DocumentMapper#typeText() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WriterCollector.java    From elasticsearch-inout-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
    fieldsVisitor.reset();
    currentReader.document(doc, fieldsVisitor);

    Map<String, SearchHitField> searchFields = null;
    if (fieldsVisitor.fields() != null) {
        searchFields = new HashMap<String, SearchHitField>(
                fieldsVisitor.fields().size());
        for (Map.Entry<String, List<Object>> entry : fieldsVisitor
                .fields().entrySet()) {
            searchFields.put(entry.getKey(), new InternalSearchHitField(
                    entry.getKey(), entry.getValue()));
        }
    }

    DocumentMapper documentMapper = context.mapperService().documentMapper(
            fieldsVisitor.uid().type());
    Text typeText;
    if (documentMapper == null) {
        typeText = new StringAndBytesText(fieldsVisitor.uid().type());
    } else {
        typeText = documentMapper.typeText();
    }

    InternalSearchHit searchHit = new InternalSearchHit(doc,
            fieldsVisitor.uid().id(), typeText,
            sourceRequested ? fieldsVisitor.source() : null, searchFields);

    // it looks like it is safe to reuse the HitContext,
    // the cache is only used by the highlighter which we do not use.
    FetchSubPhase.HitContext hitContext = new FetchSubPhase.HitContext();
    for (FetchSubPhase fetchSubPhase : fetchSubPhases) {
        if (fetchSubPhase.hitExecutionNeeded(context)) {
            hitContext.reset(searchHit, arc, doc,
                    context.searcher().getIndexReader(), doc,
                    fieldsVisitor);
            fetchSubPhase.hitExecute(context, hitContext);
        }
    }
    searchHit.shardTarget(context.shardTarget());
    collectHit(searchHit);
    numExported++;
}
 
Example 2
Source File: ExportCollector.java    From elasticsearch-inout-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void collect(int doc) throws IOException {
    fieldsVisitor.reset();
    currentReader.document(doc, fieldsVisitor);

    Map<String, SearchHitField> searchFields = null;
    if (fieldsVisitor.fields() != null) {
        searchFields = new HashMap<String, SearchHitField>(fieldsVisitor.fields().size());
        for (Map.Entry<String, List<Object>> entry : fieldsVisitor.fields().entrySet()) {
            searchFields.put(entry.getKey(), new InternalSearchHitField(entry.getKey(), entry.getValue()));
        }
    }

    DocumentMapper documentMapper = context.mapperService()
            .documentMapper(fieldsVisitor.uid().type());
    Text typeText;
    if (documentMapper == null) {
        typeText = new StringAndBytesText(fieldsVisitor.uid().type());
    } else {
        typeText = documentMapper.typeText();
    }

    InternalSearchHit searchHit = new InternalSearchHit(doc,
            fieldsVisitor.uid().id(), typeText,
            sourceRequested ? fieldsVisitor.source() : null,
            searchFields);

    for (FetchSubPhase fetchSubPhase : fetchSubPhases) {
        FetchSubPhase.HitContext hitContext = new FetchSubPhase.HitContext();
        if (fetchSubPhase.hitExecutionNeeded(context)) {
            hitContext.reset(searchHit, arc, doc, context.searcher().getIndexReader(), doc, fieldsVisitor);
            fetchSubPhase.hitExecute(context, hitContext);
        }
    }

    searchHit.shardTarget(context.shardTarget());
    exportFields.hit(searchHit);
    BytesStreamOutput os = new BytesStreamOutput();
    XContentBuilder builder = new XContentBuilder(XContentFactory.xContent(XContentType.JSON), os);
    exportFields.toXContent(builder, ToXContent.EMPTY_PARAMS);
    builder.flush();
    BytesReference bytes = os.bytes();
    out.write(bytes.array(), bytes.arrayOffset(), bytes.length());
    out.write('\n');
    out.flush();
    numExported++;
}