elasticsearch 在Painless中,从数组中删除值

i34xakig  于 2023-02-18  发布在  ElasticSearch
关注(0)|答案(1)|浏览(118)

在Splunk SPL中,从数组中删除值很容易......
| eval帐户名称= mvindex(帐户名称,0)
Windows安全日志将帐户名引用为数组(0)中的计算机名
数组(1)包含实际执行的帐户名。
我需要做与Painless中的mvindex函数相同的事情。
我找到了很多搜索结果,但没有找到任何有用的。这里一定有一个简单的方法来删除数组值。

xcitsw88

xcitsw881#

你有没有找下面的东西?

POST sample_index/_doc
{
  "Account_Name": [
    "machine-name",
    "account-name"
  ]
}

POST sample_index/_update_by_query
{
  "query": {
    "match_all": {}
  },
  "script": {
    "source": "ctx._source['Account_Name'].remove(0)",
    "lang": "painless"
  }
}

GET sample_index/_search

检索后结果:

{
  "took": 892,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "sample_index",
        "_id": "t3RIY4YBnUNkT6fHnBrI",
        "_score": 1,
        "_source": {
          "Account_Name": [
            "account-name"
          ]
        }
      }
    ]
  }
}

相关问题