org.elasticsearch.index.fieldvisitor.FieldsVisitor Java Examples

The following examples show how to use org.elasticsearch.index.fieldvisitor.FieldsVisitor. 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: FetchPhase.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
private Map<String, SearchHitField> getSearchFields(SearchContext context, int nestedSubDocId, boolean loadAllStored, Set<String> fieldNames, List<String> fieldNamePatterns, LeafReaderContext subReaderContext) {
    Map<String, SearchHitField> searchFields = null;
    if (context.hasFieldNames() && !context.fieldNames().isEmpty()) {
        FieldsVisitor nestedFieldsVisitor = null;
        if (loadAllStored) {
            nestedFieldsVisitor = new AllFieldsVisitor();
        } else if (fieldNames != null || fieldNamePatterns != null) {
            nestedFieldsVisitor = new CustomFieldsVisitor(fieldNames == null ? Collections.<String>emptySet() : fieldNames,
                    fieldNamePatterns == null ? Collections.<String>emptyList() : fieldNamePatterns, false);
        }

        if (nestedFieldsVisitor != null) {
            loadStoredFields(context, subReaderContext, nestedFieldsVisitor, nestedSubDocId);
            nestedFieldsVisitor.postProcess(context.mapperService());
            if (!nestedFieldsVisitor.fields().isEmpty()) {
                searchFields = new HashMap<>(nestedFieldsVisitor.fields().size());
                for (Map.Entry<String, List<Object>> entry : nestedFieldsVisitor.fields().entrySet()) {
                    searchFields.put(entry.getKey(), new InternalSearchHitField(entry.getKey(), entry.getValue()));
                }
            }
        }
    }
    return searchFields;
}
 
Example #2
Source File: IndicesTTLService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void collect(int doc) {
    try {
        FieldsVisitor fieldsVisitor = new FieldsVisitor(false);
        context.reader().document(doc, fieldsVisitor);
        Uid uid = fieldsVisitor.uid();
        final long version = Versions.loadVersion(context.reader(), new Term(UidFieldMapper.NAME, uid.toBytesRef()));
        docsToPurge.add(new DocToPurge(uid.type(), uid.id(), version, fieldsVisitor.routing()));
    } catch (Exception e) {
        logger.trace("failed to collect doc", e);
    }
}
 
Example #3
Source File: FetchPhase.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private void loadStoredFields(SearchContext searchContext, LeafReaderContext readerContext, FieldsVisitor fieldVisitor, int docId) {
    fieldVisitor.reset();
    try {
        readerContext.reader().document(docId, fieldVisitor);
    } catch (IOException e) {
        throw new FetchPhaseExecutionException(searchContext, "Failed to fetch doc id [" + docId + "]", e);
    }
}
 
Example #4
Source File: ShardGetService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static FieldsVisitor buildFieldsVisitors(String[] fields, FetchSourceContext fetchSourceContext) {
    if (fields == null || fields.length == 0) {
        return fetchSourceContext.fetchSource() ? new FieldsVisitor(true) : null;
    }

    return new CustomFieldsVisitor(Sets.newHashSet(fields), fetchSourceContext.fetchSource());
}