【问题标题】:IsSearchable not recognized when creating azure search index创建天蓝色搜索索引时无法识别 IsSearchable
【发布时间】:2021-02-12 18:56:46
【问题描述】:

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

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);

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

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

【问题讨论】:

  • 你有没有拼写错误?看起来在 Booking 类中您有“BooknName”,您的索引称为“bookname”。
  • 您是从 SDK 版本 10 迁移吗? IsSearchable 和其他属性来自什么命名空间?
  • 啊,是的,我刚刚在这里创建了一个小版本的类。实际课程是书名,并且有更多字段。
  • @BruceJohnston:我是新手,正在尝试全新的。它来自Microsoft.Azure.Search.Service, Version=10.1.0.0
  • 查看希思的回复。您正在尝试将旧 SDK (Microsoft.Azure.Search.*) 中的属性与新 SDK (Azure.Search.Documents) 一起使用,但它们不能一起使用。

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


【解决方案1】:

由于您正在实例化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 很快就会被弃用,顺便说一句。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-15
    • 2020-03-02
    • 1970-01-01
    • 2021-11-16
    • 2017-09-14
    • 1970-01-01
    • 2021-01-29
    相关资源
    最近更新 更多