简体   繁体   English

使用嵌套的elasticsearch自动完成映射

[英]elasticsearch autocompletion mapping using nest

I am using nest to implement elasticsearch in .net and am new to it. 我正在使用Nest在.net中实现elasticsearch,并且是它的新手。 I am trying to map suggesters please help me with it. 我正在尝试绘制建议者地图,请帮助我。 how to do that in c# using nest 如何在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
            }
        }
    }
}'

Find the complete code below. 在下面找到完整的代码。 It creates a new ElasticClient object and then adds the mapping song to the index songs . 它创建一个新的ElasticClient对象,然后将映射song添加到索引songs Make sure that index songs already exists before you execute this code. 在执行此代码之前,请确保索引songs已经存在。 You can also create the index songs before creating the mapping through code anyways. 无论如何,您还可以在通过代码创建映射之前创建索引songs I'll leave that upto you to figure out. 我让你自己去解决。 Find an exhaustive example of how mappings can be created in Nest here . 此处找到如何在Nest中创建映射的详尽示例。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM