簡體   English   中英

Apache Nifi JOLTTransformJSON處理器

[英]Apache Nifi JOLTTransformJSON Processor

我有一個流程旨在使用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"
}
  }
 ]

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

但是,如果hashtags數組為空,則如下所示

"entities": {
    "hashtags": []

輸出將不包含主題標簽,如果twitter op沒有使用JOLT處理器的主題標簽,如何使輸出具有主題標簽元素但具有空數組。

在第二個“默認”操作中嘗試此操作。

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

通過使用“ modify-default-beta”操作來解決此問題,如下所示

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM