如何使用Azure Search .NET SDK中的json文件使用自定义分析器创建索引? [英] How to create Index with custom analyzers from json file in Azure Search .NET SDK?

查看:84
本文介绍了如何使用Azure Search .NET SDK中的json文件使用自定义分析器创建索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经了解到,Azure Search .NET SDK使用NewtonSoft.Json在其底层REST API调用中将其模型转换为json,或从json转换为json,所以我在自己的应用程序中一直这样做.

I had read that the Azure Search .NET SDK uses NewtonSoft.Json to convert it's models to/from json in it's underlying REST API calls so I've been doing the same in my own app.

我有一个简单的应用程序,它使用.NET SDK创建了一个新索引.为此,我使用以下格式概述了json文件中的索引: https://docs.microsoft.com/zh-cn/rest/api/searchservice/create-index ,然后我将其转换为Microsoft.Azure.Search.Models.Index对象使用Newtonsoft.

I have a simple app which creates a new Index using the .NET SDK. To do this, I was defining my Index in a json file, using the format outlined here https://docs.microsoft.com/en-us/rest/api/searchservice/create-index and then I was converting this to a Microsoft.Azure.Search.Models.Index object using Newtonsoft.

var index = JsonConvert.DeserializeObject<Microsoft.Azure.Search.Models.Index>(System.IO.File.ReadAllText("config.json");

在配置自定义分析器之前,此方法工作正常,但由于配置中包含自定义分析器,因此无法将分析器,令牌生成器和令牌过滤器解析为正确的类型. IE.我的自定义分析器被反序列化为Microsoft.Azure.Search.Models.Analyzer,而不是Microsoft.Azure.Search.Models.CustomAnalyzer,Tokenizer和TokenFilters也是如此,它们都被反序列化为基本类型.

This was working fine before I configured custom Analyzers, but now that I have custom Analyzers in my config, the Analyzers, Tokenizers, and TokenFilters are not being resolved into the correct types. ie. my custom Analyzer is being deserialized as a Microsoft.Azure.Search.Models.Analyzer, instead of Microsoft.Azure.Search.Models.CustomAnalyzer, same goes for the Tokenizers and TokenFilters, they are being deserialized into the base types.

是否可以通过json文件在.NET SDK中创建像这样的索引的简单方法?

Is there an easy way I can create an Index like this in the .NET SDK from a json file?

推荐答案

不幸的是,这不是官方支持的方案.虽然它适用于简单的索引定义,但我们正在努力了解为支持所有情况而需要做的事情.

Unfortunately this is not an officially supported scenario. While it works for simple index definitions, we're working to understand what we need to do to be able to support all cases.

请在我们的用户语音"页面上发布您的功能请求,以帮助我们确定优先级: https://feedback.azure.com/forums/263029-azure-search

Please post your feature request on our User Voice page to help us prioritize: https://feedback.azure.com/forums/263029-azure-search

同时,您可以通过调整

In the meantime, you might be able to get it working yourself by adapting the JsonSerializerSettings initialization code at the bottom of this file.

这篇关于如何使用Azure Search .NET SDK中的json文件使用自定义分析器创建索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