Skip to content

Commit e1dc69b

Browse files
Add Put Mapping API (#6236) (#6237)
Co-authored-by: Steve Gordon <sgordon@hotmail.co.uk>
1 parent 19f5dd5 commit e1dc69b

File tree

197 files changed

+5290
-356
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+5290
-356
lines changed

src/Elastic.Clients.Elasticsearch/Common/Fluent/Promise/DescriptorPromiseBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public abstract class DescriptorPromiseBase<TDescriptor, TValue> : IDescriptor,
1818
{
1919
internal readonly TValue PromisedValue;
2020

21-
protected DescriptorPromiseBase(TValue instance)
21+
internal DescriptorPromiseBase(TValue instance)
2222
{
2323
PromisedValue = instance;
2424
Self = (TDescriptor)this;

src/Elastic.Clients.Elasticsearch/Common/Infer/PropertyName/PropertyName.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public PropertyName(PropertyInfo property)
6161

6262
string IUrlParameter.GetString(ITransportConfiguration settings)
6363
{
64-
if (!(settings is IElasticsearchClientSettings elasticsearchSettings))
64+
if (settings is not IElasticsearchClientSettings elasticsearchSettings)
6565
{
6666
throw new ArgumentNullException(nameof(settings),
6767
$"Can not resolve {nameof(PropertyName)} if no {nameof(IElasticsearchClientSettings)} is provided");

src/Elastic.Clients.Elasticsearch/Common/IsADictionaryBase.cs

Lines changed: 109 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -8,157 +8,159 @@
88
using System.ComponentModel;
99
using System.Linq;
1010

11-
namespace Elastic.Clients.Elasticsearch
12-
{
11+
namespace Elastic.Clients.Elasticsearch;
12+
13+
public interface IIsADictionary { }
1314

14-
public interface IIsADictionary { }
15+
public interface IIsADictionary<TKey, TValue> : IDictionary<TKey, TValue>, IIsADictionary { }
1516

16-
public interface IIsADictionary<TKey, TValue> : IDictionary<TKey, TValue>, IIsADictionary { }
17+
/// <summary>
18+
/// A base dictionary type for internally tagged unions.
19+
/// </summary>
20+
/// <typeparam name="TKey"></typeparam>
21+
/// <typeparam name="TValue"></typeparam>
1722

18-
public abstract class IsADictionaryBase<TKey, TValue> : IIsADictionary<TKey, TValue>
23+
public abstract class IsADictionaryBase<TKey, TValue> : IIsADictionary<TKey, TValue>
24+
{
25+
internal IsADictionaryBase() => BackingDictionary = new Dictionary<TKey, TValue>();
26+
27+
internal IsADictionaryBase(IDictionary<TKey, TValue> backingDictionary)
1928
{
20-
protected IsADictionaryBase() => BackingDictionary = new Dictionary<TKey, TValue>();
29+
if (backingDictionary != null)
30+
foreach (var key in backingDictionary.Keys)
31+
ValidateKey(Sanitize(key));
2132

22-
protected IsADictionaryBase(IDictionary<TKey, TValue> backingDictionary)
23-
{
24-
// ReSharper disable VirtualMemberCallInConstructor
25-
if (backingDictionary != null)
26-
foreach (var key in backingDictionary.Keys)
27-
ValidateKey(Sanitize(key));
28-
// ReSharper enable VirtualMemberCallInConstructor
33+
BackingDictionary = backingDictionary != null
34+
? new Dictionary<TKey, TValue>(backingDictionary)
35+
: new Dictionary<TKey, TValue>();
36+
}
2937

30-
BackingDictionary = backingDictionary != null
31-
? new Dictionary<TKey, TValue>(backingDictionary)
32-
: new Dictionary<TKey, TValue>();
33-
}
38+
public TValue this[TKey key]
39+
{
40+
get => BackingDictionary[Sanitize(key)];
41+
set => BackingDictionary[ValidateKey(Sanitize(key))] = value;
42+
}
3443

35-
public TValue this[TKey key]
36-
{
37-
get => BackingDictionary[Sanitize(key)];
38-
set => BackingDictionary[ValidateKey(Sanitize(key))] = value;
39-
}
44+
internal Dictionary<TKey, TValue> BackingDictionary { get; }
45+
int ICollection<KeyValuePair<TKey, TValue>>.Count => BackingDictionary.Count;
46+
bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly => Self.IsReadOnly;
4047

41-
protected Dictionary<TKey, TValue> BackingDictionary { get; }
42-
int ICollection<KeyValuePair<TKey, TValue>>.Count => BackingDictionary.Count;
43-
bool ICollection<KeyValuePair<TKey, TValue>>.IsReadOnly => Self.IsReadOnly;
48+
TValue IDictionary<TKey, TValue>.this[TKey key]
49+
{
50+
get => BackingDictionary[Sanitize(key)];
51+
set => BackingDictionary[ValidateKey(Sanitize(key))] = value;
52+
}
4453

45-
TValue IDictionary<TKey, TValue>.this[TKey key]
46-
{
47-
get => BackingDictionary[Sanitize(key)];
48-
set => BackingDictionary[ValidateKey(Sanitize(key))] = value;
49-
}
54+
ICollection<TKey> IDictionary<TKey, TValue>.Keys => BackingDictionary.Keys;
55+
private ICollection<KeyValuePair<TKey, TValue>> Self => BackingDictionary;
56+
ICollection<TValue> IDictionary<TKey, TValue>.Values => BackingDictionary.Values;
5057

51-
ICollection<TKey> IDictionary<TKey, TValue>.Keys => BackingDictionary.Keys;
52-
private ICollection<KeyValuePair<TKey, TValue>> Self => BackingDictionary;
53-
ICollection<TValue> IDictionary<TKey, TValue>.Values => BackingDictionary.Values;
58+
void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item)
59+
{
60+
ValidateKey(Sanitize(item.Key));
61+
Self.Add(item);
62+
}
5463

55-
void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item)
56-
{
57-
ValidateKey(Sanitize(item.Key));
58-
Self.Add(item);
59-
}
64+
void ICollection<KeyValuePair<TKey, TValue>>.Clear() => BackingDictionary.Clear();
6065

61-
void ICollection<KeyValuePair<TKey, TValue>>.Clear() => BackingDictionary.Clear();
66+
[EditorBrowsable(EditorBrowsableState.Never)]
67+
bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> item) => Self.Contains(item);
6268

63-
[EditorBrowsable(EditorBrowsableState.Never)]
64-
bool ICollection<KeyValuePair<TKey, TValue>>.Contains(KeyValuePair<TKey, TValue> item) => Self.Contains(item);
69+
void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex) => Self.CopyTo(array, arrayIndex);
6570

66-
void ICollection<KeyValuePair<TKey, TValue>>.CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex) => Self.CopyTo(array, arrayIndex);
71+
bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item) => Self.Remove(item);
6772

68-
bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item) => Self.Remove(item);
73+
void IDictionary<TKey, TValue>.Add(TKey key, TValue value) => BackingDictionary.Add(ValidateKey(Sanitize(key)), value);
6974

