简体   繁体   English

Apache Nifi JOLTTransformJSON处理器

[英]Apache Nifi JOLTTransformJSON Processor

I have a flow that is designed to pull tweets using Get twitter processor and I use JOLTTransformJSON processor to extract few attributes including the hashtags, my Jolt Specification is as follows 我有一个流程旨在使用Get twitter处理器提取推文,并且我使用JOLTTransformJSON处理器提取一些属性,包括井号,我的Jolt规范如下

[
  {
"operation": "shift",
"spec": {
  "entities": {
    "hashtags": {
      "*": "hashtags"
    }
  },
  "text": "content",
  "id": "id",
  "timestamp_ms": "timestamp",
  "retweet_count": "retweetcount",
  "url": "url"
}
  },
  {
"operation": "default",
"spec": {
  "type": "twitter"
}
  },
  {
"operation": "cardinality",
"spec": {
  "hashtags": "MANY"
}
  }
 ]

when the twitter output contains hashtags the JOLTTransformJSON processor output will give me those hashtags in the following way 当twitter输出包含主题标签时,JOLTTransformJSON处理器输出将通过以下方式为我提供这些主题标签

{
"hashtags": [{
    "text": "Venus",
    "indices": [16,
    22]
},
{
    "text": "Cancer",
    "indices": [69,
    76]
},
{
    "text": "ascendant",
    "indices": [86,
    96]
}],
"content": "acmc_clock_euro #Venus is now (16h58m01s UT) setting at 10°32'50.2'' #Cancer opposite #ascendant at Helsinki, SF",
"id": 895332436975931393,
"timestamp": "1502298862104",
"retweetcount": 0,
"url": "https://twitter.com/pe602/status/895332436975931393",
"type": "twitter"
}

but if the hashtags array is empty as follows 但是,如果hashtags数组为空,则如下所示

"entities": {
    "hashtags": []

the output will not contain hashtags, how can I make the output have hashtags element but with an empty array if the twitter op doesn't have hashtags using JOLT processor. 输出将不包含主题标签,如果twitter op没有使用JOLT处理器的主题标签,如何使输出具有主题标签元素但具有空数组。

Try this in your 2nd "default" operation. 在第二个“默认”操作中尝试此操作。

{
  "operation": "default",
  "spec": {
    "hastags": [],
    "type": "twitter"
  }
}

Resolved this by using "modify-default-beta" operation as follows 通过使用“ modify-default-beta”操作来解决此问题,如下所示

{ "operation": "modify-default-beta", "spec": { "hashtags": [] } } {“ operation”:“ modify-default-beta”,“ spec”:{“ hashtags”:[]}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM