Search in sources :

Example 76 with IndexRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest in project beam by apache.

the class HadoopFormatIOElasticIT method prepareElasticIndex.

private static void prepareElasticIndex() throws IOException {
    RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost(options.getElasticServerIp(), options.getElasticServerPort(), "http")));
    for (int i = 0; i < 1000; i++) {
        IndexRequest request = new IndexRequest(ELASTIC_INDEX_NAME).source(createElasticRow(i));
        client.index(request, RequestOptions.DEFAULT);
    }
}
Also used : HttpHost(org.apache.http.HttpHost) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 77 with IndexRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest in project beam by apache.

the class HadoopFormatIOElasticTest method prepareElasticIndex.

private static void prepareElasticIndex() throws IOException {
    RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost(elasticsearch.getContainerIpAddress(), elasticsearch.getMappedPort(9200), "http")));
    for (int i = 0; i < TEST_DATA_ROW_COUNT; i++) {
        IndexRequest request = new IndexRequest(ELASTIC_INDEX_NAME).source(createElasticRow(ELASTIC_TYPE_ID_PREFIX + i, "Faraday" + i));
        client.index(request, RequestOptions.DEFAULT);
    }
}
Also used : HttpHost(org.apache.http.HttpHost) RestHighLevelClient(org.elasticsearch.client.RestHighLevelClient) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 78 with IndexRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest in project hazelcast by hazelcast.

the class AuthElasticSinksTest method given_clientWithWrongPassword_whenWriteToElasticSink_thenFailWithAuthenticationException.

@Test
public void given_clientWithWrongPassword_whenWriteToElasticSink_thenFailWithAuthenticationException() {
    ElasticsearchContainer container = ElasticSupport.secureElastic.get();
    String containerIp = container.getContainerIpAddress();
    Integer port = container.getMappedPort(PORT);
    Sink<TestItem> elasticSink = new ElasticSinkBuilder<>().clientFn(() -> client("elastic", "WrongPassword", containerIp, port)).bulkRequestFn(() -> new BulkRequest().setRefreshPolicy(RefreshPolicy.IMMEDIATE)).mapToRequestFn((TestItem item) -> new IndexRequest("my-index").source(item.asMap())).retries(0).build();
    Pipeline p = Pipeline.create();
    p.readFrom(TestSources.items(new TestItem("id", "Frantisek"))).writeTo(elasticSink);
    assertThatThrownBy(() -> submitJob(p)).hasRootCauseInstanceOf(ElasticsearchStatusException.class).hasStackTraceContaining("unable to authenticate user [elastic]");
}
Also used : BulkRequest(org.elasticsearch.action.bulk.BulkRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) ElasticsearchStatusException(org.elasticsearch.ElasticsearchStatusException) ElasticsearchContainer(org.testcontainers.elasticsearch.ElasticsearchContainer) TestItem(com.hazelcast.jet.elastic.CommonElasticSinksTest.TestItem) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 79 with IndexRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest in project hazelcast by hazelcast.

the class AuthElasticSinksTest method given_authenticatedClient_whenWriteToElasticSink_thenFinishSuccessfully.

@Test
public void given_authenticatedClient_whenWriteToElasticSink_thenFinishSuccessfully() throws IOException {
    Sink<TestItem> elasticSink = new ElasticSinkBuilder<>().clientFn(elasticClientSupplier()).bulkRequestFn(() -> new BulkRequest().setRefreshPolicy(RefreshPolicy.IMMEDIATE)).mapToRequestFn((TestItem item) -> new IndexRequest("my-index").source(item.asMap())).build();
    Pipeline p = Pipeline.create();
    p.readFrom(TestSources.items(new TestItem("id", "Frantisek"))).writeTo(elasticSink);
    submitJob(p);
    assertSingleDocument();
}
Also used : BulkRequest(org.elasticsearch.action.bulk.BulkRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) TestItem(com.hazelcast.jet.elastic.CommonElasticSinksTest.TestItem) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Test(org.junit.Test)

Example 80 with IndexRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.index.IndexRequest in project elasticsearch-jdbc by jprante.

the class StandardSink method index.

@Override
public void index(IndexableObject object, boolean create) throws IOException {
    if (clientAPI == null) {
        return;
    }
    if (Strings.hasLength(object.index())) {
        setIndex(object.index());
    }
    if (Strings.hasLength(object.type())) {
        setType(object.type());
    }
    if (Strings.hasLength(object.id())) {
        setId(object.id());
    }
    IndexRequest request = Requests.indexRequest(this.index).type(this.type).id(getId()).source(object.build());
    if (object.meta(ControlKeys._version.name()) != null) {
        request.versionType(VersionType.EXTERNAL).version(Long.parseLong(object.meta(ControlKeys._version.name())));
    }
    if (object.meta(ControlKeys._routing.name()) != null) {
        request.routing(object.meta(ControlKeys._routing.name()));
    }
    if (object.meta(ControlKeys._parent.name()) != null) {
        request.parent(object.meta(ControlKeys._parent.name()));
    }
    if (object.meta(ControlKeys._timestamp.name()) != null) {
        request.timestamp(object.meta(ControlKeys._timestamp.name()));
    }
    if (object.meta(ControlKeys._ttl.name()) != null) {
        request.ttl(Long.parseLong(object.meta(ControlKeys._ttl.name())));
    }
    if (logger.isTraceEnabled()) {
        logger.trace("adding bulk index action {}", request.source().toUtf8());
    }
    clientAPI.bulkIndex(request);
}
Also used : IndexRequest(org.elasticsearch.action.index.IndexRequest)

Aggregations

IndexRequest (org.elasticsearch.action.index.IndexRequest)187 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)37 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)37 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)34 IOException (java.io.IOException)30 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)27 Test (org.junit.Test)27 ElasticsearchException (org.elasticsearch.ElasticsearchException)21 IndexResponse (org.elasticsearch.action.index.IndexResponse)20 HashMap (java.util.HashMap)17 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)17 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)17 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)17 Map (java.util.Map)15 GetRequest (org.elasticsearch.action.get.GetRequest)14 CreateIndexRequest (org.elasticsearch.client.indices.CreateIndexRequest)12 BytesReference (org.elasticsearch.common.bytes.BytesReference)12 ArrayList (java.util.ArrayList)11 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)10 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)9