JOLT规范将json转换为数组

时间:2020-07-24 10:49:27

标签: json jolt

我正在尝试编写规范以使用jolt转换进行以下转换。结果,我想得到以下内容:

输入json:

"hits": [
                {
                  "_index": "partners",
                  "_type": "_doc",
                  "partner_id": "first",
                  "_nested": {
                    "field": "list_point_of_sales",
                    "offset": 0
                  },
                  "_score": 1.0,
                  "_source": {
                    "point_of_sale_id": 2,
                    "location": [
                      65,
                      65
                    ],
                    "point_of_sale_name": "some_point_of_sales_2",
                    "index": "222603",
                    "country": "Belarus",
                    "region": "Minsk",
                    "departments": 3,
                    "city": "Minsk",
                    "city_type": "some_type",
                    "street_type": "some_type",
                    "street": "Some",
                    "house": "",
                    "building": "23B",
                    "flat_type": "some_type",
                    "flat": 23,
                    "unstruct_address": "some address"
                  }
                },
                {
                  "_index": "partners",
                  "_type": "_doc",
                  "partner_id": "first",
                  "_nested": {
                    "field": "list_point_of_sales",
                    "offset": 1
                  },
                  "_score": 1.0,
                  "_source": {
                    "point_of_sale_id": 2,
                    "location": [
                      65,
                      65
                    ],
                    "point_of_sale_name": "some_point_of_sales_2",
                    "index": "222603",
                    "country": "Belarus",
                    "region": "Minsk",
                    "departments": 3,
                    "city": "Minsk",
                    "city_type": "some_type",
                    "street_type": "some_type",
                    "street": "Some",
                    "house": "",
                    "building": "23B",
                    "flat_type": "some_type",
                    "flat": 23,
                    "unstruct_address": "some address"
                  }
                },
                {
                  "_index": "partners",
                  "_type": "_doc",
                  "partner_id": "second",
                  "_nested": {
                    "field": "list_point_of_sales",
                    "offset": 1
                  },
                  "_score": 1.0,
                  "_source": {
                    "point_of_sale_id": 2,
                    "location": [
                      60,
                      60
                    ],
                    "point_of_sale_name": "some_point_of_sales_2",
                    "index": "222603",
                    "country": "Belarus",
                    "region": "Minsk",
                    "departments": 3,
                    "city": "Minsk",
                    "city_type": "some_type",
                    "street_type": "some_type",
                    "street": "Some",
                    "house": "",
                    "building": "23B",
                    "flat_type": "some_type",
                    "flat": 23,
                    "unstruct_address": "some address"
                  }
                }
              ]

应用JOLT后的结果:

{
    "partners":[
        {
            "partner_id": "first",
            "info(_source in the incoming json)":[
                {
                    "point_of_sale_id": 2,
                    "location": [
                      65,
                      65
                    ],
                    "point_of_sale_name": "some_point_of_sales_2",
                    "index": "222603",
                    "country": "Belarus",
                    "region": "Minsk",
                    "departments": 3,
                    "city": "Minsk",
                    "city_type": "some_type",
                    "street_type": "some_type",
                    "street": "Some",
                    "house": "",
                    "building": "23B",
                    "flat_type": "some_type",
                    "flat": 23,
                    "unstruct_address": "some address"
                  },
                  {
                    "point_of_sale_id": 2,
                    "location": [
                      65,
                      65
                    ],
                    "point_of_sale_name": "some_point_of_sales_2",
                    "index": "222603",
                    "country": "Belarus",
                    "region": "Minsk",
                    "departments": 3,
                    "city": "Minsk",
                    "city_type": "some_type",
                    "street_type": "some_type",
                    "street": "Some",
                    "house": "",
                    "building": "23B",
                    "flat_type": "some_type",
                    "flat": 23,
                    "unstruct_address": "some address"
                  }
            ]
        },
        {
            "partner_id": "second",
            "info(_source in the incoming json)":[
                {
                    "point_of_sale_id": 2,
                    "location": [
                      60,
                      60
                    ],
                    "point_of_sale_name": "some_point_of_sales_2",
                    "index": "222603",
                    "country": "Belarus",
                    "region": "Minsk",
                    "departments": 3,
                    "city": "Minsk",
                    "city_type": "some_type",
                    "street_type": "some_type",
                    "street": "Some",
                    "house": "",
                    "building": "23B",
                    "flat_type": "some_type",
                    "flat": 23,
                    "unstruct_address": "some address"
                  }
            ]
        }
    ]
}

这个想法是使用 partner_id 对文档进行分组,并制作一个数组 _source 具有相同 partner_id 的文档。给定结构的文档很多。有人可以帮助我了解JOLT规范吗?

0 个答案:

没有答案