ELK Stack Query DSL

김현우·2021년 10월 3일
0

GET : 조회

  • 전체 조회
GET index
  • Query Context
GET kibana_sample_data_ecommerce/_search
{
  "query": {
    "match": {
      "category": "men's"
    }
  }
}
  • Filter Context
GET kibana_sample_data_ecommerce/_search
{
  "query": {
    "bool": {
      "filter": {
        "term": {
          "day_of_week": "Monday"
        }
      }
    }
  }
}
  • Operator "and"
GET kibana_sample_data_ecommerce/_search
{
  "_source": "customer_full_name", 
  "query": {
    "match": {
      "customer_full_name": {
        "query": "mary bailey",
        "operator": "and"
      }
    }
  }
}
  • match_phrase
GET kibana_sample_data_ecommerce/_search
{
  "_source": ["customer_full_name"],
  "size": 20,
  "query": {
    "match_phrase": {
      "customer_full_name": "mary bailey"
    }
  }
}
  • multi_match
GET kibana_sample_data_ecommerce/_search
{
  "query": {
    "multi_match": {
      "query": "mary",
      "fields": [
        "customer_first_name",
        "customer_last_name"
        ]
    }
  }
}
  • range
GET kibana_sample_data_ecommerce/_search
{
  "query": {
    "range": {
      "products.base_price": {
        "gte": 10,
        "lte": 20
      }
    }
  }
}

PUT : 생성 혹은 수정

  • PUT으로 데이터 생성 혹은 수정
PUT index2/_doc/2
{
  "name": "김현우",
  "gender": "male",
  "age": 24
}

_bulk

  • 대용량 업로드
POST _bulk
{"index":{"_index":"test_index"}}
{"nickname":"hyunwoo","content":"ssac"}
{"index":{"_index":"test_index"}}
{"nickname":"kim","content":"ssac server"}
{"index":{"_index":"test_index"}}
{"nickname":"woo","content":"ssac client"}
{"index":{"_index":"test_index"}}
{"nickname":"hyunwookim","content":"ssac server"}
{"index":{"_index":"test_index"}}
{"nickname":"hyunwookim","content":"ssac web"}
{"index":{"_index":"test_index"}}
{"nickname":"man","content":"web ssac"}
{"index":{"_index":"test_index"}}
{"nickname":"man","content":"ssac client"}
{"index":{"_index":"test_index"}}
{"nickname":"fong","content":"ssac foever"}
{"index":{"_index":"test_index"}}
{"nickname":"fong","content":"ssac is good"}
{"index":{"_index":"test_index"}}
{"nickname":"hyunwookim","content":"ssac"}

ngram_analyzer

  • ngram analyzer
PUT kor_index
{
  "settings" : {
    "index":{
      "max_ngram_diff": 50,
      "analysis":{
        "analyzer":{
          "my_ngram_analyzer": {
            "tokenizer": "my_ngram_tokenizer"
          }
        },
        "tokenizer": {
          "my_ngram_tokenizer": {
            "type": "ngram",
            "min_gram": "1",
            "max_gram": "10"
          }
        }
      }
    }
  },
  "mappings": {
      "properties": {
        "subway": {
          "type": "text",
          "fields": {
            "ngram": {
              "type": "text",
              "analyzer": "my_ngram_analyzer"
            }
          }
        }
      }
  }
}

DELETE : 삭제

  • 데이터 삭제
DELETE index

타입설명
must쿼리를 실행하여 참인 도큐먼트 찾음, 복수의 쿼리 사용 시 AND 연산
must_not쿼리를 실행하여 거짓인 도큐먼트 찾음, 다른 타입과 같이 넣을 경우 도큐먼트에서 제외
should단독으로 사용 시 쿼리를 실행하여 참인 도큐먼트 찾음, 복수의 쿼리 사용 시 OR 연산, 다른 타입과 같이 넣을 경우 스코어에만 영향
filter쿼리를 실행하여 yes/no 형식의 필터 컨텍스트 실행
profile
두려워 말라, 놀라지 말라, 굳세게 하리라

0개의 댓글