Azure认知搜索:如何映射嵌入文档列?

发布于 2025-01-16 15:11:16 字数 1926 浏览 1 评论 0原文

创建 ACS 索引时,我将 mongodb 作为后端数据源,并且 mongodb 中的一些列是 _id。根据 ACS 索引器的定义,名称不能以 _ 开头,因此我需要为 mongodb 集合列创建一些到 ACS 索引名称的映射。

mongodb 数据如下所示:

"customer": {
        "_id": {
            "$oid": "623a4b1bdb6d0a1210fd0234"
        },
        "customerName": "Andrew Jr"
    }

我创建的 ACS 索引定义是:

{
            "name": "customer",
            "type": "Edm.ComplexType",
            "fields": [
                {
                    "name": "id",
                    "type": "Edm.String",
                    "searchable": true,
                    "filterable": true,
                    "retrievable": true,
                    "sortable": true,
                    "facetable": true,
                    "key": false,
                    "indexAnalyzer": null,
                    "searchAnalyzer": null,
                    "analyzer": null,
                    "normalizer": null,
                    "synonymMaps": []
                },
                {
                    "name": "customerName",
                    "type": "Edm.String",
                    "searchable": true,
                    "filterable": true,
                    "retrievable": true,
                    "sortable": true,
                    "facetable": true,
                    "key": false,
                    "indexAnalyzer": null,
                    "searchAnalyzer": null,
                    "analyzer": null,
                    "normalizer": null,
                    "synonymMaps": []
                }
            ]
        }

所以基本上我想将客户嵌入文档中的字段 _id 从 mongodb 数据源映射到索引列 id。

我尝试使用索引器将它们映射在一起:

 "fieldMappings": [ { "sourceFieldName" : "_id", "targetFieldName" : "id" } ],

我收到错误:字段映射指定索引中不存在的目标字段“id”

如何定义 sourceFieldName 和 targertFieldName 来引用嵌入文档?

I have mongodb as the backend datasource when creating the ACS index and some columns from mongodb is _id. Per definition of the ACS indexer the name can not start with _ so I will need to create some mapping for the mongodb collection columns to the ACS index names.

The mongodb data is like below:

"customer": {
        "_id": {
            "$oid": "623a4b1bdb6d0a1210fd0234"
        },
        "customerName": "Andrew Jr"
    }

The ACS index definition I created is:

{
            "name": "customer",
            "type": "Edm.ComplexType",
            "fields": [
                {
                    "name": "id",
                    "type": "Edm.String",
                    "searchable": true,
                    "filterable": true,
                    "retrievable": true,
                    "sortable": true,
                    "facetable": true,
                    "key": false,
                    "indexAnalyzer": null,
                    "searchAnalyzer": null,
                    "analyzer": null,
                    "normalizer": null,
                    "synonymMaps": []
                },
                {
                    "name": "customerName",
                    "type": "Edm.String",
                    "searchable": true,
                    "filterable": true,
                    "retrievable": true,
                    "sortable": true,
                    "facetable": true,
                    "key": false,
                    "indexAnalyzer": null,
                    "searchAnalyzer": null,
                    "analyzer": null,
                    "normalizer": null,
                    "synonymMaps": []
                }
            ]
        }

So basically I want to map the field _id inside customer embedded document from the mongodb data source to the index column id.

I tried to use the indexer to map them together :

 "fieldMappings": [ { "sourceFieldName" : "_id", "targetFieldName" : "id" } ],

I am getting the error: Field mapping specifies target field 'id' that doesn't exist in the index

How can I define the sourceFieldName and targertFieldName to reference to embedded document ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

寻梦旅人 2025-01-23 15:11:16

我也一直在努力解决这个问题 - 如果你的问题与我的相同,不幸的是我认为这是不可能的。

在 Microsoft 文档此处,在页面顶部附近,它表示字段映射适用于:

仅限顶级搜索字段,其中“targetFieldName”是简单字段或集合。目标字段不能是复杂类型。

I've just been struggling with this too - if your issue is the same as mine, I don't think it is possible unfortunately.

In the Microsoft documentation here, near the top of the page it says field mappings apply to:

Top-level search fields only, where the "targetFieldName" is either a simple field or a collection. A target field can't be a complex type.

凉宸 2025-01-23 15:11:16

将“targetFieldName”值更改为“name”而不是“id”并检查执行情况。

"fieldMappings": [ { "sourceFieldName" : "_id", "targetFieldName" : "id" } ],

Change the "targetFieldName" value to "name" instead of "id" and check with the execution.

"fieldMappings": [ { "sourceFieldName" : "_id", "targetFieldName" : "id" } ],
陈年往事 2025-01-23 15:11:16

您可以使用更新索引器来管理现有索引器的字段映射API 请求。

PUT https://[service name].search.windows.net/indexers/myindexer?api-version=[api-version]
Content-Type: application/json
api-key: [admin key]
{
    "dataSourceName" : "mydatasource",
    "targetIndexName" : "myindex",
    "fieldMappings" : [ { "sourceFieldName" : "_id", "targetFieldName" : "id" } ]

一个源字段可以在多个字段映射中引用。

"fieldMappings" : [
    { "sourceFieldName" : "text", "targetFieldName" : "textStandardEnglishAnalyzer" },
    { "sourceFieldName" : "text", "targetFieldName" : "textSoundexAnalyzer" }
]
}

You can manage the field mappings of an existing indexer using the Update Indexer API request.

PUT https://[service name].search.windows.net/indexers/myindexer?api-version=[api-version]
Content-Type: application/json
api-key: [admin key]
{
    "dataSourceName" : "mydatasource",
    "targetIndexName" : "myindex",
    "fieldMappings" : [ { "sourceFieldName" : "_id", "targetFieldName" : "id" } ]

A source field can be referenced in multiple field mappings.

"fieldMappings" : [
    { "sourceFieldName" : "text", "targetFieldName" : "textStandardEnglishAnalyzer" },
    { "sourceFieldName" : "text", "targetFieldName" : "textSoundexAnalyzer" }
]
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文