도서 요약 / / 2022. 12. 22. 20:20

07. Full Text Queries

complete guide to elasticsearch를 정리한 자료입니다.
https://www.udemy.com/course/elasticsearch-complete-guide/

90. Full text 쿼리 소개

  • Term-level 쿼리는 정확한 값을 찾기 위해 사용된다.
  • match 쿼리는 형태소 분석을 한다.

데이터 준비

데이터 임포트

curl -H "Content-Type: application/x-ndjson" -XPOST "http://localhost:9200/recipe/_bulk?pretty" --data-binary "@recipes-bulk.json"

https://github.com/codingexplained/complete-guide-to-elasticsearch/blob/master/recipes-bulk.json

91. match 쿼리로 검색

GET recipe/_search
{
  "query": {
    "match": {
      "title": "Recipes with pasta or spaghetti"
    }
  }
}

기본 operator는 or이다. and로 변경하려면 아래와 같이 실행한다.

GET recipe/_search
{
  "query": {
    "match": {
      "title": {
        "query": "Recipes with pasta or spaghetti",
        "operator": "and"
      }
    }
  }
}

92. match phrase

문장을 검색하는 경우에 사용된다.

GET recipe/_search
{
  "query": {
    "match_phrase": {
      "title": "spaghetti puttanesca"
    }
  }
}

위의 문장에 들어가 있는 경우는 검색이 되지만.. 단어의 순서를 바꾸면 검색이 되지 않는다.

GET recipe/_search
{
  "query": {
    "match_phrase": {
      "title": "spaghetti puttanesca"
    }
  }
}

93. Searching multiple fields

GET recipe/_search
{
  "query": {
    "multi_match": {
      "query": "pasta",
      "fields": ["title", "description"]
    }
  }
}
반응형
  • 네이버 블로그 공유
  • 네이버 밴드 공유
  • 페이스북 공유
  • 카카오스토리 공유