ES使用桶聚合,默认是10个
可以在聚合的时候, 指定size
searchSourceBuilder.aggregation(AggregationBuilders.terms("sourceGroupby").field("A").size(20));
- ES 分区数目 只能在创建index的时候指定,无法创建后进行修改。想要修改;只能先创建新的索引,同时配置好分区数目等信息。然后使用reindex;把数据迁移到新的index上。
- ES使用时间,必须指定timeZone
boolQueryBuilder.filter(QueryBuilders.rangeQuery("c_time").gte("now-1d/d").lt("now-30s/d").timeZone("Asia/Shanghai")
static {
try {
Properties prop = new Properties();
InputStream in =
SaoImpl.class.getClassLoader().getResourceAsStream("elasticsearch.properties");
prop.load(in);
ESHOST = prop.getProperty("hosts").trim();
} catch (Exception e) {
logger.error("init error!", e);
}
}
@Bean()
RestHighLevelClient restHighLevelClient1() {
String[] urls = StringUtils.split(ESHOST, ",");
HttpHost[] host = new HttpHost[urls.length];
for (int i = 0; i < urls.length; i++) {
host[i] = HttpHost.create(urls[i]);
}
return new RestHighLevelClient(RestClient.builder(host));
}