70-
void IDictionary<TKey, TValue>.Add(TKey key, TValue value) => BackingDictionary.Add(ValidateKey(Sanitize(key)), value);
75+
[EditorBrowsable(EditorBrowsableState.Never)]
76+
bool IDictionary<TKey, TValue>.ContainsKey(TKey key) => BackingDictionary.ContainsKey(Sanitize(key));
7177

72-
[EditorBrowsable(EditorBrowsableState.Never)]
73-
bool IDictionary<TKey, TValue>.ContainsKey(TKey key) => BackingDictionary.ContainsKey(Sanitize(key));
78+
bool IDictionary<TKey, TValue>.Remove(TKey key) => BackingDictionary.Remove(Sanitize(key));
7479

75-
bool IDictionary<TKey, TValue>.Remove(TKey key) => BackingDictionary.Remove(Sanitize(key));
80+
bool IDictionary<TKey, TValue>.TryGetValue(TKey key, out TValue value) => BackingDictionary.TryGetValue(Sanitize(key), out value);
7681

77-
bool IDictionary<TKey, TValue>.TryGetValue(TKey key, out TValue value) => BackingDictionary.TryGetValue(Sanitize(key), out value);
82+
IEnumerator IEnumerable.GetEnumerator() => BackingDictionary.GetEnumerator();
7883

