How can I get NiFi to take a multi value that is in a database single column to populate Solr index which is an array?

huangapple go评论65阅读模式
英文:

How can I get NiFi to take a multi value that is in a database single column to populate Solr index which is an array?

问题

The Jolt Transformer processor can be used to achieve the desired output. Here's the translated part of your text:

"我正在写这个问题已经好几个小时了...

我在考虑可能需要使用Jolt Transformer处理器来实现这个。

示例:数据库列名为“A”的单个条目包含在varchar字段中的值。
“Alabama”,“Ohio”,“Texas”,“Missouri”

再次强调,上面的值是列“A”的一个条目。

这些数据需要填充Solr索引字段“STATES”。

目前,我有一个ExecuteSQLRecord从数据库中获取数据,使用JsonRecordSetWriter作为Record Writer。此处理器连接到我的PutSolrContentStream。

问题似乎是始终将列A中的数据用引号“”括起来,并且所有字段都已经转义了。

如何覆盖此行为以手动设置要使用的引号?

根据当前的工作方式,从查询调用发送到Solr的数据如下所示。

[
 {
  “STATES”: “\“Alabama\“,“\“Ohio\“,“\“Texas\“,“\“Missouri\“”
 }
]

或者尝试看看我可以得到什么输出的其他尝试如下:

“STATES”: “Alabama,Ohio,Texas,Missouri”
“STATES”: “‘Alabama’,‘Ohio’,‘Texas’,‘Missouri’”

我需要的是输出如下

[
 {
  “STATES”: [“Alabama”,“Ohio”,“Texas”,“Missouri”]
 }
]

Jolt Transformer是否是解决方案

我看到的Jolt示例都很简单,例如,特定值会更改,比如STATES变成“MY_STATES”。但是目前我不知道如何将

“STATES”: “Alabama,Ohio,Texas,Missouri”

转换为

“STATES”: [“Alabama”,“Ohio”,“Texas”,“Missouri”]

"

英文:

Been writing this question for hours...

I'm thinking that I may need to use the Jolt Transformer processor for this.

Example A single entry in a database column called "A" contains this value in a varchar field.
"Alabama","Ohio","Texas","Missouri"

Again the above value is 1 entry in the column "A".

The data needs to populate a Solr Index field called "STATES".

Currently I have an ExecuteSQLRecord pulling the database data with a JsonRecordSetWriter for the Record Writer. This processor connects to my PutSolrContentStream.

The problem seems to be that the data always gets wrapped from column A in quotes " and all" already in the field get escaped.

How can I override this in order to manually set the quotes to be used?

With the way things are working right now the data sent to Solr looks like the following from the query call.

[
 {
  "STATES": "\"Alabama\",\"Ohio\",\"Texas\",\"Missouri\""
 }
]

or other attempts to see what I can get it to output are like

"STATES": "Alabama,Ohio,Texas,Missouri"
"STATES": "'Alabama','Ohio','Texas','Missouri'"

What I need is for the output to be
call.

[
 {
  "STATES": ["Alabama","Ohio","Texas","Missouri"]
 }
]

Would the Jolt Transformer be the solution

Examples I've seen with the Jolt have been simple where a specific value gets changed such as STATES becomes "MY_STATES". But I'm at a loss at the moment for how to convert the

"STATES": "Alabama,Ohio,Texas,Missouri"

to

"STATES": ["Alabama","Ohio","Texas","Missouri"]

答案1

得分: 1

你只需在类似modify-overwrite-beta变换中使用split函数,示例代码如下:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "STATES": "=split(',',@(1,&))"  // &代表当前级别属性
    }
  }
]

对于输入:

{
  "STATES": "Alabama,Ohio,Texas,Missouri"
}

您可以通过将SpecificationInput放入它们的框中,然后切换到ADVANCED选项卡进行测试,如下图所示:

How can I get NiFi to take a multi value that is in a database single column to populate Solr index which is an array?

英文:

You just can use a split function within a modify-overwrite-beta transformation such as

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "STATES": "=split(',',@(1,&))"  // & stands for the current level attribute
    }
  }
]

for the input

{
  "STATES": "Alabama,Ohio,Texas,Missouri"
}

You can test by putting the Specification and Input into their boxes after toggling the ADVANCED tab illustrated in the following image :

How can I get NiFi to take a multi value that is in a database single column to populate Solr index which is an array?

huangapple
  • 本文由 发表于 2023年6月8日 22:16:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76432789.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定