Search in sources :

Example 1 with TermVectorsRequest

use of org.opensearch.client.core.TermVectorsRequest in project OpenSearch by opensearch-project.

the class RequestConverters method termVectors.

static Request termVectors(TermVectorsRequest tvrequest) throws IOException {
    String endpoint;
    if (tvrequest.getType() != null) {
        endpoint = new EndpointBuilder().addPathPart(tvrequest.getIndex(), tvrequest.getType(), tvrequest.getId()).addPathPartAsIs("_termvectors").build();
    } else {
        endpoint = new EndpointBuilder().addPathPart(tvrequest.getIndex()).addPathPartAsIs("_termvectors").addPathPart(tvrequest.getId()).build();
    }
    Request request = new Request(HttpGet.METHOD_NAME, endpoint);
    Params params = new Params();
    params.withRouting(tvrequest.getRouting());
    params.withPreference(tvrequest.getPreference());
    params.withRealtime(tvrequest.getRealtime());
    request.addParameters(params.asMap());
    request.setEntity(createEntity(tvrequest, REQUEST_BODY_CONTENT_TYPE));
    return request;
}
Also used : BulkRequest(org.opensearch.action.bulk.BulkRequest) WriteRequest(org.opensearch.action.support.WriteRequest) AbstractBulkByScrollRequest(org.opensearch.index.reindex.AbstractBulkByScrollRequest) GetStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) DeleteRequest(org.opensearch.action.delete.DeleteRequest) CountRequest(org.opensearch.client.core.CountRequest) TermVectorsRequest(org.opensearch.client.core.TermVectorsRequest) FieldCapabilitiesRequest(org.opensearch.action.fieldcaps.FieldCapabilitiesRequest) UpdateRequest(org.opensearch.action.update.UpdateRequest) SearchTemplateRequest(org.opensearch.script.mustache.SearchTemplateRequest) RankEvalRequest(org.opensearch.index.rankeval.RankEvalRequest) GetSourceRequest(org.opensearch.client.core.GetSourceRequest) MultiSearchRequest(org.opensearch.action.search.MultiSearchRequest) DocWriteRequest(org.opensearch.action.DocWriteRequest) SearchScrollRequest(org.opensearch.action.search.SearchScrollRequest) ExplainRequest(org.opensearch.action.explain.ExplainRequest) SearchRequest(org.opensearch.action.search.SearchRequest) DeleteStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest) GetRequest(org.opensearch.action.get.GetRequest) MultiSearchTemplateRequest(org.opensearch.script.mustache.MultiSearchTemplateRequest) PutStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.PutStoredScriptRequest) UpdateByQueryRequest(org.opensearch.index.reindex.UpdateByQueryRequest) MultiTermVectorsRequest(org.opensearch.client.core.MultiTermVectorsRequest) ClearScrollRequest(org.opensearch.action.search.ClearScrollRequest) DeleteByQueryRequest(org.opensearch.index.reindex.DeleteByQueryRequest) IndexRequest(org.opensearch.action.index.IndexRequest) ClusterHealthRequest(org.opensearch.action.admin.cluster.health.ClusterHealthRequest) ReindexRequest(org.opensearch.index.reindex.ReindexRequest) MultiGetRequest(org.opensearch.action.get.MultiGetRequest)

Example 2 with TermVectorsRequest

use of org.opensearch.client.core.TermVectorsRequest in project OpenSearch by opensearch-project.

the class RequestConvertersTests method testMultiTermVectorsWithType.

