将默认值添加到 JOLT 中的数组
adding default values to an array in JOLT
我需要将请求转换为 SOLR 微服务。在许多其他属性中,我有一个要从 SOLR 返回的字段列表。我确实需要在那里添加几个默认字段。
IE。使用以下输入:
{
"jsonToTransform": {
"authorizedCountries": [],
"searchOptions": {
"maxRecords": "10",
"matchScore": "true",
"matchIndicators": "true",
},
"searchAttrList": {
"distanceUnit": "M",
"phoneNumber": "369283729375",
"distance": "8.5",
"latitude": 44.71663,
"longitude": 10.23196
},
"responseAttrList": ["distance","locationAddressLongitude","locationAddressLatitude","name","streetAddress","city","state","postalCode","countryCode","primaryCategoryCode","categoryCodeDesc","url"]
}
}
我需要得到这个输出:
{
"searchOptions" : {
"maxRecords" : "10",
"matchScore" : "true",
"matchIndicators" : "true"
},
"searchAttrList" : {
"distance" : "13.68",
"point" : "44.71663,10.23196"
},
"solrOptions" : {
"responseElementsList" : ["distance","locationAddressLongitude","locationAddressLatitude","name","streetAddress","city","state","postalCode","countryCode","primaryCategoryCode","categoryCodeDesc","url","compatibilityIndex","privacyIndicator"],
"countryCodeList" : [ ],
"pnm_boost" : "1.0",
"anm_boost" : "1.0",
...
}
}
除了在 responseElementsList 末尾添加这两个字段外,我几乎一切正常。我有这个规格:
{
"operation": "default",
"spec": {
"*": {
"solrOptions": {
"anm_boost": "1.0",
"pnm_boost": "1.0",
"responseElementsList": ["compatibilityIndex","privacyIndicator"]
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"solr*": {
"*": "&1.&",
"@(1,responseAttrList)": "&1.responseElementsList",
"@(1,authorizedCountries)": "&1.countryCodeList",
...
},
"search*": "&",
"searchOptions": {
"*": "&1.&",
...
}
}
}
}
但作为回应,我得到了:
"responseElementsList" : ["distance","locationAddressLongitude","locationAddressLatitude","name","streetAddress","city","state","postalCode","countryCode","primaryCategoryCode","categoryCodeDesc","url",["compatibilityIndex","privacyIndicator"]],
我确实尝试了其他一些变体,但它们也没有产生所需的输出。
请告诉我我做错了什么。
您可以将 responseElementsList
对象添加到 shift 转换中,其中遍历数组的索引,但不是整个数组如
[
....,
{
"operation": "shift",
"spec": {
"*": {
"solr*": {
"*": "&1.&",
"@(1,responseAttrList)": "&1.responseElementsList",
"responseElementsList": {
"*": {
"@": "&3.&2"
}
},
"@(1,authorizedCountries)": "&1.countryCodeList",
...
},
"search*": "&",
"searchOptions": {
"*": "&1.&",
...
}
}
}
}
...
]
其中&3表示键名"solrOptions"
以便在common对象下进行组合,而&2表示"responseElementsList"
键名.
我需要将请求转换为 SOLR 微服务。在许多其他属性中,我有一个要从 SOLR 返回的字段列表。我确实需要在那里添加几个默认字段。 IE。使用以下输入:
{
"jsonToTransform": {
"authorizedCountries": [],
"searchOptions": {
"maxRecords": "10",
"matchScore": "true",
"matchIndicators": "true",
},
"searchAttrList": {
"distanceUnit": "M",
"phoneNumber": "369283729375",
"distance": "8.5",
"latitude": 44.71663,
"longitude": 10.23196
},
"responseAttrList": ["distance","locationAddressLongitude","locationAddressLatitude","name","streetAddress","city","state","postalCode","countryCode","primaryCategoryCode","categoryCodeDesc","url"]
}
}
我需要得到这个输出:
{
"searchOptions" : {
"maxRecords" : "10",
"matchScore" : "true",
"matchIndicators" : "true"
},
"searchAttrList" : {
"distance" : "13.68",
"point" : "44.71663,10.23196"
},
"solrOptions" : {
"responseElementsList" : ["distance","locationAddressLongitude","locationAddressLatitude","name","streetAddress","city","state","postalCode","countryCode","primaryCategoryCode","categoryCodeDesc","url","compatibilityIndex","privacyIndicator"],
"countryCodeList" : [ ],
"pnm_boost" : "1.0",
"anm_boost" : "1.0",
...
}
}
除了在 responseElementsList 末尾添加这两个字段外,我几乎一切正常。我有这个规格:
{
"operation": "default",
"spec": {
"*": {
"solrOptions": {
"anm_boost": "1.0",
"pnm_boost": "1.0",
"responseElementsList": ["compatibilityIndex","privacyIndicator"]
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"solr*": {
"*": "&1.&",
"@(1,responseAttrList)": "&1.responseElementsList",
"@(1,authorizedCountries)": "&1.countryCodeList",
...
},
"search*": "&",
"searchOptions": {
"*": "&1.&",
...
}
}
}
}
但作为回应,我得到了:
"responseElementsList" : ["distance","locationAddressLongitude","locationAddressLatitude","name","streetAddress","city","state","postalCode","countryCode","primaryCategoryCode","categoryCodeDesc","url",["compatibilityIndex","privacyIndicator"]],
我确实尝试了其他一些变体,但它们也没有产生所需的输出。 请告诉我我做错了什么。
您可以将 responseElementsList
对象添加到 shift 转换中,其中遍历数组的索引,但不是整个数组如
[
....,
{
"operation": "shift",
"spec": {
"*": {
"solr*": {
"*": "&1.&",
"@(1,responseAttrList)": "&1.responseElementsList",
"responseElementsList": {
"*": {
"@": "&3.&2"
}
},
"@(1,authorizedCountries)": "&1.countryCodeList",
...
},
"search*": "&",
"searchOptions": {
"*": "&1.&",
...
}
}
}
}
...
]
其中&3表示键名"solrOptions"
以便在common对象下进行组合,而&2表示"responseElementsList"
键名.