use of org.opensearch.action.index.IndexRequestBuilder in project fess by codelibs.
the class EsAbstractBehavior method createInsertRequest.
protected IndexRequestBuilder createInsertRequest(final EsAbstractEntity esEntity) {
final IndexRequestBuilder builder = client.prepareIndex().setIndex(asEsIndex()).setSource(toSource(esEntity));
final String id = esEntity.asDocMeta().id();
if (id != null) {
builder.setId(id);
}
final RequestOptionCall<IndexRequestBuilder> indexOption = esEntity.asDocMeta().indexOption();
if (indexOption != null) {
indexOption.callback(builder);
}
return builder;
}
use of org.opensearch.action.index.IndexRequestBuilder in project fess by codelibs.
the class EsAbstractBehavior method delegateInsert.
// ===================================================================================
// Update
// ======
@Override
protected int delegateInsert(final Entity entity, final InsertOption<? extends ConditionBean> option) {
final EsAbstractEntity esEntity = (EsAbstractEntity) entity;
IndexRequestBuilder builder = createInsertRequest(esEntity);
final IndexResponse response = builder.execute().actionGet(indexTimeout);
esEntity.asDocMeta().id(response.getId());
return response.getResult() == Result.CREATED ? 1 : 0;
}
use of org.opensearch.action.index.IndexRequestBuilder in project fess by codelibs.
the class EsAbstractBehavior method delegateBatchRequest.
protected <BUILDER> int[] delegateBatchRequest(final List<? extends Entity> entityList, Function<EsAbstractEntity, BUILDER> call) {
@SuppressWarnings("unchecked") final BulkList<? extends Entity, BUILDER> bulkList = (BulkList<? extends Entity, BUILDER>) entityList;
final RequestOptionCall<BUILDER> builderEntityCall = bulkList.getEntityCall();
final BulkRequestBuilder bulkBuilder = client.prepareBulk();
for (final Entity entity : entityList) {
final EsAbstractEntity esEntity = (EsAbstractEntity) entity;
BUILDER builder = call.apply(esEntity);
if (builder instanceof IndexRequestBuilder) {
if (builderEntityCall != null) {
builderEntityCall.callback(builder);
}
bulkBuilder.add((IndexRequestBuilder) builder);
} else if (builder instanceof UpdateRequestBuilder) {
if (builderEntityCall != null) {
builderEntityCall.callback(builder);
}
bulkBuilder.add((UpdateRequestBuilder) builder);
} else if (builder instanceof DeleteRequestBuilder) {
if (builderEntityCall != null) {
builderEntityCall.callback(builder);
}
bulkBuilder.add((DeleteRequestBuilder) builder);
}
}
final RequestOptionCall<BulkRequestBuilder> builderCall = bulkList.getCall();
if (builderCall != null) {
builderCall.callback(bulkBuilder);
}
final BulkResponse response = bulkBuilder.execute().actionGet(bulkTimeout);
final BulkItemResponse[] itemResponses = response.getItems();
if (itemResponses.length != entityList.size()) {
throw new IllegalStateException("Invalid response size: " + itemResponses.length + " != " + entityList.size());
}
final int[] results = new int[itemResponses.length];
for (int i = 0; i < itemResponses.length; i++) {
final BulkItemResponse itemResponse = itemResponses[i];
final Entity entity = entityList.get(i);
if (entity instanceof EsAbstractEntity) {
((EsAbstractEntity) entity).asDocMeta().id(itemResponse.getId());
}
results[i] = itemResponse.isFailed() ? 0 : 1;
}
return results;
}
use of org.opensearch.action.index.IndexRequestBuilder in project fess by codelibs.
the class EsAbstractBehavior method createUpdateRequest.
protected IndexRequestBuilder createUpdateRequest(final EsAbstractEntity esEntity) {
final IndexRequestBuilder builder = client.prepareIndex().setIndex(asEsIndex()).setId(esEntity.asDocMeta().id()).setSource(toSource(esEntity));
final RequestOptionCall<IndexRequestBuilder> indexOption = esEntity.asDocMeta().indexOption();
if (indexOption != null) {
indexOption.callback(builder);
}
final Long seqNo = esEntity.asDocMeta().seqNo();
if (seqNo != null && seqNo.longValue() != SequenceNumbers.UNASSIGNED_SEQ_NO) {
esEntity.asDocMeta().seqNo(seqNo);
}
final Long primaryTerm = esEntity.asDocMeta().primaryTerm();
if (primaryTerm != null && primaryTerm.longValue() != SequenceNumbers.UNASSIGNED_PRIMARY_TERM) {
esEntity.asDocMeta().primaryTerm(primaryTerm);
}
return builder;
}
use of org.opensearch.action.index.IndexRequestBuilder in project fess by codelibs.
the class EsAbstractBehavior method createInsertRequest.
protected IndexRequestBuilder createInsertRequest(final EsAbstractEntity esEntity) {
final IndexRequestBuilder builder = client.prepareIndex().setIndex(asEsIndex()).setSource(toSource(esEntity));
final String id = esEntity.asDocMeta().id();
if (id != null) {
builder.setId(id);
}
final RequestOptionCall<IndexRequestBuilder> indexOption = esEntity.asDocMeta().indexOption();
if (indexOption != null) {
indexOption.callback(builder);
}
return builder;
}
Aggregations