public void testMultiTermVectorsWithType() throws IOException {
    MultiTermVectorsRequest mtvRequest = new MultiTermVectorsRequest();
    int numberOfRequests = randomIntBetween(0, 5);
    for (int i = 0; i < numberOfRequests; i++) {
        String index = randomAlphaOfLengthBetween(3, 10);
        String type = randomAlphaOfLengthBetween(3, 10);
        String id = randomAlphaOfLengthBetween(3, 10);
        TermVectorsRequest tvRequest = new TermVectorsRequest(index, type, id);
        String[] fields = generateRandomStringArray(10, 5, false, false);
        tvRequest.setFields(fields);
        mtvRequest.add(tvRequest);
    }
    Request request = RequestConverters.mtermVectors(mtvRequest);
    assertEquals(HttpGet.METHOD_NAME, request.getMethod());
    assertEquals("_mtermvectors", request.getEndpoint());
    assertToXContentBody(mtvRequest, request.getEntity());
}
Also used : TermVectorsRequest(org.opensearch.client.core.TermVectorsRequest) MultiTermVectorsRequest(org.opensearch.client.core.MultiTermVectorsRequest) MultiTermVectorsRequest(org.opensearch.client.core.MultiTermVectorsRequest) RandomSearchRequestGenerator.randomSearchRequest(org.opensearch.search.RandomSearchRequestGenerator.randomSearchRequest) MasterNodeRequest(org.opensearch.action.support.master.MasterNodeRequest) WriteRequest(org.opensearch.action.support.WriteRequest) AbstractBulkByScrollRequest(org.opensearch.index.reindex.AbstractBulkByScrollRequest) RatedRequest(org.opensearch.index.rankeval.RatedRequest) DeleteRequest(org.opensearch.action.delete.DeleteRequest) TermVectorsRequest(org.opensearch.client.core.TermVectorsRequest) AcknowledgedRequest(org.opensearch.action.support.master.AcknowledgedRequest) FieldCapabilitiesRequest(org.opensearch.action.fieldcaps.FieldCapabilitiesRequest) UpdateRequest(org.opensearch.action.update.UpdateRequest) GetSourceRequest(org.opensearch.client.core.GetSourceRequest) MultiSearchRequest(org.opensearch.action.search.MultiSearchRequest) DocWriteRequest(org.opensearch.action.DocWriteRequest) SearchScrollRequest(org.opensearch.action.search.SearchScrollRequest) ExplainRequest(org.opensearch.action.explain.ExplainRequest) SearchRequest(org.opensearch.action.search.SearchRequest) PutStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.PutStoredScriptRequest) DeleteByQueryRequest(org.opensearch.index.reindex.DeleteByQueryRequest) MultiGetRequest(org.opensearch.action.get.MultiGetRequest) BulkRequest(org.opensearch.action.bulk.BulkRequest) GetStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptRequest) ReplicationRequest(org.opensearch.action.support.replication.ReplicationRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) CountRequest(org.opensearch.client.core.CountRequest) BulkShardRequest(org.opensearch.action.bulk.BulkShardRequest) SearchTemplateRequest(org.opensearch.script.mustache.SearchTemplateRequest) RankEvalRequest(org.opensearch.index.rankeval.RankEvalRequest) DeleteStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest) GetRequest(org.opensearch.action.get.GetRequest) MultiSearchTemplateRequest(org.opensearch.script.mustache.MultiSearchTemplateRequest) UpdateByQueryRequest(org.opensearch.index.reindex.UpdateByQueryRequest) MultiTermVectorsRequest(org.opensearch.client.core.MultiTermVectorsRequest) ClearScrollRequest(org.opensearch.action.search.ClearScrollRequest) IndexRequest(org.opensearch.action.index.IndexRequest) ReindexRequest(org.opensearch.index.reindex.ReindexRequest)

Example 3 with TermVectorsRequest

use of org.opensearch.client.core.TermVectorsRequest in project OpenSearch by opensearch-project.

the class CrudIT method testTermvectorsWithNonExistentIndex.

// Not entirely sure if _termvectors belongs to CRUD, and in the absence of a better place, will have it here
public void testTermvectorsWithNonExistentIndex() {
    TermVectorsRequest request = new TermVectorsRequest("non-existent", "non-existent");
    OpenSearchException exception = expectThrows(OpenSearchException.class, () -> execute(request, highLevelClient()::termvectors, highLevelClient()::termvectorsAsync));
    assertEquals(RestStatus.NOT_FOUND, exception.status());
}
Also used : TermVectorsRequest(org.opensearch.client.core.TermVectorsRequest) MultiTermVectorsRequest(org.opensearch.client.core.MultiTermVectorsRequest) OpenSearchException(org.opensearch.OpenSearchException)

Example 4 with TermVectorsRequest

use of org.opensearch.client.core.TermVectorsRequest in project OpenSearch by opensearch-project.

the class RequestConvertersTests method testTermVectors.

