use of org.elasticsearch.action.index.IndexResponse in project fess by codelibs.
the class EsAbstractBehavior method delegateUpdate.
@Override
protected int delegateUpdate(final Entity entity, final UpdateOption<? extends ConditionBean> option) {
final EsAbstractEntity esEntity = (EsAbstractEntity) entity;
final IndexRequestBuilder builder = createUpdateRequest(esEntity);
final IndexResponse response = builder.execute().actionGet(indexTimeout);
long version = response.getVersion();
if (version != -1) {
esEntity.asDocMeta().version(version);
}
return 1;
}
use of org.elasticsearch.action.index.IndexResponse 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.elasticsearch.action.index.IndexResponse in project fess by codelibs.
the class EsAbstractBehavior method delegateUpdate.
@Override
protected int delegateUpdate(final Entity entity, final UpdateOption<? extends ConditionBean> option) {
final EsAbstractEntity esEntity = (EsAbstractEntity) entity;
final IndexRequestBuilder builder = createUpdateRequest(esEntity);
final IndexResponse response = builder.execute().actionGet(indexTimeout);
long version = response.getVersion();
if (version != -1) {
esEntity.asDocMeta().version(version);
}
return 1;
}
use of org.elasticsearch.action.index.IndexResponse 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.elasticsearch.action.index.IndexResponse in project xmall by Exrick.
the class ItemESMessageListener method onMessage.
@Override
public void onMessage(Message message) {
try {
// 从消息中取商品id
TextMessage textMessage = (TextMessage) message;
log.info("得到消息:" + textMessage.getText());
String[] text = textMessage.getText().split(",");
Long itemId = new Long(text[1]);
// 等待事务提交
Thread.sleep(1000);
// 更新索引
Settings settings = Settings.builder().put("cluster.name", ES_CLUSTER_NAME).build();
TransportClient client = new PreBuiltTransportClient(settings).addTransportAddress(new TransportAddress(InetAddress.getByName(ES_CONNECT_IP), 9300));
if ("add".equals(text[0])) {
// 根据商品id查询商品信息
SearchItem searchItem = itemMapper.getItemById(itemId);
String image = searchItem.getProductImageBig();
if (image != null && !"".equals(image)) {
String[] strings = image.split(",");
image = strings[0];
} else {
image = "";
}
searchItem.setProductImageBig(image);
IndexResponse indexResponse = client.prepareIndex(ITEM_INDEX, ITEM_TYPE, String.valueOf(searchItem.getProductId())).setSource(jsonBuilder().startObject().field("productId", searchItem.getProductId()).field("salePrice", searchItem.getSalePrice()).field("productName", searchItem.getProductName()).field("sub_title", searchItem.getSubTitle()).field("productImageBig", searchItem.getProductImageBig()).field("category_name", searchItem.getCategory_name()).endObject()).get();
} else if ("delete".equals(text[0])) {
DeleteResponse deleteResponse = client.prepareDelete(ITEM_INDEX, ITEM_TYPE, String.valueOf(itemId)).get();
}
log.info("处理消息成功");
client.close();
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations