[elasticsearc] max_clause_count 설정

HI·2024년 12월 24일

max_clause_count ?

max_clause_count 는 쿼리에서 사용할 수 있는 최대 절 수 이다.
7버전까지는 elasticsearch.yml에서 수정해서 사용할 수 있었는데, 8버전부터 서버 상태에 따라 동적할당만 되도록 수정되었다.

확인 방법

GET _cluster/settings?include_defaults&filter_path=**.max_clause_count

내 서버의 max_clause_count 계산 방법

https://github.com/elastic/elasticsearch/blob/8.13/server/src/main/java/org/elasticsearch/search/SearchUtils.java#L18
해당 코드를 보면

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_multiwildcard를 사용하는데 https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-multi-term-query.html 문서에 따르면
sapn_multiwildcard를 함께 사용할때 확장이 되고 오류가 날 수 있다는 식으로 나와있다.

즉 정리하면

  • 쿼리는 보여지는 것 보다 확장되서 검색될 수 있고 이때 쿼리 절의 수가 max_cluase_count 보다 작아야함!
  • 같은 쿼리여도 어떤 색인에 검색하느냐에 따라 오류가 날 수 있고, 안날 수 있다!
  • 검색하는 색인의 필드가 많은 텀을 가지고 있을 수록 확장되는 개수도 다르기 때문!

0개의 댓글