public void testTermVectors() throws IOException {
    String index = randomAlphaOfLengthBetween(3, 10);
    String id = randomAlphaOfLengthBetween(3, 10);
    TermVectorsRequest tvRequest = new TermVectorsRequest(index, id);
    Map<String, String> expectedParams = new HashMap<>();
    String[] fields;
    if (randomBoolean()) {
        String routing = randomAlphaOfLengthBetween(3, 10);
        tvRequest.setRouting(routing);
        expectedParams.put("routing", routing);
    }
    if (randomBoolean()) {
        tvRequest.setRealtime(false);
        expectedParams.put("realtime", "false");
    }
    boolean hasFields = randomBoolean();
    if (hasFields) {
        fields = generateRandomStringArray(10, 5, false, false);
        tvRequest.setFields(fields);
    }
    Request request = RequestConverters.termVectors(tvRequest);
    StringJoiner endpoint = new StringJoiner("/", "/", "");
    endpoint.add(index).add("_termvectors").add(id);
    assertEquals(HttpGet.METHOD_NAME, request.getMethod());
    assertEquals(endpoint.toString(), request.getEndpoint());
    for (Map.Entry<String, String> param : expectedParams.entrySet()) {
        assertThat(request.getParameters(), hasEntry(param.getKey(), param.getValue()));
    }
    assertToXContentBody(tvRequest, request.getEntity());
}
Also used : TermVectorsRequest(org.opensearch.client.core.TermVectorsRequest) MultiTermVectorsRequest(org.opensearch.client.core.MultiTermVectorsRequest) HashMap(java.util.HashMap) RandomSearchRequestGenerator.randomSearchRequest(org.opensearch.search.RandomSearchRequestGenerator.randomSearchRequest) MasterNodeRequest(org.opensearch.action.support.master.MasterNodeRequest) WriteRequest(org.opensearch.action.support.WriteRequest) AbstractBulkByScrollRequest(org.opensearch.index.reindex.AbstractBulkByScrollRequest) RatedRequest(org.opensearch.index.rankeval.RatedRequest) DeleteRequest(org.opensearch.action.delete.DeleteRequest) TermVectorsRequest(org.opensearch.client.core.TermVectorsRequest) AcknowledgedRequest(org.opensearch.action.support.master.AcknowledgedRequest) FieldCapabilitiesRequest(org.opensearch.action.fieldcaps.FieldCapabilitiesRequest) UpdateRequest(org.opensearch.action.update.UpdateRequest) GetSourceRequest(org.opensearch.client.core.GetSourceRequest) MultiSearchRequest(org.opensearch.action.search.MultiSearchRequest) DocWriteRequest(org.opensearch.action.DocWriteRequest) SearchScrollRequest(org.opensearch.action.search.SearchScrollRequest) ExplainRequest(org.opensearch.action.explain.ExplainRequest) SearchRequest(org.opensearch.action.search.SearchRequest) PutStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.PutStoredScriptRequest) DeleteByQueryRequest(org.opensearch.index.reindex.DeleteByQueryRequest) MultiGetRequest(org.opensearch.action.get.MultiGetRequest) BulkRequest(org.opensearch.action.bulk.BulkRequest) GetStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptRequest) ReplicationRequest(org.opensearch.action.support.replication.ReplicationRequest) AnalyzeRequest(org.opensearch.client.indices.AnalyzeRequest) CountRequest(org.opensearch.client.core.CountRequest) BulkShardRequest(org.opensearch.action.bulk.BulkShardRequest) SearchTemplateRequest(org.opensearch.script.mustache.SearchTemplateRequest) RankEvalRequest(org.opensearch.index.rankeval.RankEvalRequest) DeleteStoredScriptRequest(org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest) GetRequest(org.opensearch.action.get.GetRequest) MultiSearchTemplateRequest(org.opensearch.script.mustache.MultiSearchTemplateRequest) UpdateByQueryRequest(org.opensearch.index.reindex.UpdateByQueryRequest) MultiTermVectorsRequest(org.opensearch.client.core.MultiTermVectorsRequest) ClearScrollRequest(org.opensearch.action.search.ClearScrollRequest) IndexRequest(org.opensearch.action.index.IndexRequest) ReindexRequest(org.opensearch.index.reindex.ReindexRequest) Map(java.util.Map) HashMap(java.util.HashMap) Collections.singletonMap(java.util.Collections.singletonMap) Collections.emptyMap(java.util.Collections.emptyMap) StringJoiner(java.util.StringJoiner)

