Skip to content

Commit 65bb0ab

Browse files
committed
fix #2316 although uncommon and no longer supported in 5.x Elasticsearch 2.x allows you to also send camelCase versions of settings and these will not be normalized and returned as is, we should also support these at read time. PascalCase is not supported
1 parent 7f93d1b commit 65bb0ab

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/Nest/IndexModules/IndexSettings/Settings/IndexSettingsConverter.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,23 @@ private void SetKnownIndexSettings(JsonReader reader, JsonSerializer serializer,
207207

208208
private static void Set<T>(IIndexSettings s, IDictionary<string, JProperty> settings, string key, Action<T> assign, JsonSerializer serializer = null)
209209
{
210-
if (!settings.ContainsKey(key)) return;
210+
if (!settings.ContainsKey(key)) key = ToCamelCase(key);
211+
if (!settings.ContainsKey(key)) return;
212+
211213
var v = settings[key];
212214
T value = serializer == null ? v.Value.ToObject<T>() : v.Value.ToObject<T>(serializer);
213215
assign(value);
214216
s.Add(key, value);
215217
settings.Remove(key);
216-
}
218+
}
219+
private static string ToCamelCase(string indexSettingKey) =>
220+
string.Join(".", indexSettingKey
221+
.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries)
222+
.Select(t=>t
223+
.Split(new[] { "_" }, StringSplitOptions.RemoveEmptyEntries)
224+
.Select((s,i) => i == 0 ? s : char.ToUpperInvariant(s[0]) + s.Substring(1, s.Length - 1))
225+
.Aggregate(string.Empty, (s1, s2) => s1 + s2)
226+
)
227+
);
217228
}
218229
}

src/Tests/IndexModules/IndexSettings/Settings/TypedIndexSettings.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using FluentAssertions;
34
using Nest;
45
using Tests.Framework;
56

@@ -34,7 +35,7 @@ public class Usage : PromiseUsageTestBase<IIndexSettings, IndexSettingsDescripto
3435
};
3536

3637
/**
37-
*
38+
*
3839
*/
3940
protected override Func<IndexSettingsDescriptor, IPromise<IIndexSettings>> Fluent => s => s
4041
.Setting("any.setting", "can be set")
@@ -81,5 +82,24 @@ public class Usage : PromiseUsageTestBase<IIndexSettings, IndexSettingsDescripto
8182
FileSystemStorageImplementation = FileSystemStorageImplementation.MMap
8283
};
8384
}
85+
86+
87+
public class CamelCaseSettingsAreReadCorrectlyTests : SerializationTestBase
88+
{
89+
[U] public void CamelCasedTypedSettings()
90+
{
91+
var indexSettings = new Nest.IndexSettings
92+
{
93+
{ "index.numberOfShards", 2 }
94+
};
95+
var settings = this.Serialize(indexSettings);
96+
var deserizalized = this.Deserialize<Nest.IndexSettings>(settings);
97+
98+
deserizalized.NumberOfShards.Should().Be(2);
99+
100+
101+
102+
}
103+
}
84104
}
85105
}

0 commit comments

Comments
 (0)