Kibana中用于Elastisearch的Python脚本

时间:2019-04-01 05:21:19

标签: python elasticsearch kibana elastic-stack

我正在尝试从Kibana索引管理在Elastisearch中创建脚本化字段。但是这种语言很难应付:无痛。我熟悉python。我可以在elastisearch 6.6及更高版本中使用python语言编写字段脚本

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

下面提到了映射:

{
  "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"
                }
              }
            }

...

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

?  Fields.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"
}

上面的Field被解析为包含许多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中创建了一个新字段,而我想在[Fields] [Sprints]内的字典中添加新字段“ Status:”

索引管理实用程序

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

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

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

如何在sprints词典中创建新列。我还可以使用PYTHON语言编写脚本吗?

除了官方文档以外,还有其他在线教程可以帮助您理解查询吗?

0 个答案:

没有答案