gpt4 book ai didi

azure - 在 C# 代码中定义 AzureSearch 索引字段映射

转载 作者:行者123 更新时间:2023-12-03 05:57:31 25 4
gpt4 key购买 nike

我想在 C# 中以编程方式定义 JSON 对象和 Azure 搜索索引之间的字段映射。我在这里找到了有关如何在 Javascript 中执行此操作的解释 https://azure.microsoft.com/en-us/documentation/articles/search-howto-index-json-blobs/

 "fieldMappings" : [ 
{ "sourceFieldName" : "/article/text", "targetFieldName" : "text" },
{ "sourceFieldName" : "/article/datePublished", "targetFieldName" : "date" },
{ "sourceFieldName" : "/article/tags", "targetFieldName" : "tags" }
]

但是我需要 C# 等效代码。到目前为止我已经尝试过了:

      var index = new
{
name = "testindex",
fields = new []
{
//...
},
fieldMappings = new[]
{
new { sourceFieldName = "/status/text", targetFieldName = "text"}
}
}

但是此代码因异常而崩溃

{"Azure Search request failed:{\"error\":{\"code\":\"\",\"message\":\"The request is invalid. Details: index : The property 'fieldMappings' does not exist on type 'Microsoft.Azure.Search.V2015_02_28.IndexDefinition'. Make sure to only use property names that are defined by the type.\\r\\n\"}}"}

关于如何在 C# 代码中以编程方式定义这些字段映射,有什么建议吗?另外,这些 fieldMapping 是否应该在索引定义的索引器内定义?谢谢!

@LaterEdit:摘自本文Creating Collection in Azure Search Service using Indexer我发现这些映射必须在索引器上定义,但如果我在定义索引器时添加它们,属性 fieldMappings 仍然不存在。

  var indexer = new
{
name = "textixr",
dataSourceName = "testsdocdb",
schedule = new { interval = "PT5M" }, // every 5 minutes
targetIndexName = "test",
fieldMappings = new []
{
new { sourceFieldName = "/status/text", targetFieldName = "text" }
}
};

最佳答案

您需要使用 api 版本 2015-02-28-预览版。字段映射在 2015 年 2 月 28 日不可用。

顺便说一句,只有在使用 blob 索引器对 JSON blob 进行索引时,才能使用带有 JSON 指针的字段映射(例如 /status/text)。它们不能与 DocumentDB 索引器一起使用。要使用 DocumentDB 投影嵌套属性,请在数据源定义的 container.query 属性中使用类似 SQL 的查询。有关 DocumentDB 索引器的更多信息,请查看 this article

关于azure - 在 C# 代码中定义 AzureSearch 索引字段映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38548270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com