Skip to content

Commit

Permalink
fixes insert async
Browse files Browse the repository at this point in the history
  • Loading branch information
otaviojava committed Mar 27, 2018
1 parent d0dcd04 commit f5b0f6c
Showing 1 changed file with 6 additions and 8 deletions.
Expand Up @@ -18,6 +18,7 @@
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.QueryBuilder;
import org.jnosql.diana.api.ExecuteAsyncQueryException;
Expand Down Expand Up @@ -55,12 +56,12 @@ class DefaultElasticsearchDocumentCollectionManagerAsync implements Elasticsearc
}

@Override
public void insert(DocumentEntity entity){
public void insert(DocumentEntity entity) {
insert(entity, NOOP);
}

@Override
public void insert(DocumentEntity entity, Duration ttl){
public void insert(DocumentEntity entity, Duration ttl) {
insert(entity, ttl, e -> {
});
}
Expand All @@ -72,11 +73,8 @@ public void insert(DocumentEntity entity, Consumer<DocumentEntity> callBack) {
Document id = entity.find(ID_FIELD)
.orElseThrow(() -> new ElasticsearchKeyFoundException(entity.toString()));
Map<String, Object> jsonObject = getMap(entity);
byte[] bytes = JSONB.toJson(jsonObject).getBytes(UTF_8);
client.prepareIndex(index, entity.getName(), id.get(String.class)).setSource(bytes).execute()
.addListener(new SaveActionListener(callBack, entity));


IndexRequest request = new IndexRequest(index, entity.getName(), id.get(String.class)).source(jsonObject);
client.indexAsync(request, new SaveActionListener(callBack, entity));
}

@Override
Expand All @@ -100,7 +98,7 @@ public void update(DocumentEntity entity) {
}

@Override
public void update(DocumentEntity entity, Consumer<DocumentEntity> callBack){
public void update(DocumentEntity entity, Consumer<DocumentEntity> callBack) {
insert(entity, callBack);
}

Expand Down

0 comments on commit f5b0f6c

Please sign in to comment.