how to delete doc of datastream in elasticsearch, 엘라스틱서치 데이터스트림 도규먼트 삭제하기

To delete a document in an Elasticsearch data stream, you can use the _delete API. However, data streams work a bit differently from regular indices in Elasticsearch. A document in a data stream is generally stored across multiple backing indices, so you must first find the specific backing index and document ID.

Here are the steps to delete a document from an Elasticsearch data stream:

Steps to delete a document from a data stream:

  1. Find the document's index:

    • Search the data stream to find the document and note the _index and _id values.

    Use a query like this:

    GET /<data-stream-name>/_search
    {
      "query": {
        "match": {
          "<field>": "<value>"
        }
      }
    }
    

    Replace <data-stream-name>, <field>, and <value> with appropriate values. From the result, note the _index (which will be a backing index) and the document's _id.

  2. Delete the document:

    • Once you have the document’s _index and _id, you can delete it using the following command:
    DELETE /<index-name>/_doc/<document-id>
    

    Replace <index-name> with the specific backing index you got from the previous search result, and replace <document-id> with the document's ID.

Example:

  1. Search for the document:

    GET /logs-metrics/_search
    {
      "query": {
        "match": {
          "user": "john_doe"
        }
      }
    }
    

    The response might return something like:

    {
      "hits": {
        "hits": [
          {
            "_index": ".ds-logs-metrics-2023.06.01-000001",
            "_id": "A1B2C3D4E5F6",
            "_source": {
              "user": "john_doe",
              "action": "login"
            }
          }
        ]
      }
    }
    
  2. Delete the document: With _index as .ds-logs-metrics-2023.06.01-000001 and _id as A1B2C3D4E5F6, delete the document like this:

    DELETE /.ds-logs-metrics-2023.06.01-000001/_doc/A1B2C3D4E5F6
    

Important Notes:

  • You cannot directly delete a document from a data stream using its alias (i.e., the data stream's name). You must reference the specific backing index.
  • Elasticsearch does not automatically delete empty backing indices. You may need to manage these indices manually if required.

Let me know if you need further clarification!

댓글

이 블로그의 인기 게시물

To switch to a specific tag in a Git repository

How to checkout branch of remote git, 깃 리모트 브랜치 체크아웃

Using the MinIO API via curl

To download a file from MinIO using Spring Boot, 스프링부트 Minio 사용하기

리눅스의 부팅과정 (프로세스, 서비스 관리)

Chromium 개발 환경 세팅, 크로미움 개발 준비하기

Joining an additional control plane node to an existing Kubernetes cluster

urllib3 with proxy settings

CDPEvents in puppeteer

Avro + Grpc in python