【ElasticSearch】SpringDataElasticSearch 通过注解@Document自动创建索引失败

背景

  这里记录ElasticSearch通过@Document注解自动创建索引失败的情况

测试

  这里使用索引 index_demo 通过案例测试@Docuemnt注解在创建索引的过程中踩过的坑

@Data
@Document(indexName = "index_demo", type = "index_demo_type", shards = 1, replicas = 0, createIndex = true)
public class DemoIndex {

    @Id
    @Field(type = FieldType.Long)
    private Long userId;

    @Field(type = FieldType.Keyword)
    private String name;

}

  启动项目后发现索引index_demo并没有创建

   这里加上索引实体对应的repository文件后,重新启动

/**
 * @author Sam.yang
 * @since 2022/8/15 20:02
 */
public interface DemoIndexRepository extends ElasticsearchRepository<DemoIndex, Long> {
}

  通过在Kibana上查询,已经可以查询到对应的索引数据

 

posted @ 2022-08-15 20:23  听风是雨  阅读(1247)  评论(0)    收藏  举报
/* 看板娘 */