运行 ISM 策略 Opensearch 查询。

huangapple go评论58阅读模式
英文:

Run ISM Policy Opensearch with query

问题

我想创建一个策略,根据索引中的"expired_time"字段来删除日志。
示例:

索引:my-log

数据:

{
"logText": "消息文本",
"expired_time": "2024-02-01T14:33:33.290+00:00"
}

根据我的研究,只能通过模式索引来删除它。所以有什么方法可以处理它吗?

使用:opensearch 1.0.1

英文:

i want to create policy to delete logs base on "expired_time" field in index.
Example:

index: my-log

data:

{
"logText":"message text",
"expired_time": "2024-02-01T14:33:33.290+00:00"
}

As i research, it can only be deleted by pattern index. So anyway i can process it?

Using: opensearch 1.0.1

答案1

得分: 1

There was a _ttl field to delete documents after the retention period. But the feature is removed.

> The _ttl mappings have been removed. As a replacement for _ttl
> mappings, we recommend using ILM (ISM in Opensearch) to create time-based indices.

What you can do?

You can use _delete_by_query API to remove documents older than X times. It can make sense to trigger this query per hour.

An example:

POST index_name/_delete_by_query?conflicts=proceed
{
"query": {
"range": {
"expired_time": {
"lt": "now"
}
}
}
}

英文:

There was a _ttl field to delete documents after the retention period. But the feature is removed.

> The _ttl mappings have been removed. As a replacement for _ttl
> mappings, we recommend using ILM (ISM in Opensearch) to create time-based indices.

What you can do?

You can use _delete_by_query API to remove documents older than X times. It can make sense to trigger this query per hour.

An example:

POST index_name/_delete_by_query?conflicts=proceed
{
  "query": {
    "range": {
      "expired_time": {
        "lt": "now"
      }
    }
  }
}

huangapple
  • 本文由 发表于 2023年5月18日 11:18:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76277509.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定