Java Code Examples for org.elasticsearch.action.termvectors.TermVectorsRequest#selectedFields()

The following examples show how to use org.elasticsearch.action.termvectors.TermVectorsRequest#selectedFields() . 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: RestTermVectorsAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
static public void addFieldStringsFromParameter(TermVectorsRequest termVectorsRequest, String fields) {
    Set<String> selectedFields = termVectorsRequest.selectedFields();
    if (fields != null) {
        String[] paramFieldStrings = Strings.commaDelimitedListToStringArray(fields);
        for (String field : paramFieldStrings) {
            if (selectedFields == null) {
                selectedFields = new HashSet<>();
            }
            if (!selectedFields.contains(field)) {
                field = field.replaceAll("\\s", "");
                selectedFields.add(field);
            }
        }
    }
    if (selectedFields != null) {
        termVectorsRequest.selectedFields(selectedFields.toArray(new String[selectedFields.size()]));
    }
}
 
Example 2
Source File: ShardTermVectorsService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private void handleFieldWildcards(TermVectorsRequest request) {
    Set<String> fieldNames = new HashSet<>();
    for (String pattern : request.selectedFields()) {
        fieldNames.addAll(indexShard.mapperService().simpleMatchToIndexNames(pattern));
    }
    request.selectedFields(fieldNames.toArray(Strings.EMPTY_ARRAY));
}
 
Example 3
Source File: ShardTermVectorsService.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
private AggregatedDfs getAggregatedDfs(Fields termVectorsFields, TermVectorsRequest request) throws IOException {
    DfsOnlyRequest dfsOnlyRequest = new DfsOnlyRequest(termVectorsFields, new String[]{request.index()},
            new String[]{request.type()}, request.selectedFields());
    DfsOnlyResponse response = dfsAction.execute(dfsOnlyRequest).actionGet();
    return response.getDfs();
}
 
Example 4
Source File: GenTermValuesHandler.java    From elasticsearch-taste with Apache License 2.0 4 votes vote down vote up
@Override
public void onResponse(final SearchResponse response) {
    if (mTVListener != null) {
        try {
            mTVListener.await();
        } catch (final InterruptedException e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Interrupted.", e);
            }
        }
    }

    if (interrupted) {
        return;
    }

    final SearchHits searchHits = response.getHits();
    final SearchHit[] hits = searchHits.getHits();
    if (hits.length == 0) {
        scrollSearchGate.countDown();
        shutdown();
    } else {
        final Map<String, DocInfo> idMap = new HashMap<>(hits.length);
        final MultiTermVectorsRequestBuilder requestBuilder = client
                .prepareMultiTermVectors();
        for (final SearchHit hit : hits) {
            final String id = hit.getId();
            final SearchHitField searchHitField = hit.field(idField);
            if (searchHitField != null) {
                idMap.put(id,
                        new DocInfo((String) searchHitField.getValue(),
                                hit.getSource()));
            }
            final TermVectorsRequest termVectorRequest = new TermVectorsRequest(
                    sourceIndex, sourceType, id);
            termVectorRequest.selectedFields(sourceFields);
            requestBuilder.add(termVectorRequest);
        }
        mTVListener = new MultiTermVectorsListener(numOfThreads,
                requestHandlers, eventParams, idMap, executor, logger);
        requestBuilder.execute(mTVListener);

        client.prepareSearchScroll(response.getScrollId())
                .setScroll(new TimeValue(keepAlive.longValue()))
                .execute(this);
    }
}