GeekIBLi

elasticsearch踩坑

2021-07-19

search.max_buckets

This limit can be set by changing the [search.max_buckets] cluster level setting.]];

1
2
3
4
5
6
PUT _cluster/settings
{
"persistent": {
"search.max_buckets": 100000
}
}

Required one of fields [field, script]

[Elasticsearch exception [type=illegal_argument_exception, reason=Required one of fields [field, script], but none were specified. ]

1
2
3
4
5
6
7
8
9
10
11
12
@Test
public void test1() {
NativeSearchQuery nativeSearchQuery = new NativeSearchQuery(QueryBuilders.matchAllQuery(), null);
Script script = new Script("doc['article.keyword']");
nativeSearchQuery.addAggregation(AggregationBuilders.terms("art")
.field("article.keyword").size(10)
.subAggregation(AggregationBuilders.dateHistogram("visitTime")
.field("visitTime") // 这一行没有写
.calendarInterval(DateHistogramInterval.HOUR)));
SearchHits<YjVisitData> search = elasticsearchRestTemplate.search(nativeSearchQuery, YjVisitData.class);
System.err.println("search.getAggregations().asList() {}" + search.getAggregations().asList().size());
}