askids
askids

Reputation: 1696

Creating Elasticsearch Index using NEST 5.x

I am trying to create an index using NEST 5.x pre release version for Elasticsearch 5.x. I have samples from 2.x which shows how index can be created using ElasticClient.CreateIndex method. Below is my sample code.

ESnode = new Uri("http://localhost:9200");
Nodesettings = new ConnectionSettings(ESnode);
Client = new ElasticClient(Nodesettings);

However, when I am typing below, there is NO autocomplete available.

Client.CreateIndex( c => c.

I am able to successfully get the health of the node using below code.

var res = Client.ClusterHealth();
Console.WriteLine("Status:" + res.Status);

I am having a complex document mapping for which I have defined the class structure and intend to use Automap method. Hence I am trying to create the index programatically to avoid manually creating the index.

I tried using some very old version of NEST (1.x) and I am able to get the autocomplete for createIndex. But both v2.4x and 5.x did not provide the autocomplete. Is there a new way to create index? Please let me know.

Thanks

Upvotes: 3

Views: 6496

Answers (1)

Russ Cam
Russ Cam

Reputation: 125488

You need to supply a name to the index, in addition to the delegate that provides additional index creation options

var createIndexResponse = client.CreateIndex("index-name", c => c
    .Settings(s => s
        .NumberOfShards(1)
        .NumberOfReplicas(0)
    )
    .Mappings(m => m
        .Map<Conference>(d => d
            .AutoMap()
        )
    )
);

Upvotes: 11

Related Questions