我们允许客户在创建索引时定义自定义分析器。我们更愿意在 json 中指定这一点,以便通过底层 ElasticSearch 文档提供最大的灵活性和可理解性。
我想使用 json 字符串中定义的分析器、映射器等的任意描述来创建索引。使用感觉,我的命令是
PUT /my_index
{
"settings":
{
"analysis":
{
"char_filter" :
{
"my_mapping" :
{
"type" : "mapping",
"mappings" : [".=>,", "'=>,"]
}
},
"analyzer":
{
"my_analyzer":
{
"type": "custom",
"tokenizer": "standard",
"filter": ["lowercase" ],
"char_filter" : ["my_mapping"]
}
}
}
}
}
}
理想情况下,我的代码看起来像
string json = RetrieveJson();
ElasticSearchClient client = InitializeClient();
client.CreateIndexUsingJson( json ); // this is the syntax I can't figure out
帖子here https://stackoverflow.com/questions/23220874/creating-an-index-nest尝试通过实例化 IndexSettings 然后调用 Add( "analysis", json ) 来实现此目的,但 Add 不是我正在使用的 ElasticSearch 库版本上的函数。
我可以想象的选项包括:
- 以某种方式使用 ElasticClient.Raw.IndicesCreatePost 或类似的东西
- 通过 IndexSettingsConverter.ReadJson() 将 json 字符串反序列化为 IndexSettings 对象,然后通过 ElasticClient.CreateIndex(ICreateIndexRequest) 应用该对象
这两种机制的文档都非常少。
我绝对试图避免 CreateIndex 的 lambda 函数版本,因为将用户的 json 转换为 lamdba 表达式,然后立即将它们转换回 NEST 深处的 json 会很痛苦。
非常感谢上面#1 或#2 的其他选项或具体示例,这也是解决此问题的推荐方法。