Example 5 with TermVectorsRequest

use of org.opensearch.client.core.TermVectorsRequest in project OpenSearch by opensearch-project.

the class CRUDDocumentationIT method testMultiTermVectors.

// Not entirely sure if _mtermvectors belongs to CRUD, and in the absence of a better place, will have it here
public void testMultiTermVectors() throws Exception {
    RestHighLevelClient client = highLevelClient();
    CreateIndexRequest authorsRequest = new CreateIndexRequest("authors").mapping(XContentFactory.jsonBuilder().startObject().startObject("properties").startObject("user").field("type", "keyword").endObject().endObject().endObject());
    CreateIndexResponse authorsResponse = client.indices().create(authorsRequest, RequestOptions.DEFAULT);
    assertTrue(authorsResponse.isAcknowledged());
    client.index(new IndexRequest("index").id("1").source("user", "foobar"), RequestOptions.DEFAULT);
    client.index(new IndexRequest("index").id("2").source("user", "baz"), RequestOptions.DEFAULT);
    Response refreshResponse = client().performRequest(new Request("POST", "/authors/_refresh"));
    assertEquals(200, refreshResponse.getStatusLine().getStatusCode());
    {
        // tag::multi-term-vectors-request
        // <1>
        MultiTermVectorsRequest request = new MultiTermVectorsRequest();
        TermVectorsRequest tvrequest1 = new TermVectorsRequest("authors", "1");
        tvrequest1.setFields("user");
        // <2>
        request.add(tvrequest1);
        XContentBuilder docBuilder = XContentFactory.jsonBuilder();
        docBuilder.startObject().field("user", "guest-user").endObject();
        TermVectorsRequest tvrequest2 = new TermVectorsRequest("authors", docBuilder);
        // <3>
        request.add(tvrequest2);
    // end::multi-term-vectors-request
    }
    // tag::multi-term-vectors-request-template
    TermVectorsRequest tvrequestTemplate = // <1>
    new TermVectorsRequest("authors", "fake_id");
    tvrequestTemplate.setFields("user");
    String[] ids = { "1", "2" };
    MultiTermVectorsRequest request = // <2>
    new MultiTermVectorsRequest(ids, tvrequestTemplate);
    // end::multi-term-vectors-request-template
    // tag::multi-term-vectors-execute
    MultiTermVectorsResponse response = client.mtermvectors(request, RequestOptions.DEFAULT);
    // end::multi-term-vectors-execute
    // tag::multi-term-vectors-response
    List<TermVectorsResponse> tvresponseList = // <1>
    response.getTermVectorsResponses();
    if (tvresponseList != null) {
        for (TermVectorsResponse tvresponse : tvresponseList) {
        }
    }
    // end::multi-term-vectors-response
    ActionListener<MultiTermVectorsResponse> listener;
    // tag::multi-term-vectors-execute-listener
    listener = new ActionListener<MultiTermVectorsResponse>() {

        @Override
        public void onResponse(MultiTermVectorsResponse mtvResponse) {
        // <1>
        }

        @Override
        public void onFailure(Exception e) {
        // <2>
        }
    };
    // end::multi-term-vectors-execute-listener
    CountDownLatch latch = new CountDownLatch(1);
    listener = new LatchedActionListener<>(listener, latch);
    // tag::multi-term-vectors-execute-async
    client.mtermvectorsAsync(request, RequestOptions.DEFAULT, // <1>
    listener);
    // end::multi-term-vectors-execute-async
    assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
Also used : TermVectorsRequest(org.opensearch.client.core.TermVectorsRequest) MultiTermVectorsRequest(org.opensearch.client.core.MultiTermVectorsRequest) MultiTermVectorsResponse(org.opensearch.client.core.MultiTermVectorsResponse) TermVectorsResponse(org.opensearch.client.core.TermVectorsResponse) BulkRequest(org.opensearch.action.bulk.BulkRequest) Request(org.opensearch.client.Request) WriteRequest(org.opensearch.action.support.WriteRequest) DeleteRequest(org.opensearch.action.delete.DeleteRequest) TermVectorsRequest(org.opensearch.client.core.TermVectorsRequest) UpdateRequest(org.opensearch.action.update.UpdateRequest) RethrottleRequest(org.opensearch.client.RethrottleRequest) GetSourceRequest(org.opensearch.client.core.GetSourceRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) DocWriteRequest(org.opensearch.action.DocWriteRequest) GetRequest(org.opensearch.action.get.GetRequest) UpdateByQueryRequest(org.opensearch.index.reindex.UpdateByQueryRequest) MultiTermVectorsRequest(org.opensearch.client.core.MultiTermVectorsRequest) DeleteByQueryRequest(org.opensearch.index.reindex.DeleteByQueryRequest) IndexRequest(org.opensearch.action.index.IndexRequest) ReindexRequest(org.opensearch.index.reindex.ReindexRequest) MultiGetRequest(org.opensearch.action.get.MultiGetRequest) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) Matchers.containsString(org.hamcrest.Matchers.containsString) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) IndexRequest(org.opensearch.action.index.IndexRequest) CountDownLatch(java.util.concurrent.CountDownLatch) MultiTermVectorsResponse(org.opensearch.client.core.MultiTermVectorsResponse) OpenSearchException(org.opensearch.OpenSearchException) MultiGetResponse(org.opensearch.action.get.MultiGetResponse) IndexResponse(org.opensearch.action.index.IndexResponse) BulkItemResponse(org.opensearch.action.bulk.BulkItemResponse) GetResponse(org.opensearch.action.get.GetResponse) MultiTermVectorsResponse(org.opensearch.client.core.MultiTermVectorsResponse) ReplicationResponse(org.opensearch.action.support.replication.ReplicationResponse) DocWriteResponse(org.opensearch.action.DocWriteResponse) Response(org.opensearch.client.Response) GetSourceResponse(org.opensearch.client.core.GetSourceResponse) UpdateResponse(org.opensearch.action.update.UpdateResponse) ListTasksResponse(org.opensearch.action.admin.cluster.node.tasks.list.ListTasksResponse) TermVectorsResponse(org.opensearch.client.core.TermVectorsResponse) DeleteResponse(org.opensearch.action.delete.DeleteResponse) CreateIndexResponse(org.opensearch.client.indices.CreateIndexResponse) BulkByScrollResponse(org.opensearch.index.reindex.BulkByScrollResponse) MultiGetItemResponse(org.opensearch.action.get.MultiGetItemResponse) BulkResponse(org.opensearch.action.bulk.BulkResponse) MultiTermVectorsRequest(org.opensearch.client.core.MultiTermVectorsRequest) CreateIndexRequest(org.opensearch.client.indices.CreateIndexRequest) CreateIndexResponse(org.opensearch.client.indices.CreateIndexResponse) XContentBuilder(org.opensearch.common.xcontent.XContentBuilder)

