Elasticsearch search query for matching keyword

To develop an Elasticsearch query for keyword type matching, you can use the "match" query with the "keyword" type field. The "keyword" type fields are not analyzed, which means they are treated as exact values and not tokenized.

Here's an example of how to use the "match" query for keyword type matching:

Suppose you have an index called "my_index" with documents containing a field called "title" of "keyword" type. The goal is to search for documents that have a specific "title" value.

POST /my_index/_search
{
  "query": {
    "match": {
      "title": "Your Keyword Here"
    }
  }
}

In this example, replace "Your Keyword Here" with the actual keyword you want to match. Elasticsearch will find all documents in "my_index" that have an exact match for the "title" field with the specified keyword.

Please note that by default, the "match" query uses the "OR" operator, meaning it will match documents containing any of the provided terms. If you want to perform an exact match on the entire field value, you can use the "operator" parameter:

POST /my_index/_search
{
  "query": {
    "match": {
      "title": {
        "query": "Your Keyword Here",
        "operator": "and"
      }
    }
  }
}

With the "operator" set to "and," Elasticsearch will only return documents that have an exact match with the entire "title" field value, rather than matching any individual term in the "title" field.

Remember to adjust the index name ("my_index") and field name ("title") in the queries based on your actual data model.

댓글

이 블로그의 인기 게시물

Tomcat(톰캣) SSL 포트 설정

How to split a list into chunks of 100 items in JavaScript, 자바스크립트 리스트 쪼개기

How to catch exceptions on Future in Java, 자바 Future 에러 잡기

Using the MinIO API via curl

운영체제를 개발 방법

dagrun_timeout of Airflow

What are 5 creative things I could do with my kids' art, 아이와 함께하는 창의적 놀이

In HBase, the "memory to disk" flush operation

[OS_Linux_Ubuntu] telnet & ssh 설치와 설정 (installation / configuration)

[Ubuntu] *.deb 파일 설치 방법