Azure Search索引管道中如何拼接两个字符串字段?
Azure Search字符串字段拼接实现方案
可以实现两个字符串字段的拼接,根据你的使用场景(是最终存入索引时拼接,还是技能集处理流程中需要用到拼接结果),有两种常用方案:
方案1:索引器字段映射直接拼接(适合最终索引字段)
如果只是需要将拼接后的字段存入搜索索引,不需要在技能集的中间步骤使用该字段,可以直接在索引器的fieldMappings中使用concat映射函数:
"fieldMappings": [ { "sourceFieldName": "/document/field1", "targetFieldName": "combinedField", "mappingFunction": { "name": "concat", "parameters": { "separator": " ", // 自定义分隔符,比如空格、逗号等 "items": ["/document/field1", "/document/field2"] } } } ]
方案2:自定义Web API技能(适合技能集流程中拼接)
如果需要在技能集的处理流程中生成拼接后的字段(供后续技能使用),可以通过自定义Web API技能实现,比如用Azure Functions搭建一个简单的拼接服务:
技能集配置示例
{ "@odata.type": "#Microsoft.Skills.Custom.WebApiSkill", "name": "string-concat-skill", "context": "/document", "uri": "https://你的函数应用名.azurewebsites.net/api/concat-strings?code=你的函数密钥", "httpMethod": "POST", "inputs": [ { "name": "string1", "source": "/document/field1" }, { "name": "string2", "source": "/document/field2" } ], "outputs": [ { "name": "combinedString", "targetName": "combinedField" } ] }
Azure Functions拼接函数示例(C#)
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Extensions.Http; using Newtonsoft.Json; using System.IO; using System.Threading.Tasks; public static class ConcatStrings { [FunctionName("concat-strings")] public static async Task<IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req) { string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); dynamic data = JsonConvert.DeserializeObject(requestBody); string string1 = data.values[0].data.string1; string string2 = data.values[0].data.string2; // 自定义拼接逻辑,可修改分隔符或格式 string combined = $"{string1} {string2}"; return new OkObjectResult(new { values = new[] { new { recordId = data.values[0].recordId, data = new { combinedString = combined }, errors = new object[] {}, warnings = new object[] {} } } }); } }
补充说明:你提到的Text Merger技能确实是用于合并数组类型的多值字段,Shaper技能主要用于构造嵌套对象或整理字段结构,这两个都不支持直接拼接单个字符串字段,上述两种方案可以覆盖你的需求。
内容的提问来源于stack exchange,提问作者Kamil
相关产品推荐
相关产品推荐

