Type to search.

Delete sensitive data

Stack

The Elastic Stack includes Elastic's core products such as Elasticsearch, Kibana, Logstash, and Beats.

Availability

  • Generally available

    This functionality is generally available and ready for production usage.

Unless stated otherwise on the page, this functionality is available when your Elastic Stack is deployed on Elastic Cloud Hosted, Elastic Cloud Enterprise, Elastic Cloud on Kubernetes, and self-managed environments.

This documentation corresponds to the latest patch available for each minor version. If you're not using the latest patch, check the release notes for changes.

If you accidentally ingest sensitive data, follow these steps to remove or redact the offending data:

  1. Stop collecting the sensitive data. Use the remedy column of the sensitive fields table to determine how to stop collecting the offending data.

  2. Delete or redact the ingested data. With data collection fixed, you can now delete or redact the offending data:

To redact sensitive data in a specific field, use the update by query API.

For example, the following query removes the client.ip address from APM documents in the logs-apm.error-default data stream:

JSON
POST /logs-apm.error-default/_update_by_query
{
  "query": {
    "exists": {
      "field": "client.ip"
    }
  },
  "script": {
    "source": "ctx._source.client.ip = params.redacted",
    "params": {
      "redacted": "[redacted]"
    }
  }
}

Or, perhaps you only want to redact IP addresses from European users:

JSON
POST /logs-apm.error-default/_update_by_query
{
  "query": {
    "term": {
      "client.geo.continent_name": {
        "value": "Europe"
      }
    }
  },
  "script": {
    "source": "ctx._source.client.ip = params.redacted",
    "params": {
      "redacted": "[redacted]"
    }
  }
}

See update by query API for more information and examples.

Warning

This will permanently delete your data. You should test your queries with the search API prior to deleting data.

To delete an Elasticsearch document, you can use the delete by query API.

For example, to delete all documents in the apm-traces-* data stream with a user.email value, run the following query:

JSON
POST /apm-traces-*/_delete_by_query
{
  "query": {
    "exists": {
      "field": "user.email"
    }
  }
}

See delete by query API for more information and examples.