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());
}
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());
}
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);
}
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);
}
}
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);
}
}
Aggregations