79-
IEnumerator IEnumerable.GetEnumerator() => BackingDictionary.GetEnumerator();
84+
IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator() => BackingDictionary.GetEnumerator();
8085

81-
IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator() => BackingDictionary.GetEnumerator();
86+
protected virtual TKey ValidateKey(TKey key) => key;
8287

83-
protected virtual TKey ValidateKey(TKey key) => key;
88+
protected virtual TKey Sanitize(TKey key) => key;
89+
}
8490

85-
protected virtual TKey Sanitize(TKey key) => key;
86-
}
91+
public abstract class IsADictionaryDescriptorBase<TDescriptor, TPromised, TKey, TValue>
92+
: DescriptorPromiseBase<TDescriptor, TPromised>
93+
where TDescriptor : IsADictionaryDescriptorBase<TDescriptor, TPromised, TKey, TValue>
94+
where TPromised : class, IIsADictionary<TKey, TValue>
95+
{
96+
protected IsADictionaryDescriptorBase(TPromised instance) : base(instance) { }
8797

88-
public abstract class IsADictionaryDescriptorBase<TDescriptor, TPromised, TKey, TValue>
89-
: DescriptorPromiseBase<TDescriptor, TPromised>
90-
where TDescriptor : IsADictionaryDescriptorBase<TDescriptor, TPromised, TKey, TValue>
91-
where TPromised : class, IIsADictionary<TKey, TValue>
98+
protected TDescriptor Assign(TKey key, TValue value)
9299
{
93-
protected IsADictionaryDescriptorBase(TPromised instance) : base(instance) { }
94-
95-
protected TDescriptor Assign(TKey key, TValue value)
96-
{
97-
PromisedValue.Add(key, value);
98-
return Self;
99-
}
100+
PromisedValue.Add(key, value);
101+
return Self;
100102
}
103+
}
101104

102-
public interface IIsAReadOnlyDictionary { }
105+
public interface IIsAReadOnlyDictionary { }
103106

104-
public interface IIsAReadOnlyDictionary<TKey, TValue> : IReadOnlyDictionary<TKey, TValue>, IIsAReadOnlyDictionary { }
107+
public interface IIsAReadOnlyDictionary<TKey, TValue> : IReadOnlyDictionary<TKey, TValue>, IIsAReadOnlyDictionary { }
105108

106-
public abstract class IsAReadOnlyDictionaryBase<TKey, TValue> : IIsAReadOnlyDictionary<TKey, TValue>
109+
public abstract class IsAReadOnlyDictionaryBase<TKey, TValue> : IIsAReadOnlyDictionary<TKey, TValue>
110+
{
111+
protected IsAReadOnlyDictionaryBase(IReadOnlyDictionary<TKey, TValue> backingDictionary)
107112
{
108-
protected IsAReadOnlyDictionaryBase(IReadOnlyDictionary<TKey, TValue> backingDictionary)
109-
{
110-
if (backingDictionary == null)
111-
return;
113+
if (backingDictionary == null)
114+
return;
112115

113-
var dictionary = new Dictionary<TKey, TValue>(backingDictionary.Count);
114-
foreach (var key in backingDictionary.Keys)
115-
// ReSharper disable once VirtualMemberCallInConstructor
116-
// expect all implementations of Sanitize to be pure
117-
dictionary[Sanitize(key)] = backingDictionary[key];
116+
var dictionary = new Dictionary<TKey, TValue>(backingDictionary.Count);
117+
foreach (var key in backingDictionary.Keys)
118+
// ReSharper disable once VirtualMemberCallInConstructor
119+
// expect all implementations of Sanitize to be pure
120+
dictionary[Sanitize(key)] = backingDictionary[key];
118121

119-
BackingDictionary = dictionary;
120-
}
122+
BackingDictionary = dictionary;
123+
}
121124

122-
public int Count => BackingDictionary.Count;
125+
public int Count => BackingDictionary.Count;
123126

124-
public TValue this[TKey key] => BackingDictionary[key];
127+
public TValue this[TKey key] => BackingDictionary[key];
125128

126-
public IEnumerable<TKey> Keys => BackingDictionary.Keys;
129+
public IEnumerable<TKey> Keys => BackingDictionary.Keys;
127130

128-
public IEnumerable<TValue> Values => BackingDictionary.Values;
129-
protected internal IReadOnlyDictionary<TKey, TValue> BackingDictionary { get; } = EmptyReadOnly<TKey, TValue>.Dictionary;
131+
public IEnumerable<TValue> Values => BackingDictionary.Values;
132+
protected internal IReadOnlyDictionary<TKey, TValue> BackingDictionary { get; } = EmptyReadOnly<TKey, TValue>.Dictionary;
130133

131-
IEnumerator IEnumerable.GetEnumerator() => BackingDictionary.GetEnumerator();
134+
IEnumerator IEnumerable.GetEnumerator() => BackingDictionary.GetEnumerator();
132135

133-
IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator() =>
134-
BackingDictionary.GetEnumerator();
136+
IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator() =>
137+
BackingDictionary.GetEnumerator();
135138

136-
public bool ContainsKey(TKey key) => BackingDictionary.ContainsKey(key);
139+
public bool ContainsKey(TKey key) => BackingDictionary.ContainsKey(key);
137140

138-
public bool TryGetValue(TKey key, out TValue value) =>
139-
BackingDictionary.TryGetValue(key, out value);
141+
public bool TryGetValue(TKey key, out TValue value) =>
142+
BackingDictionary.TryGetValue(key, out value);
140143

141-
protected virtual TKey Sanitize(TKey key) => key;
142-
}
144+
protected virtual TKey Sanitize(TKey key) => key;
145+
}
143146

