ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • profile을 통해 실제 쿼리가 어떻게 구성되는지 확인해보기
    Elasticsearch 2025. 3. 27. 20:59

    예시 데이터

    {
        "id": "park_rocky-mountain",
        "title": "Rocky Mountain",
        "description": "Bisected north to south by the Continental Divide, this portion of the Rockies has ecosystems varying from over 150 riparian lakes to montane and subalpine forests to treeless alpine tundra."
    }

     

    "profile"을 통해 실제 쿼리가 어떻게 진행되는지 확인

     

    필드 미지정 시 Query?

    GET my-index/_search
    {
        "profile": true,
        "query": {
            "query_string": {
              "query":  "(\"park\")"
            }
        }
    }
    description 확인

     
    필드 미지정 시 모든 필드에 search를 하는것을 확인
     


    괄호 밖과 안에서 서로 다른 필드 지정

    case 1:

    GET my-index/_search
    {
        "profile": true,
        "query": {
            "query_string": {
              "query":  "id:(\"park\")"
            }
        }
    }

     
    case 2:

    GET my-index/_search
    {
        "profile": true,
        "query": {
            "query_string": {
              "query":  "id:((\"park\") AND title:(\"mountain\"))"
            }
        }
    }

     

    profile 결과는 각 쿼리 단계별로 소요된 시간과 리소스 사용량을 JSON 형태로 제공합니다.
    이를 통해 어떤 부분이 성능 저하를 유발하는지 파악하고, 인덱스 구조나 쿼리 문법을 최적화할 수 있습니다.

    활용 방안:
    • 인덱스 최적화: 자주 검색되는 필드나 패턴을 파악하여, 해당 필드에 대한 인덱싱 전략을 조정할 수 있습니다.
    • 쿼리 구조 개선: 불필요한 복잡한 쿼리 구조를 단순화하거나, 효율적인 검색 연산자로 변경하여 성능을 향상시킬 수 있습니다.

Designed by Tistory.