我有一个使用场景,需要在Elasticsearch中按月创建索引。想法是按月创建索引,以便于维护,并且可以在过期时删除。为了实现这一点,我使用了spring-batch,并且有一个每月的任务,将按月创建索引。对于Elasticsearch-Java集成,我使用了Spring-Data Elasticsearch实现。我现在面临的问题是,我无法找出如何使用Entity对象提供动态名称来创建索引和映射。我的当前实现是考虑单个索引进行的。请查看下面的代码,这是我用来创建索引的。
elasticsearchTemplate.createIndex(SingleChat.class);
elasticsearchTemplate.putMapping(SingleChat.class);
elasticsearchTemplate.refresh(SingleChat.class, true);
而 SingleChat 是我的实体类
@Document(indexName="singlemsgtemp_#{jobParameters['MONTH']}",type="singlechat")
public class SingleChat {
@org.springframework.data.annotation.Id
String Id;
@Field(type = FieldType.String)
String conservationId;
@Field(type = FieldType.String)
String from;
@Field(type = FieldType.String)
String to;
@Field(type = FieldType.String)
String msgContent;
@Field(type = FieldType.String)
String sessionId;
@Field(type = FieldType.Date, index = FieldIndex.not_analyzed, store = true, format = DateFormat.date_hour_minute_second_millis)
Date postedDate;
@Field(type = FieldType.Date, index = FieldIndex.not_analyzed, store = true, format = DateFormat.date_hour_minute_second_millis)
Date expireDate;
}
但是它并没有像预期的那样工作。我正在尝试其他一些方法。但我愿意接受建议。同时,请随意评论我的当前方法,它是否可行。如果需要更多细节,请告诉我。
spring-data-commons
添加到我的项目中,以便使用org.springframework.data.spel.ExpressionDependencies
。这不包含在spring-data-elasticsearch
中。 - nonNumericalFloat