While upgrading to elastic 2.3.1 I am running into a snag with the .Net Nest Client.
In Nest 1.0, I could read an index's settings from a file and configure the index on creation using the raw string. Is there a way to the something similar in Nest 2.0 or do I have to use the fluent API for each setting including the analysis portion? The same question for mappings.
Nest 1.0
private bool CreateIndex(string index, FileInfo settingsFile)
{
var settings = File.ReadAllText(settingsFile.FullName);
IElasticsearchConnector _elastic
var response = _elastic.Client.Raw.IndicesCreate(index, settings);
if (!response.IsValid)
{
//Logging error
return false
}
return true;
}
ElasticClient.Raw
has been renamed to ElasticClient.LowLevel
.
This is how you can compose your request in NEST 2.x.
_elastic.Client.LowLevel.IndicesCreate<object>(indexName, File.ReadAllText("index.json"));
Content of index.json
file:
{
"settings" : {
"index" : {
"number_of_shards" : 1,
"number_of_replicas" : 1
},
"analysis" : {
"analyzer" : {
"analyzer-name" : {
"type" : "custom",
"tokenizer" : "keyword",
"filter" : "lowercase"
}
}
},
"mappings" : {
"employeeinfo" : {
"properties" : {
"age" : {
"type" : "long"
},
"experienceInYears" : {
"type" : "long"
},
"name" : {
"type" : "string",
"analyzer" : "analyzer-name"
}
}
}
}
}
}
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With