3

es~依赖包版本对索引初始化的影响

 2 years ago
source link: https://www.cnblogs.com/lori/p/15648832.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

es~依赖包版本对索引初始化的影响

es依赖包我们通常指两个org.elasticsearch:elasticsearchorg.elasticsearch.client:elasticsearch-rest-high-level-client,这两个包的版本需要对应上,你的索引初始化才能生效,否则你在实体上添加的@Setting,@Mapping是不会生效的。

对于springboot2.2.6.RELEASE版本的spring-boot-starter-data-elasticsearch来说,我们选择以下两个版本的客户端,是比较兼容的

  <dependency>
      <groupId>org.elasticsearch.client</groupId>
      <artifactId>elasticsearch-rest-high-level-client</artifactId>
      <version>6.5.4</version>
  </dependency>
  <!--  elasticsearch对应兼容版本为6.8.7-->
  <dependency>
      <groupId>org.elasticsearch</groupId>
      <artifactId>elasticsearch</artifactId>
      <version>6.8.7</version>
  </dependency>

实体上添加初始化索引

  • es-mapping.json内容,确定了分片数据,副本数据,分页数等
{
  "index": {
    // 分页数
    "max_result_window": 1000000,
    // 分片数,30G一个片
    "number_of_shards": 10,
    // 副本
    "number_of_replicas": 1
  }
}
  • 实体EventRecord内容
@Document(indexName = "kc_event_logger")
@Setting(settingPath = "mapping/es-setting.json")
@Data
public class EventRecord implements Serializable {
}
  • 生成的索引也是没有问题的

注意@Mapping(mappingPath = "mapping/es-mapping.json") 这个根据xml生成mapping的我测试总有问题,而且,使用上面的方法不需要你添加@Mapping了,因为索引的mapping已经根据实体字段动态生成了。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK