我正在使用Nest在.net中实现elasticsearch,并且是它的新手。我正在尝试映射建议者,请帮助我。如何在C#中使用Nest做到这一点
curl -X PUT localhost:9200/songs/song/_mapping -d '{
"song" : {
"properties" : {
"name" : { "type" : "string" },
"suggest" : { "type" : "completion",
"index_analyzer" : "simple",
"search_analyzer" : "simple",
"payloads" : true
}
}
}
}'
最佳答案
在下面找到完整的代码。它创建一个新的ElasticClient
对象,然后将映射song
添加到索引songs
中。在执行此代码之前,请确保索引songs
已经存在。无论如何,您也可以在通过代码创建映射之前创建索引songs
。我让你自己去解决。查找如何在Nest here中创建映射的详尽示例。
var client = new ElasticClient(new ConnectionSettings(new Uri("http://localhost:9200")));
var response = client.Map<object>(d => d
.Index("songs")
.Type("song")
.Properties(props => props
.String(s => s
.Name("name"))
.Completion(c => c
.Name("suggest")
.IndexAnalyzer("simple")
.SearchAnalyzer("simple")
.Payloads())));
Debug.Assert(response.IsValid);
关于c# - 使用嵌套的elasticsearch自动完成映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34530264/