Skip to content

Instantly share code, notes, and snippets.

@tomlokhorst
Created July 8, 2014 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomlokhorst/d9d19559f7e2ab3610a7 to your computer and use it in GitHub Desktop.
Save tomlokhorst/d9d19559f7e2ab3610a7 to your computer and use it in GitHub Desktop.
// Current (C# 5) syntax
var request = new CreateIndexRequest("new-index-name")
{
IndexSettings = new IndexSettings
{
Settings = new Dictionary<string, object>
{
{"index.settings", "value"}
},
Mappings = new List<RootObjectMapping>
{
new RootObjectMapping
{
Name = "my_root_object",
Properties = new Dictionary<PropertyNameMarker, IElasticType>
{
{"my_field", new StringMapping() { Analyzer = "default" } }
}
}
}
}
};
// C# 6 dictionary initializer syntax
var request = new CreateIndexRequest("new-index-name")
{
IndexSettings = new IndexSettings
{
Settings = {
"index.settings" = "value"
},
Mappings = {
new RootObjectMapping
{
Name = "my_root_object",
Properties = {
"my_field" = new StringMapping() { Analyzer = "default" }
}
}
}
}
};
// C# 6 member initializer syntax
var request = new CreateIndexRequest("new-index-name")
{
IndexSettings = new IndexSettings
{
Settings = {
$index_settings = "value" // Custom made-up serializer maps _ to .
},
Mappings = {
new RootObjectMapping
{
Name = "my_root_object",
Properties = {
$my_field = new StringMapping() { Analyzer = "default" }
}
}
}
}
};
{
"settings": {
"index.settings": "value"
},
"mappings": {
"my_root_object": {
"properties": {
"my_field": { "analyzer": "default" }
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment