在json

时间:2019-05-23 07:20:10

标签: jolt

我不熟悉JOLT转换。我正在尝试创建一个转换规范。 我在对象中有一个类别列表,只需要变换一些细节即可。

我的示例代码和规格如下所示。

在“ 0 / SYS_CATALOG_DESCRIPTION”列表中,我需要将其转换为基于lang的字符串,即en_US,我需要获取AA产品 最终结果将是“ _description”:“ AA产品”

“ subCategories”应该给我以下结果:

"subCategories": [
{
"_id": "ce_155584",
"_parentIds": ["ce_128375"],
"_description": "Filters" //based on lang = en_US
}
]

示例JSON:

{
  "total": 16,
  "max_score": 2.2809339,
  "hits": [
    {
      "_index": "bosch-dms-frontend-service_en_us_1558584002",
      "_type": "categories",
      "_id": "ce_128375",
      "_score": 2.2809339,
      "_source": {
        "_parentIds": [
          "1234"
        ],
        "0/SYS_CATALOG_DESCRIPTION": [
          {
            "lang": "de_DE",
            "value": "AA Produkte"
          },
          {
            "lang": "en_US",
            "value": "AA Products"
          }
        ],
        "subCategories": [
          {
            "_index": "bosch-dms-frontend-service_en_us_1558584002",
            "_type": "categories",
            "_id": "ce_155584",
            "_score": 2.2809339,
            "_source": {
              "_parentIds": [
                "ce_128375"
              ],
              "0/SYS_CATALOG_DESCRIPTION": [
                {
                  "lang": "en_US",
                  "value": "Filters"
                },
                {
                  "lang": "zh_CN",
                  "value": "AA Filters (CN)"
                }
              ],
              "0/SYS_SYSTEMNAME": "AA_Filters"
            }
          }
        ]
      }
    }
  ]
}

SPEC:

[

  {
    "operation": "shift", // shift operation
    "spec": {
      "hits": {
        "*": { 
          "_id": "_id",
          "_source": {
            "_parentIds": "_parentIds",
            "0/SYS_CATALOG_DESCRIPTION": "_description",
          }
        }
      }
    }
    }

]

最终结果将是

{
  "_id" : "ce_128375",
  "_parentIds" : [ "1234" ],
  "_description" : "AA Products (BR)",
   "subCategories": [ 
            {
            "_id": "ce_155584",
            "_score": 2.2809339,
            "_parentIds": ["ce_128375"],
            "_description" : "Filters"
            }

   ]
}

我尝试了几种方法,但没有达到结果。 谢谢。

1 个答案:

答案 0 :(得分:0)

检查此规格是否满足您的要求:

[

  {
    "operation": "shift", // shift operation
    "spec": {
      "hits": {
        "*": {
          "_id": ["&",
                          "subCategories.[]._parentIds[]"],
          "_source": {
            "_parentIds": "&",
            "0/SYS_CATALOG_DESCRIPTION": {
              "*": {
                "lang": {
                  "en_US": {
                    "@(2,value)": "_description"
                  }
                }
              }
            },
            "subCategories": {
              "*": {
                "_id": "subCategories.[&1].&",
                "_score": "subCategories.[&1].&",
                "_source": {
                  "0/SYS_CATALOG_DESCRIPTION": {
                    "*": {
                      "lang": {
                        "en_US": {
                          "@(2,value)": "subCategories.[&6]._description"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    }

]