Search in sources :

Example 1 with MultiTermVectorsRequest

use of org.elasticsearch.action.termvectors.MultiTermVectorsRequest in project elasticsearch by elastic.

the class RestMultiTermVectorsAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    MultiTermVectorsRequest multiTermVectorsRequest = new MultiTermVectorsRequest();
    TermVectorsRequest template = new TermVectorsRequest();
    template.index(request.param("index"));
    template.type(request.param("type"));
    RestTermVectorsAction.readURIParameters(template, request);
    multiTermVectorsRequest.ids(Strings.commaDelimitedListToStringArray(request.param("ids")));
    request.withContentOrSourceParamParserOrNull(p -> multiTermVectorsRequest.add(template, p));
    return channel -> client.multiTermVectors(multiTermVectorsRequest, new RestToXContentListener<MultiTermVectorsResponse>(channel));
}
Also used : MultiTermVectorsRequest(org.elasticsearch.action.termvectors.MultiTermVectorsRequest) TermVectorsRequest(org.elasticsearch.action.termvectors.TermVectorsRequest) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) MultiTermVectorsRequest(org.elasticsearch.action.termvectors.MultiTermVectorsRequest) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) MultiTermVectorsResponse(org.elasticsearch.action.termvectors.MultiTermVectorsResponse) Strings(org.elasticsearch.common.Strings) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) TermVectorsRequest(org.elasticsearch.action.termvectors.TermVectorsRequest) MultiTermVectorsRequest(org.elasticsearch.action.termvectors.MultiTermVectorsRequest) MultiTermVectorsResponse(org.elasticsearch.action.termvectors.MultiTermVectorsResponse)

Example 2 with MultiTermVectorsRequest

use of org.elasticsearch.action.termvectors.MultiTermVectorsRequest in project elasticsearch by elastic.

the class MoreLikeThisQueryBuilderTests method executeMultiTermVectors.

@Override
protected MultiTermVectorsResponse executeMultiTermVectors(MultiTermVectorsRequest mtvRequest) {
    try {
        MultiTermVectorsItemResponse[] responses = new MultiTermVectorsItemResponse[mtvRequest.size()];
        int i = 0;
        for (TermVectorsRequest request : mtvRequest) {
            TermVectorsResponse response = new TermVectorsResponse(request.index(), request.type(), request.id());
            response.setExists(true);
            Fields generatedFields;
            if (request.doc() != null) {
                generatedFields = generateFields(randomFields, request.doc().utf8ToString());
            } else {
                generatedFields = generateFields(request.selectedFields().toArray(new String[request.selectedFields().size()]), request.id());
            }
            EnumSet<TermVectorsRequest.Flag> flags = EnumSet.of(TermVectorsRequest.Flag.Positions, TermVectorsRequest.Flag.Offsets);
            response.setFields(generatedFields, request.selectedFields(), flags, generatedFields);
            responses[i++] = new MultiTermVectorsItemResponse(response, null);
        }
        return new MultiTermVectorsResponse(responses);
    } catch (IOException ex) {
        throw new ElasticsearchException("boom", ex);
    }
}
Also used : TermVectorsRequest(org.elasticsearch.action.termvectors.TermVectorsRequest) MultiTermVectorsRequest(org.elasticsearch.action.termvectors.MultiTermVectorsRequest) MultiTermVectorsItemResponse(org.elasticsearch.action.termvectors.MultiTermVectorsItemResponse) MultiTermVectorsResponse(org.elasticsearch.action.termvectors.MultiTermVectorsResponse) TermVectorsResponse(org.elasticsearch.action.termvectors.TermVectorsResponse) Fields(org.apache.lucene.index.Fields) MultiFields(org.apache.lucene.index.MultiFields) IOException(java.io.IOException) ElasticsearchException(org.elasticsearch.ElasticsearchException) MultiTermVectorsResponse(org.elasticsearch.action.termvectors.MultiTermVectorsResponse)

Example 3 with MultiTermVectorsRequest

use of org.elasticsearch.action.termvectors.MultiTermVectorsRequest in project elasticsearch by elastic.

the class IndicesRequestIT method testMultiTermVector.

public void testMultiTermVector() {
    String multiTermVectorsShardAction = MultiTermVectorsAction.NAME + "[shard][s]";
    interceptTransportActions(multiTermVectorsShardAction);
    List<String> indices = new ArrayList<>();
    MultiTermVectorsRequest multiTermVectorsRequest = new MultiTermVectorsRequest();
    int numDocs = iterations(1, 30);
    for (int i = 0; i < numDocs; i++) {
        String indexOrAlias = randomIndexOrAlias();
        multiTermVectorsRequest.add(indexOrAlias, "type", Integer.toString(i));
        indices.add(indexOrAlias);
    }
    internalCluster().coordOnlyNodeClient().multiTermVectors(multiTermVectorsRequest).actionGet();
    clearInterceptedActions();
    assertIndicesSubset(indices, multiTermVectorsShardAction);
}
Also used : MultiTermVectorsRequest(org.elasticsearch.action.termvectors.MultiTermVectorsRequest) ArrayList(java.util.ArrayList)

Aggregations

MultiTermVectorsRequest (org.elasticsearch.action.termvectors.MultiTermVectorsRequest)3 IOException (java.io.IOException)2 MultiTermVectorsResponse (org.elasticsearch.action.termvectors.MultiTermVectorsResponse)2 TermVectorsRequest (org.elasticsearch.action.termvectors.TermVectorsRequest)2 ArrayList (java.util.ArrayList)1 Fields (org.apache.lucene.index.Fields)1 MultiFields (org.apache.lucene.index.MultiFields)1 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 MultiTermVectorsItemResponse (org.elasticsearch.action.termvectors.MultiTermVectorsItemResponse)1 TermVectorsResponse (org.elasticsearch.action.termvectors.TermVectorsResponse)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 Strings (org.elasticsearch.common.Strings)1 Settings (org.elasticsearch.common.settings.Settings)1 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)1 RestController (org.elasticsearch.rest.RestController)1 RestRequest (org.elasticsearch.rest.RestRequest)1 GET (org.elasticsearch.rest.RestRequest.Method.GET)1 POST (org.elasticsearch.rest.RestRequest.Method.POST)1 RestToXContentListener (org.elasticsearch.rest.action.RestToXContentListener)1