common-data-es使用说明
chenweida heeft deze pagina aangepast 7 jaren geleden

es 版本: 2.4.4

1.依赖common-data-es 工程

        <dependency>
            <groupId>com.yihu.base</groupId>
            <artifactId>common-data-es </artifactId>
            <version>${版本以项目中最新的版本为主}</version>
        </dependency>
        

2.在yml中添加es配置

     
spring:
  data:
    elasticsearch: #ElasticsearchProperties
      cluster-name: jkzl #默认即为elasticsearch  集群名
      cluster-nodes: 120.25.194.233:9300,120.25.194.233:9300 #配置es节点信息,逗号分隔,如果没有指定,则启动ClientNode

  # JEST (Elasticsearch HTTP client) (JestProperties)
  elasticsearch:
    jest:
      uris: http://192.168.226.133:9200
      connection-timeout: # Connection timeout in milliseconds.
      multi-threaded: true # Enable connection requests from multiple execution threads.

    
    

3.代码中使用spring注入方式使用


  @Autowired
  private ElastricSearchHelper elastricSearchHelper

  #spring提供的工具类
  @Autowired  
  private ElasticsearchTemplate elasticsearchTemplate;

4.ElastricSearchHelper方法解析

 实体类要继承 SaveModel



/**
 * 新增
 */
 public Boolean save(String index, String type, List<SaveModel> sms) {

}



/**
 * 修改
 * 需要先等到ID在更新ID更新
 */
public Boolean update(String index, String type, List<SaveModel> sms) {

}


/**
 * 删除
 *  需要先等到ID在更新ID删除
 */
private void deleteData(String index, String type, List<SaveModel> saveModels) {

}