Elasticsearch Kibana 를 이용한 쿼리생성

By | 2021년 11월 13일
Table of Contents

Elasticsearch Kibana 를 이용한 쿼리생성

Elasticsearch 에서 사용되는 검색쿼리를 생성하는 것이 복잡하면,
Kibana 를 이용해 기초 쿼리를 생성하면 간편하게 복잡한 쿼리를 생성해 낼 수 있다.

Kibana Discover

우선 Elasticsearch 에 데이타를 임포트 한다.

Add index

인덱스가 확인되지 않으면, 아래 방법으로 인덱스를 추가해 준다.

쿼리 생성

인덱스가 추가되면 아래와 같이 필드명과 값을 이용해 쿼리를 생성할 수 있다.

and, or 를 이용해 검색 쿼리를 생성할 수 있다.

category : 책상 and (item_name : 1800 or item_option_name : 1800)

Elasticsearch 용 쿼리 조회

쿼리

curl -XGET 'nb.skyer9.pe.kr:9200/item_info/_search?pretty' -H 'Content-Type: application/json' -d'
{
  "from": 0,
  "size": 20,
  "sort": {
    "_score": "desc"
  },
  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "bool": {
                  "should": [
                    {
                      "match": {
                        "category": {
                          "query": "책상",
                          "boost": 10
                        }
                      }
                    }
                  ],
                  "minimum_should_match": 1
                }
              },
              {
                "bool": {
                  "should": [
                    {
                      "bool": {
                        "should": [
                          {
                            "match": {
                              "item_name": {
                                "query": "1800",
                                "boost": 2
                              }
                            }
                          }
                        ],
                        "minimum_should_match": 1
                      }
                    },
                    {
                      "bool": {
                        "should": [
                          {
                            "match": {
                              "item_option_name": {
                                "query": "1800",
                                "boost": 2
                              }
                            }
                          }
                        ],
                        "minimum_should_match": 1
                      }
                    }
                  ],
                  "minimum_should_match": 1
                }
              }
            ]
          }
        }
      ],
      "filter": [],
      "should": [],
      "must_not": []
    }
  }
}'

답글 남기기