use of org.elasticsearch.action.index.IndexRequest in project pinpoint by naver.
the class ElasticsearchIT_6_0_x_IT method testIndexV60UP.
private void testIndexV60UP(PluginTestVerifier verifier) throws IOException {
IndexRequest indexRequest = new IndexRequest("postv6", "doc", "3");
String jsonString = "{" + "\"user\":\"kimchy\"," + "\"postDate\":\"2013-01-30\"," + "\"message\":\"trying out Elasticsearch\"" + "}";
indexRequest.source(jsonString, XContentType.JSON);
Class<?> clazz;
try {
clazz = Class.forName("org.elasticsearch.client.RestHighLevelClient");
} catch (ClassNotFoundException e) {
throw new AssertionError(e);
}
Method method;
try {
method = clazz.getMethod("index", IndexRequest.class, Class.forName("[Lorg.apache.http.Header;"));
} catch (NoSuchMethodException | ClassNotFoundException e) {
throw new AssertionError(e);
}
try {
method.invoke(restHighLevelClient, indexRequest, new Header[] {});
} catch (IllegalAccessException | InvocationTargetException e) {
throw new AssertionError(e);
}
Method index;
try {
index = restHighLevelClient.getClass().getDeclaredMethod("index", IndexRequest.class, Class.forName("[Lorg.apache.http.Header;"));
} catch (NoSuchMethodException | ClassNotFoundException e) {
throw new AssertionError(e);
}
verifier.verifyTrace(event(ElasticsearchConstants.ELASTICSEARCH_EXECUTOR.getName(), index, null, ELASTICSEARCH_ADDRESS, "ElasticSearch", new ExpectedAnnotation(ElasticsearchConstants.ARGS_DSL_ANNOTATION_KEY.getName(), indexRequest.toString())));
}
use of 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);
}
}
use of 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);
}
}
use of 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]");
}
use of 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();
}
Aggregations