用于Elasticsearch的Kibana中的Python脚本

2024-10-01 15:28:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图从Kibana索引管理在Elasticsearch中创建脚本字段。但这种语言太难应付了:无痛。我对Python很熟悉。是否可以在Elasticsearch 6.6及更高版本中使用Python语言编写字段脚本

我正在尝试设置一个新列:Status,如果完成日期小于当前日期,则其值将为非活动状态

映射如下:

{
  "mapping": {
    "atlassian": {
      "properties": {
        "Fields": {
          "properties": {
            "Sprints": {
              "properties": {
                "completeDate": {
                  "type": "date"
                },
                "endDate": {
                  "type": "date"
                },
                "name": {
                  "type": "text",
                  "fields": {
                    "keyword": {
                      "type": "keyword",
                      "ignore_above": 256
                    }
                  }
                },
                "startDate": {
                  "type": "date"
                }
              }
            }

...

文档在表视图中如下所示:

^{2}$

上面的字段被解析为包含许多sprint信息的字典数组。但在表视图中,它的视图就像一个嵌套的字典。在

在JSON视图中,文档如下所示:

{
  "_index": "jira_addon_index",
  "_type": "atlassian",
  "_id": "452",
  "_version": 2,
  "_score": 0,
  "_source": {
    "Fields": {
      "summary": "[XXXX - JIRA Exception Report] Project does not exist for the items present in Stories without Sprints Panel",
      "issuetype": {
        "name": "Bug"
      },
      "Sprints": [
        {
          "endDate": "2019-01-29T00:30:00.000Z",
          "name": "XXX - sprint 21",
          "startDate": "2019-01-09T15:51:49.104Z",
          "completeDate": "2019-01-28T22:50:19.411Z"
        }
      ],
      "components": null,
      "customfield_12094": null,
      "created": "2019-01-07T19:32:55.826+0800",

...

我试图从开发工具和索引管理中的脚本字段实用程序创建一个新字段

开发工具

POST jira_addon_index/_update_by_query
{
  "query": {
      "range": {
      "Fields.Sprints.endDate": {
        "lt": "now/d"
      }
    }
  },
  "script": {
    "lang": "painless",
    "source": """
      ctx._source.Fields.Sprints.add(params.StatusTwo)
    """,
    "params": {
      "StatusOne":"Active",
      "StatusTwo":"Closed"
    }
  }
}


上面的代码在父JSON中创建了一个新字段,而我想添加新字段“Status:inthedictionary inside[Fields][Sprints]

索引管理工具

long timestampLog = doc['Fields.Sprints.completeDate'].value.getMillis();

long timestampNow = new Date().getTime();

if (timestampLog < timestampNow ) { 
return "INACTIVE"
} else {
return "ACTIVE"
}

如何在sprints字典中创建新列。此外,我可以使用Python语言编写脚本吗?在

除了官方文档之外,有没有其他的在线教程来理解查询?在


Tags: name文档脚本视图语言sourcefieldsdate

热门问题