You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure OpenAI On Your Data对接ElasticSearch:数组字段映射异常求助

解决Azure OpenAI On Your Data无法读取ElasticSearch数组类型内容字段的问题

问题原因

Azure OpenAI On Your Data的ElasticSearch数据源字段映射逻辑默认不支持直接读取数组类型字段,因此contentText数组无法被正确识别并纳入响应生成的上下文。

解决方案

方案1:在ElasticSearch中创建运行时字段拼接数组内容

在ElasticSearch索引中添加一个运行时字段,将contentText数组的所有元素拼接为单个字符串,之后在Azure配置中引用该字段。

执行以下ElasticSearch命令创建运行时字段:

PUT /myindex/_mapping
{
  "runtime": {
    "contentText_combined": {
      "type": "text",
      "script": {
        "source": "emit(doc['contentText'].values.join(' '))"
      }
    }
  }
}

修改Azure OpenAI配置中的fields_mapping:

"fields_mapping": {
  "title_field": "titleText",
  "content_fields": ["contentText_combined"]
}

方案2:在查询配置中使用脚本字段动态生成拼接内容

直接在Azure OpenAI的数据源配置中添加script_fields,动态将数组内容拼接为字符串,无需修改ElasticSearch索引结构。

修改后的数据源配置片段:

"data_sources": [
  {
    "type": "elasticsearch",
    "parameters": {
      "endpoint": "https://mytest.es.westeurope.azure.elastic-cloud.com",
      "index_name": "myindex",
      "authentication": {
        "type": "encoded_api_key",
        "encoded_api_key": "xxxxxx"
      },
      "query_type": "simple",
      "roleInformation": "You are a friendly assistant",
      "fields_mapping": {
        "title_field": "titleText",
        "content_fields": ["content_combined"]
      },
      "script_fields": {
        "content_combined": {
          "script": {
            "source": "doc['contentText'].values.join(' ')"
          }
        }
      }
    }
  }
]

说明

两种方案核心逻辑一致:将数组类型的contentText转换为单个字符串,让Azure OpenAI On Your Data的字段映射能正确识别并读取内容。方案1在索引层面处理,后续所有查询均可复用;方案2仅针对当前Azure配置的查询生效,无需修改索引。

内容的提问来源于stack exchange,提问作者torete

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 05:33:28