Elasticsearch Query String Query에 대해서 알아보기

query string쿼리는 연산자를 중심으로 텍스트를 분할하여 쿼리를 분석합니다.

example

$ curl "localhost:9200/sales-records/_search?pretty" -H "Content-Type:application/json" -d '
{
  "query": {
    "query_string": {
      "default_field": "country",
      "query": "(south africa) OR (south korea)"
    }
  }
}'

“south africa”와 “south korea”로 나뉘며 각 부분은 분석기에 의해서 독립적으로 분석됩니다.

공백은 연산자로 간주되지 않아 공백 상태 그대로 분석기에 전달됩니다. 만약 각 단어를 개별적으로 쿼리하길 원한다면 단어에 연산자를 추가해야합니다.

예를 들어, “south africa”을 검색하시려면 (south AND africa)으로 입력하시면 되며 “(south africa) OR (south korea)”는 “(south AND africa) OR (south AND korea)” 로 하시면 됩니다.

여러 필드를 통해 검색을 하고 싶다면 type 속성을 사용하시면 됩니다. 기본값은 “best_fields”입니다. 그리고 fields를 검색할 필드명을 명시할 수 있습니다.

example

$ curl "localhost:9200/sales-records/_search?pretty" -H "Content-Type:application/json" -d '
{
  "query": {
    "query_string": {
      "query": "south AND asia",
      "fields": ["country", "message"]
    }
  }
}'

참고사이트

  1. https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html



Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • 무료 프록시, 크롤러 실패의 지름길, 유료 프록시가 필수인 7가지 기술적 이유
  • 파이썬 웹 크롤링 완벽 가이드 - 현업 데이터 엔지니어의 실전 노하우
  • AI 글쓰기 품질을 높이는 프롬프트 엔지니어링 8단계 (실전 템플릿 포함)
  • AI 시대, 경쟁력 있는 사람이 되는 법, 효과적인 프롬프트 작성 가이드
  • AI를 믿을 수 있을까? 인간이 할루시네이션을 구분할줄 알아야 한다.