pavan sp
pavan sp

Reputation: 105

elasticsearch autocompletion mapping using nest

I am using nest to implement elasticsearch in .net and am new to it. I am trying to map suggesters please help me with it. how to do that in c# using 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
            }
        }
    }
}'

Upvotes: 0

Views: 1283

Answers (1)

bittusarkar
bittusarkar

Reputation: 6357

Find the complete code below. It creates a new ElasticClient object and then adds the mapping song to the index songs. Make sure that index songs already exists before you execute this code. You can also create the index songs before creating the mapping through code anyways. I'll leave that upto you to figure out. Find an exhaustive example of how mappings can be created in 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);

Upvotes: 1

Related Questions