Search in sources :

Example 71 with IndexRequest

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

the class DefaultIndexRequestFactoryTest method testGetIndexRequestMessageBytes.

@Test
public void testGetIndexRequestMessageBytes() throws Exception {
    IndexRequest indexRequest = INDEX_REQUEST_FACTORY.getIndexRequest(new OutgoingMessageEnvelope(SYSTEM, "{\"foo\":\"bar\"}".getBytes(Charsets.UTF_8)));
    assertEquals(Collections.singletonMap("foo", "bar"), indexRequest.sourceAsMap());
}
Also used : IndexRequest(org.elasticsearch.action.index.IndexRequest) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope) Test(org.junit.Test)

Example 72 with IndexRequest

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

the class ElasticsearchSystemProducerTest method testSend.

@Test
public void testSend() throws Exception {
    OutgoingMessageEnvelope envelope = mock(OutgoingMessageEnvelope.class);
    IndexRequest indexRequest = mock(IndexRequest.class);
    when(INDEX_REQUEST_FACTORY.getIndexRequest(envelope)).thenReturn(indexRequest);
    producer.send(SOURCE_ONE, envelope);
    verify(processorOne).add(indexRequest);
}
Also used : IndexRequest(org.elasticsearch.action.index.IndexRequest) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope) Test(org.junit.Test)

Example 73 with IndexRequest

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

the class TestEmitter method createIndexRequest.

public IndexRequest createIndexRequest(Tuple2<Integer, String> element) {
    Map<String, Object> document = new HashMap<>();
    document.put(dataFieldName, element.f1);
    try {
        return new IndexRequest(index).id(element.f0.toString()).type(DOCUMENT_TYPE).source(xContentBuilderProvider.getBuilder().map(document));
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 74 with IndexRequest

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

the class RowElasticsearchEmitter method processUpsert.

private void processUpsert(RowData row, RequestIndexer indexer) {
    final byte[] document = serializationSchema.serialize(row);
    final String key = createKey.apply(row);
    if (key != null) {
        final UpdateRequest updateRequest = new UpdateRequest(indexGenerator.generate(row), documentType, key).doc(document, contentType).upsert(document, contentType);
        indexer.add(updateRequest);
    } else {
        final IndexRequest indexRequest = new IndexRequest(indexGenerator.generate(row), documentType).id(key).source(document, contentType);
        indexer.add(indexRequest);
    }
}
Also used : UpdateRequest(org.elasticsearch.action.update.UpdateRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 75 with IndexRequest

use of org.graylog.shaded.elasticsearch7.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())));
}
Also used : ExpectedAnnotation(com.navercorp.pinpoint.bootstrap.plugin.test.ExpectedAnnotation) Method(java.lang.reflect.Method) IndexRequest(org.elasticsearch.action.index.IndexRequest) InvocationTargetException(java.lang.reflect.InvocationTargetException)

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