Elasticsearch filter cache 테스트하기

By | 2022년 7월 16일
Table of Contents

Elasticsearch filter cache 테스트하기

참조

필터 캐시를 테스트하기 위해서는 대량의 데이타가 필요하다.
서버 메모리는 4G 이상으로 한다.

한줄요약

  1. term 쿼리는 캐시되지 않는다.
  2. match 쿼리는 value 가 numeric/keyword 인경우 캐시된다.(text 는 안된다.)
  3. range 쿼리는 캐시된다.

데이타 준비

여기 를 참조해서 데이타를 다운받는다.

Elasticsearch 설치

여기 를 참조해 ES 를 설치한다.

kibana 설치

CSV 업로드 수단중에 키바나가 가장 편한 듯 하다.

sudo apt install kibana

sudo systemctl daemon-reload
sudo systemctl enable kibana.service

sudo systemctl start kibana.service

키바나 원격접속은 항상 위험하므로 접속 가능한 아이피를 제한할 수단을 가지고 있는게 좋다.

sudo vi /etc/kibana/kibana.yml
......
server.host: "0.0.0.0"
......
sudo systemctl restart kibana.service

데이타 업로드

키바나는 100M 의 사이즈 제한이 있으므로,
다운받은 식당 데이타를 열어 10만건 정도만 남기고 나머지는 삭제한다.
파일형식은 UTF-8 로 한다.

filter 캐시 확인하기

curl -XGET 'http://localhost:9200/_nodes/stats/indices/query_cache?human&pretty' -H 'Content-Type: application/json'

term 쿼리는 캐시되지 않는다.
참조

curl -XGET 'http://localhost:9200/test_index/_search?pretty' -H 'Content-Type: application/json' -d '{
  "query": {
    "bool": {
      "filter": [
        { "term": { "사업장명": "네네치킨 마곡나루점" } }
      ]
    }
  }
}'

curl -XGET 'http://localhost:9200/_nodes/stats/indices/query_cache?human&pretty' -H 'Content-Type: application/json'

match 쿼리의 경우 value 가 numeric/keyword 인 경우 캐시가 된다.
value 가 text 인 경우 캐시되지 않는다.

아래 쿼리를 3-40 회 반복해서 호출하면 캐시가 생겨나는 것을 확인할 수 있다.

# long
curl -XGET 'http://localhost:9200/test_index/_search?pretty' -H 'Content-Type: application/json' -d '{
  "query": {
    "bool": {
      "filter": [
        { "match": { "폐업일자": 20220506 } }
      ]
    }
  }
}'

# keyword
curl -XGET 'http://localhost:9200/test_index/_search?pretty' -H 'Content-Type: application/json' -d '{
  "query": {
    "bool": {
      "filter": [
        { "match": { "최종수정시점": "20170918111246" } }
      ]
    }
  }
}'

# text
curl -XGET 'http://localhost:9200/test_index/_search?pretty' -H 'Content-Type: application/json' -d '{
  "query": {
    "bool": {
      "filter": [
        { "match": { "도로명전체주소": "능동로" } }
      ]
    }
  }
}'

curl -XGET 'http://localhost:9200/_nodes/stats/indices/query_cache?human&pretty' -H 'Content-Type: application/json'

range 쿼리는 캐시된다.
아래 쿼리를 3-40 회 반복해서 호출하면 캐시가 생겨나는 것을 확인할 수 있다.

curl -XGET 'http://localhost:9200/test_index/_search?pretty' -H 'Content-Type: application/json' -d '{
  "query": {
    "bool": {
      "filter": [
        { "range": { "번호": {
          "gte": 50,
          "lt": 150
        } } }
      ]
    }
  }
}'

curl -XGET 'http://localhost:9200/_nodes/stats/indices/query_cache?human&pretty' -H 'Content-Type: application/json'

답글 남기기