创建天蓝色搜索索引时无法识别IsSearchable

时间:2020-10-30 10:03:25

标签: c# .net azure-cognitive-search .net-4.6.1 azure-search-.net-sdk

我正在尝试为以下型号创建索引。

public class Booking
    {
        [System.ComponentModel.DataAnnotations.Key]
        [IsSearchable,IsFilterable,IsSortable]
        public string BookId { get; set; }

        [IsSearchable, IsFilterable]
        public string BooknName { get; set; }
    }

创建索引的代码

 FieldBuilder fieldBuilder = new FieldBuilder();
 var searchFields = fieldBuilder.Build(typeof(Booking));
 var definition = new SearchIndex(indexName, searchFields);
 indexClient.CreateOrUpdateIndex(definition);

enter image description here

但是当我查看定义并通过将所有这些都设置为false来创建索引时,这会以某种方式忽略IsSearchable/IsFilterable

我在这里还缺少其他财产吗?我正在使用Azure.Search.Documents - Version=11.1.1.0

2 个答案:

答案 0 :(得分:2)

自从您实例化FieldBuilder以来,我假设您正在使用Azure.Search.Documents。在这种情况下,您需要使用我们添加的新属性,例如SearchableFieldAttribute。先前的属性有效地对应于属性。有关示例,请参见https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/search/Azure.Search.Documents/samples/Sample04_FieldBuilderIgnore.md

Microsoft.Azure.Search将很快被弃用,顺便说一句。

答案 1 :(得分:0)

您是否犯了拼写错误?看起来在Booking类中,您拥有“ BooknName”,索引称为“ bookname”。

相关问题