我想在使用 ElasticsearchTemplate 创建新索引时使用 elasticsearch.yml 中指定的副本数设置。这样做的目的是根据运行 ES 的环境设置副本数。例如:在实时中使用 4 个副本,在测试中使用 2 个副本。
我认为这可以通过在每种环境中的 elasticsearch.yml 中将副本数设置为适当的值来实现。
但是当我使用 ElasticsearchTemplate 创建新索引时(例如,通过使用 Spring Data ES 存储库),创建索引请求包含@Document注释中的默认值 1。
@Persistent
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface Document {
String indexName();
String type() default "";
short shards() default 5;
short replicas() default 1;
String refreshInterval() default "1s";
String indexStoreType() default "fs";
}
因此,不使用 elasticsearch.yml 中的默认值。有没有办法强制使用每个设置的默认设置?
我认为一种方法可能是使用索引模板,但是还有另一种方法吗?
谢谢
您使用的是哪个版本的 spring 数据弹性搜索,但在 2.1.7 中,@Document
中有一个新属性
boolean useServerConfiguration() default false;
如果将其设置为 true,则 Spring 数据存储库在创建索引请求时将不附带默认设置。