use of org.elasticsearch.action.bulk.BulkResponse in project Zpider by zeroized.
the class ElasticClient method bulkIndex.
public List<String> bulkIndex(List<Map<String, ?>> docs) throws IOException {
BulkRequest bulkRequest = new BulkRequest();
for (Map<String, ?> doc : docs) {
IndexRequest indexRequest = new IndexRequest(index, type);
indexRequest.source(doc);
bulkRequest.add(indexRequest);
}
BulkResponse bulkResponse = highLevelClient.bulk(bulkRequest);
return Arrays.stream(bulkResponse.getItems()).map(BulkItemResponse::getId).collect(Collectors.toList());
}
use of org.elasticsearch.action.bulk.BulkResponse in project jnosql-diana-driver by eclipse.
the class DefaultElasticsearchDocumentCollectionManagerAsync method delete.
@Override
public void delete(DocumentDeleteQuery query, Consumer<Void> callBack) {
requireNonNull(query, "query is required");
requireNonNull(callBack, "callBack is required");
query.getCondition().orElseThrow(() -> new IllegalArgumentException("condition is required"));
DocumentQuery select = new ElasticsearchDocumentQuery(query);
List<DocumentEntity> entities = EntityConverter.query(select, client, index);
if (entities.isEmpty()) {
callBack.accept(null);
return;
}
BulkRequest bulk = new BulkRequest();
entities.stream().map(entity -> entity.find(ID_FIELD).get().get(String.class)).map(id -> new DeleteRequest(index, query.getDocumentCollection(), id)).forEach(bulk::add);
ActionListener<BulkResponse> listener = new ActionListener<BulkResponse>() {
@Override
public void onResponse(BulkResponse bulkItemResponses) {
callBack.accept(null);
}
@Override
public void onFailure(Exception e) {
throw new ExecuteAsyncQueryException("An error when delete on elasticsearch", e);
}
};
client.bulkAsync(bulk, listener);
}
use of org.elasticsearch.action.bulk.BulkResponse in project bibot by alfintech.
the class ElasticPublisher method publishEvents.
@Override
public void publishEvents(List<CalendarEvent> calendarEvents) throws IOException {
BulkRequestBuilder bulkRequest = client.prepareBulk();
Date currentTime = Calendar.getInstance().getTime();
for (CalendarEvent calendarEvent : calendarEvents) {
System.out.println(calendarEvent);
for (String currency : calendarEvent.getCurrencies()) {
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().field("eventId", calendarEvent.getEventId()).field("currency", currency).field("title", calendarEvent.getTitle()).field("eventDate", calendarEvent.getEventDate()).field("createdDate", calendarEvent.getCreatedDate()).field("voteCount", calendarEvent.getVoteCount()).field("positiveVoteCount", calendarEvent.getPositiveVoteCount()).field("percentagePositiveVoteCount", calendarEvent.getPercentagePositiveVoteCount()).field("insertionDate", currentTime).endObject();
String idAsString = new Long(calendarEvent.getEventId()).toString();
bulkRequest.add(client.prepareIndex("calendarevents", "minutely", idAsString).setSource(builder));
}
}
BulkResponse response = bulkRequest.get();
LOG.debug(response.toString());
}
use of org.elasticsearch.action.bulk.BulkResponse in project bibot by alfintech.
the class ElasticPublisher method publishMarketData.
@Override
public void publishMarketData(List<IntervalPrice> marketDataList) throws IOException {
BulkRequestBuilder bulkRequest = client.prepareBulk();
for (IntervalPrice marketData : marketDataList) {
System.out.println(marketData);
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().field("currencyPair", marketData.getCurrencyPair().toString()).field("openDate", marketData.getOpenTime()).field("closeDate", marketData.getCloseTime()).field("openPrice", BigDecimalUtil.toDouble(marketData.getOpen())).field("closePrice", BigDecimalUtil.toDouble(marketData.getClose())).field("highPrice", BigDecimalUtil.toDouble(marketData.getHigh())).field("lowPrice", BigDecimalUtil.toDouble(marketData.getLow())).field("intervalVolume", BigDecimalUtil.toDouble(marketData.getIntervalVolume())).field("dayVolume", BigDecimalUtil.toDouble(marketData.getDayVolume())).endObject();
bulkRequest.add(client.prepareIndex("marketdata", "minutely", marketData.getCurrencyPair().toString() + marketData.getOpenTime().getTime()).setSource(builder));
}
BulkResponse response = bulkRequest.get();
LOG.debug(response.toString());
}
use of org.elasticsearch.action.bulk.BulkResponse in project vertigo by KleeGroup.
the class ESStatement method putAll.
/**
* @param indexCollection Collection des indexes à insérer
*/
void putAll(final Collection<SearchIndex<K, I>> indexCollection) {
// Injection spécifique au moteur d'indexation.
try {
final BulkRequestBuilder bulkRequest = esClient.prepareBulk().setRefreshPolicy(BULK_REFRESH);
for (final SearchIndex<K, I> index : indexCollection) {
try (final XContentBuilder xContentBuilder = esDocumentCodec.index2XContentBuilder(index)) {
bulkRequest.add(esClient.prepareIndex().setIndex(indexName).setType(typeName).setId(index.getURI().urn()).setSource(xContentBuilder));
}
}
final BulkResponse bulkResponse = bulkRequest.execute().actionGet();
if (bulkResponse.hasFailures()) {
throw new VSystemException("Can't putAll {0} into {1} index.\nCause by {2}", typeName, indexName, bulkResponse.buildFailureMessage());
}
} catch (final IOException e) {
handleIOException(e);
}
}
Aggregations