Browse Source

Merge branch 'dev' of chenweida/jkzl-start into dev

chenweida 7 years ago
parent
commit
7f56779a99

+ 16 - 5
common-data-es-starter/src/main/java/com/yihu/base/es/config/ElastricSearchHelper.java

@ -98,7 +98,13 @@ public class ElastricSearchHelper {
        return br.isSucceeded();
        return br.isSucceeded();
    }
    }
    /**
     * 更新
     * @param index
     * @param type
     * @param sms
     * @return
     */
    public Boolean update(String index, String type, List<Object> sms) {
    public Boolean update(String index, String type, List<Object> sms) {
        JestClient jestClient = null;
        JestClient jestClient = null;
        BulkResult br = null;
        BulkResult br = null;
@ -140,7 +146,12 @@ public class ElastricSearchHelper {
    /**
    /**
     * 修改
     * 跟新
     * @param index
     * @param type
     * @param _id
     * @param source
     * @return
     */
     */
    public boolean update(String index, String type, String _id, JSONObject source) {
    public boolean update(String index, String type, String _id, JSONObject source) {
        JestClient jestClient = null;
        JestClient jestClient = null;
@ -166,21 +177,21 @@ public class ElastricSearchHelper {
    /**
    /**
     * 删除
     * 删除
     */
     */
    public void delete(String index, String type, List<Object> ESIDEntitys) {
    public void delete(String index, String type, List<Object> datas) {
        JestClient jestClient = null;
        JestClient jestClient = null;
        try {
        try {
            jestClient = elasticFactory.getJestClient();
            jestClient = elasticFactory.getJestClient();
            //根据id批量删除
            //根据id批量删除
            Bulk.Builder bulk = new Bulk.Builder().defaultIndex(index).defaultType(type);
            Bulk.Builder bulk = new Bulk.Builder().defaultIndex(index).defaultType(type);
            for (Object obj : ESIDEntitys) {
            for (Object obj : datas) {
                Delete indexObj = new Delete.Builder(((ESIDEntity) obj).getId()).build();
                Delete indexObj = new Delete.Builder(((ESIDEntity) obj).getId()).build();
                bulk.addAction(indexObj);
                bulk.addAction(indexObj);
            }
            }
            BulkResult br = jestClient.execute(bulk.build());
            BulkResult br = jestClient.execute(bulk.build());
            logger.info("delete data count:" + ESIDEntitys.size());
            logger.info("delete data count:" + datas.size());
            logger.info("delete flag:" + br.isSucceeded());
            logger.info("delete flag:" + br.isSucceeded());
        } catch (Exception e) {
        } catch (Exception e) {
            e.printStackTrace();
            e.printStackTrace();