Search in sources :

Example 71 with IndexRequest

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

the class DefaultIndexRequestFactoryTest method testGetIndexRequestWithPartitionKey.

@Test
public void testGetIndexRequestWithPartitionKey() throws Exception {
    IndexRequest indexRequest = INDEX_REQUEST_FACTORY.getIndexRequest(new OutgoingMessageEnvelope(SYSTEM, "shardKey", "id", EMPTY_MSG));
    assertEquals("shardKey", indexRequest.routing());
}
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.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 73 with IndexRequest

use of 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 74 with IndexRequest

use of 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 75 with IndexRequest

use of 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)

Aggregations

IndexRequest (org.elasticsearch.action.index.IndexRequest)177 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)36 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)34 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)33 IOException (java.io.IOException)28 Test (org.junit.Test)27 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)26 ElasticsearchException (org.elasticsearch.ElasticsearchException)20 IndexResponse (org.elasticsearch.action.index.IndexResponse)17 HashMap (java.util.HashMap)16 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)15 Map (java.util.Map)14 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)14 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)13 GetRequest (org.elasticsearch.action.get.GetRequest)13 BytesReference (org.elasticsearch.common.bytes.BytesReference)12 ArrayList (java.util.ArrayList)10 Matchers.anyBoolean (org.mockito.Matchers.anyBoolean)9 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)8 CreateIndexRequest (org.elasticsearch.client.indices.CreateIndexRequest)8