「我正在嘗試使用ElasticSearch和它的NEST .NET客戶端在自動完成搜索的索引中創建我正在關注http://qbox.io/blog/an-introduction-to-ngrams-in-elasticsearch的教程並已運行。成問題,創建索引和它的設置時Sepcifically我想創建具有以下設置的指數(取直出本教程的TL的; DR,首先):如何使用嵌套將數組值設置屬性添加到ES索引
PUT /test_index
{
"settings": {
"analysis": {
"filter": {
"edge_ngram_filter": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 20
}
},
"analyzer": {
"edge_ngram_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"lowercase",
"edge_ngram_filter"
]
}
}
}
}
我的問題是我不知道如何發送"filter": [ "lowercase", "edge_ngram_filter" ]
部分使用NEST。我目前的嘗試看起來像這樣:
esclient.CreateIndex("test_index", s => s
.Settings(settings => settings
.Add("analysis.filter.edge_ngram_filter.type", "edge_ngram")
.Add("analysis.filter.edge_ngram_filter.min_gram", "2")
.Add("analysis.filter.edge_ngram_filter.max_gram", "20")
.Add("analysis.analyzer.edge_ngram_analyzer.type", "custom")
.Add("analysis.analyzer.edge_ngram_analyzer.tokenizer", "standard")
// Interesting part on the line below!
.Add("analysis.analyzer.edge_ngram_analyzer.filter", new string[] { "lowercase", "edge_ngram_filter" })
)
);
但是這失敗了一個JsonWriterException:「不支持的類型:System.String []。使用JsonSerializer類獲取對象的JSON表示。路徑「settings.index」。「我試圖簡單地手動提供JSON陣列(.Add("analysis.analyzer.edge_ngram_analyzer.filter", "[ \"lowercase\", "\edge_ngram_analyzer\" ]")
)的JSON代替轉義爲一個字符串。
是否NEST API提供這樣的方法嗎?