Aggregations

MultiTermVectorsRequest (org.opensearch.client.core.MultiTermVectorsRequest)8 TermVectorsRequest (org.opensearch.client.core.TermVectorsRequest)8 DocWriteRequest (org.opensearch.action.DocWriteRequest)7 BulkRequest (org.opensearch.action.bulk.BulkRequest)7 DeleteRequest (org.opensearch.action.delete.DeleteRequest)7 GetRequest (org.opensearch.action.get.GetRequest)7 MultiGetRequest (org.opensearch.action.get.MultiGetRequest)7 IndexRequest (org.opensearch.action.index.IndexRequest)7 WriteRequest (org.opensearch.action.support.WriteRequest)7 UpdateRequest (org.opensearch.action.update.UpdateRequest)7 GetSourceRequest (org.opensearch.client.core.GetSourceRequest)7 DeleteByQueryRequest (org.opensearch.index.reindex.DeleteByQueryRequest)7 ReindexRequest (org.opensearch.index.reindex.ReindexRequest)7 UpdateByQueryRequest (org.opensearch.index.reindex.UpdateByQueryRequest)7 DeleteStoredScriptRequest (org.opensearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest)5 GetStoredScriptRequest (org.opensearch.action.admin.cluster.storedscripts.GetStoredScriptRequest)5 PutStoredScriptRequest (org.opensearch.action.admin.cluster.storedscripts.PutStoredScriptRequest)5 ExplainRequest (org.opensearch.action.explain.ExplainRequest)5 FieldCapabilitiesRequest (org.opensearch.action.fieldcaps.FieldCapabilitiesRequest)5 ClearScrollRequest (org.opensearch.action.search.ClearScrollRequest)5