Elasticsearch 7.6.2 版本 @Document 注解 shards配置不生效

Elasticsearch 7.6.2 版本 @Document 注解 shards配置不生效

7.6.2版本中@Document注解shards属性默认为1,配置为5后,创建出来的索引,仍然只有1个分片

@Document(indexName = "stu1", shards = 5)
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Stu {

    @Id
    private Long stuId;

    @Field(store = true)
    private String stuName;

    @Field(store = true)
    private Integer age;
}

@RunWith(SpringRunner.class)
@SpringBootTest(classes = ESApplication.class)
public class ESTest {

    @Autowired
    private ElasticsearchRestTemplate elasticsearchRestTemplate;

    @Test
    public void createStuIndex() {
        Stu stu = new Stu(1001L, "leslie", 18);

        IndexCoordinates indexCoordinates = elasticsearchRestTemplate.getIndexCoordinatesFor(stu.getClass());
        IndexQuery indexQuery = new IndexQueryBuilder().withObject(stu).build();
//        elasticsearchRestTemplate.save(stu);
        elasticsearchRestTemplate.index(indexQuery, indexCoordinates);
    }
}

老师请问,创建出来的索引的 shards 参数可以通过在 @Document 注解中配置实现么。还是只支持默认的 shards。

正在回答

登陆购买课程后可参与讨论,去登陆

1回答

嗯对,这个shard的确不生效,不用管。索引前期取消创建好就行。另外版本一定要和springboot的统一啊

  • leslie1996 提问者 #1
    好哒,谢谢老师,我这个版本和springboot是统一的
    2020-06-10 18:44:18
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师