【发布时间】:2016-11-27 15:29:45
【问题描述】:
我想在 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# 代码中以编程方式定义这些字段映射的任何建议?另外,这些fieldMappings是否应该在索引定义的indexer里面定义呢?谢谢!
@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" }
}
};
【问题讨论】:
标签: azure search indexer azure-cognitive-search