144-
internal static class EmptyReadOnlyExtensions
145-
{
146-
public static IReadOnlyCollection<T> ToReadOnlyCollection<T>(this IEnumerable<T> enumerable) =>
147-
enumerable == null ? EmptyReadOnly<T>.Collection : new ReadOnlyCollection<T>(enumerable.ToList());
147+
internal static class EmptyReadOnlyExtensions
148+
{
149+
public static IReadOnlyCollection<T> ToReadOnlyCollection<T>(this IEnumerable<T> enumerable) =>
150+
enumerable == null ? EmptyReadOnly<T>.Collection : new ReadOnlyCollection<T>(enumerable.ToList());
148151

149-
public static IReadOnlyCollection<T> ToReadOnlyCollection<T>(this IList<T> enumerable) =>
150-
enumerable == null || enumerable.Count == 0 ? EmptyReadOnly<T>.Collection : new ReadOnlyCollection<T>(enumerable);
151-
}
152+
public static IReadOnlyCollection<T> ToReadOnlyCollection<T>(this IList<T> enumerable) =>
153+
enumerable == null || enumerable.Count == 0 ? EmptyReadOnly<T>.Collection : new ReadOnlyCollection<T>(enumerable);
154+
}
152155

153156

154-
internal static class EmptyReadOnly<TElement>
155-
{
156-
public static readonly IReadOnlyCollection<TElement> Collection = new ReadOnlyCollection<TElement>(new TElement[0]);
157-
public static readonly IReadOnlyList<TElement> List = new List<TElement>();
158-
}
157+
internal static class EmptyReadOnly<TElement>
158+
{
159+
public static readonly IReadOnlyCollection<TElement> Collection = new ReadOnlyCollection<TElement>(new TElement[0]);
160+
public static readonly IReadOnlyList<TElement> List = new List<TElement>();
161+
}
159162

160-
internal static class EmptyReadOnly<TKey, TValue>
161-
{
162-
public static readonly IReadOnlyDictionary<TKey, TValue> Dictionary = new ReadOnlyDictionary<TKey, TValue>(new Dictionary<TKey, TValue>(0));
163-
}
163+
internal static class EmptyReadOnly<TKey, TValue>
164+
{
165+
public static readonly IReadOnlyDictionary<TKey, TValue> Dictionary = new ReadOnlyDictionary<TKey, TValue>(new Dictionary<TKey, TValue>(0));
164166
}

src/Elastic.Clients.Elasticsearch/Serialization/DefaultRequestResponseSerializer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public DefaultRequestResponseSerializer(IElasticsearchClientSettings settings)
4545
new SelfTwoWaySerializableConverterFactory(settings),
4646
new IndicesJsonConverter(settings),
4747
new DictionaryConverter(),
48+
new IsADictionaryConverter(),
4849
new UnionConverter()
4950
},
5051
PropertyNamingPolicy = JsonNamingPolicy.CamelCase

0 commit comments

Comments
 (0)