max_clause_count 는 쿼리에서 사용할 수 있는 최대 절 수 이다.
7버전까지는 elasticsearch.yml에서 수정해서 사용할 수 있었는데, 8버전부터 서버 상태에 따라 동적할당만 되도록 수정되었다.
GET _cluster/settings?include_defaults&filter_path=**.max_clause_count
ong maxClauseCount = (heapInMb * 64 / threadPoolSize);
return Math.max(DEFAULT_MAX_CLAUSE_COUNT, (int) maxClauseCount);
기본값은 1024이고 서버에 따라 크게 설정될 수 있다.
(heapInMb * 64 / threadPoolSize) 공식의 변수는
heapInMb : jvm.option에서 본인이 설정한 jvm 값인데 mb로 환산해야 함.threadPoolSize : 이 값은GET _cluster/settings?include_defaults&filter_path=**.thread_pool.search.size
명령어로 확인 가능.
예시> heaplnMb = 30GB(30,720mb) , threadPoolSize=37 이라면
(30,720 X 64) / 37 = 40,124
max_clause_count는 40124가 된다.
즉, 8버전 부터 max_clause_count 바꾸고 싶다면 heaplnMb, threadPoolSize 값을 변경해야 하는데.
heaplnMb는 30GB가 최대이다.
threadPoolSize는 하단과 같이 변경 가능하다.
#elasticsearch.yml 에서 수정 가능.
thread_pool:
write:
size: 30
하지만 스레드 변경은 주의해서 해야할것 같다.
max_clause_count 값 계산에 대해 알아보았는데,
내 max_clause_count 가 1024 인데 1024 절대 넘지 않는 쿼리인데 오류가 나는 경우가 나타날 수 있다.
이런 경우는 실제 쿼리가 검색될 때 확장이 될 수 있다.
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"span_near": {
"in_order": false,
"clauses": [
{
"span_multi": {
"match": {
"wildcard": {
"description": "모터*"
}
}
}
},
{
"span_term": {
"description": "자동차"
}
}
],
"slop": 1
}
}
]
}
}
]
}
},
"from": 0,
"track_total_hits": true
}
위의 쿼리가 max_clause_count 를 넘는다는 오류가 발생했는데 절대 길지 않는 쿼리인데 오류가 나왔다.
쿼리에서 span_multi 와 wildcard를 사용하는데 https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-multi-term-query.html 문서에 따르면
sapn_multi와 wildcard를 함께 사용할때 확장이 되고 오류가 날 수 있다는 식으로 나와있다.
즉 정리하면