Spring data动态创建索引引用实体字段
我正在尝试用 @Document 注释我的实体。
为什么要动态创建索引来引用字段lastTime?
例如:lastTime = "2022-03-8 00:00:00"
索引应创建为aaa-2022-03-08。
我应该如何设置@Doucument中的indexName?
@Data
@Document(indexName = "xth_alert-#{}")
public class EsAlert {
@Nullable
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
public Date lastTime;
}
谢谢
I am trying to annotate my entity with @Document.
Are there any why to create Index dynamiclly reference to the field lastTime?
for example: lastTime = "2022-03-8 00:00:00"
Index should be created as aaa-2022-03-08.
How should I set the indexName in @Doucument?
@Data
@Document(indexName = "xth_alert-#{}")
public class EsAlert {
@Nullable
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
public Date lastTime;
}
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短回答:
是的,您可以使用 SpEL 模板表达式摄取实体以存储在索引上,例如
"log-#{T(java.time.LocalDate).now().toString()}"
如果你的lastTime字段是根据当地时间生成的,结果将是这样的,
Short answer :
Yes, you can ingest entities to store on indexes with SpEL template expression like
"log-#{T(java.time.LocalDate).now().toString()}"
And if you lastTime field is generated by local time the result will be like this,