|
@ -1,5 +1,6 @@
|
|
|
package com.yihu.base.es.config;
|
|
|
|
|
|
import com.alibaba.druid.support.json.JSONUtils;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.base.es.config.model.ESIDEntity;
|
|
|
import io.searchbox.client.JestClient;
|
|
@ -98,8 +99,51 @@ public class ElastricSearchHelper {
|
|
|
return br.isSucceeded();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 自定义ID
|
|
|
* @param index
|
|
|
* @param type
|
|
|
* @param source
|
|
|
* @param idFieldString
|
|
|
* @return
|
|
|
*/
|
|
|
public Boolean saveWithCustomId(String index, String type, String source, String idFieldString) {
|
|
|
JestClient jestClient = null;
|
|
|
BulkResult br = null;
|
|
|
try {
|
|
|
//得到链接elasticFactory.getJestClient();
|
|
|
jestClient = elasticFactory.getJestClient();
|
|
|
int success = 0;
|
|
|
int error = 0;
|
|
|
Bulk.Builder bulk = new Bulk.Builder().defaultIndex(index).defaultType(type);
|
|
|
try {
|
|
|
|
|
|
Index indexObj = new Index.Builder(source).id(((JSONObject) JSONUtils.parse(source)).getString(idFieldString)).
|
|
|
build();
|
|
|
success++;
|
|
|
bulk.addAction(indexObj);
|
|
|
} catch (Exception e) {
|
|
|
logger.error(e.getMessage());
|
|
|
error++;
|
|
|
}
|
|
|
br = jestClient.execute(bulk.build());
|
|
|
logger.info("save flag:" + br.isSucceeded());
|
|
|
logger.info("save success:" + success);
|
|
|
logger.info("save error:" + error);
|
|
|
return br.isSucceeded();
|
|
|
} catch (Exception e) {
|
|
|
logger.error(" save error :" + e.getMessage());
|
|
|
} finally {
|
|
|
if (jestClient != null) {
|
|
|
jestClient.shutdownClient();
|
|
|
}
|
|
|
}
|
|
|
return br.isSucceeded();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 更新
|
|
|
*
|
|
|
* @param index
|
|
|
* @param type
|
|
|
* @param sms
|
|
@ -147,6 +191,7 @@ public class ElastricSearchHelper {
|
|
|
|
|
|
/**
|
|
|
* 跟新
|
|
|
*
|
|
|
* @param index
|
|
|
* @param type
|
|
|
* @param _id
|