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!

댓글

이 블로그의 인기 게시물

Install and run an FTP server using Docker

Using the MinIO API via curl

PYTHONPATH, Python 모듈 환경설정

Elasticsearch Ingest API

오늘의 문장2

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

Fundamentals of English Grammar #1

To switch to a specific tag in a Git repository

You can use Sublime Text from the command line by utilizing the subl command

티베트-버마어파 와 한어파(중국어파)의 어순 비교