import com.sangfor.taxation.common.monitor.ServiceMonitor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.elasticsearch.annotations.Document;
@EqualsAndHashCode(callSuper = true)
@Data
@Document(indexName = "service_monitor_#{T(java.time.LocalDate).now().toString()}")
public class ServiceMonitorEntity extends EsBaseEntity{
/**
* 应用id
*/
private Integer appId;
/**
* 服务id
*/
private Integer serviceId;
/**
* 服务名
*/
private String serviceName;
/**
* 服务监控信息
*/
private ServiceMonitor monitor;
/**
* 服务新建连接最大值
*/
private Long maxConnects;
/**
* 接入节点虚拟ip
*/
private String inNodeVirtualIp;
/**
* 发布节点虚拟ip
*/
private String appNodeVirtualIp;
}
@Document(indexName = “service_monitor_#{T(java.time.LocalDate).now().toString()}”)
可以看到有个大括号表达式,里卖弄可以设置函数表达式形成动态索引。
除此之外:es动态索引spel还可以自定义一个类去使用:
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @author: wkn
* @date: 2021-06-17 16:46
*/
public final class DateString {
public static String now() {
return new SimpleDateFormat("yyyy_MM_dd-HH-mm-ss").format(new Date());
}
}
@EqualsAndHashCode(callSuper = true)
@Data
@Document(indexName = "service_monitor_#{T(com.example.myself.persistent.timec.DateString).now()}")
public class ServiceMonitorEntity extends EsBaseEntity{
此时需注意:
indexName有以下规范限制:
Name of the Elasticsearch index.
Lowercase only
, *, ?, ", <, >, |, ` ` (space character), ,, #/li>
Cannot start with -, _, +
Cannot be . or ..
Cannot be longer than 255 bytes (note it is bytes, so multi-byte characters will count towards the 255 limit faster)
除了以上特殊字符不支持,冒号 :也不支持。