검색

엘라스틱 서치는 데이터를 저장할때 실제로 검색에 사용되는 검색어인 Term으로 분석과정을 거쳐 저장하기 때문에 검색 시 대소문자, 단수 복수, 원형 여부와 상관없이 검색이 가능함. 이런 특징을 full text search, 한국어로는 전문검색이라고 함.

Query DSL(Domain Specific Language)

JPA의 QueryDSL과는 이름만 유사할 뿐임. 엘라스틱서치에서 검색을 위한 쿼리 기능을 QueryDSL이라고 함. 엘라스틱 서치의 QueryDSL은 모두 json형식으로 입력해야 함.

full-text query

  1. match_all

    GET my_index/_search
    
  2. match

    GET my_index/_search
    {
      "query": {
        "match": {
          "message": "dog"
        }
      }
    }
    
    GET my_index/_search
    {
      "query": {
        "match": {
          "message": "quick dog"
        }
      }
    }
    
    GET my_index/_search
    {
      "query": {
        "match": {
          "message": {
            "query": "quick dog",
            "operator": "and"
          }
        }
      }
    }
    
  3. match_phrase

    GET my_index/_search
    {
      "query": {
        "match_phrase": {
          "message": "lazy dog"
        }
      }
    }
    
    GET my_index/_search
    {
      "query": {
        "match_phrase": {
          "message": {
            "query": "lazy dog",
            "slop": 1
          }
        }
      }
    }
    
  4. query_string

bool query

여러 쿼리를 조합하기 위해서는 상위에 bool쿼리를 사용하고, 그 안에 다른 쿼리를 넣는 식으로 사용함. bool 쿼리는 다음의 4개의 인자를 갖고 있음.

  1. must: 쿼리가 참인 도큐먼트 검색
  2. msut_not: 쿼리가 거짓인 도큐먼트 검색
  3. should: 검색 결과 중 이 쿼리에 해당하는 도큐먼트의 점수를 높임.