Skip to content

Commit dfedbbf

Browse files
committed
Index management + tests
1 parent 4518b00 commit dfedbbf

File tree

166 files changed

+10263
-3688
lines changed

Some content is hidden

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

166 files changed

+10263
-3688
lines changed

build/scripts/packages.lock.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@
8080
},
8181
"FSharp.Core": {
8282
"type": "Direct",
83-
"requested": "[5.0.0, )",
84-
"resolved": "5.0.0",
85-
"contentHash": "iHoYXA0VaSQUONGENB1aVafjDDZDZpwu39MtaRCTrmwFW/cTcK0b2yKNVYneFHJMc3ChtsSoM9lNtJ1dYXkHfA=="
83+
"requested": "[6.0.0-beta.*, )",
84+
"resolved": "6.0.0",
85+
"contentHash": "fbv1UwJ2LXVcFCt+GGDPu0sIYA5C6gdDvAupDj3iLQF3clRkua/6J33f+FiGQa8P1tEa+zmz3wrjoTnXZ1UiYg=="
8686
},
8787
"Microsoft.NETFramework.ReferenceAssemblies": {
8888
"type": "Direct",

src/Elastic.Clients.Elasticsearch/Common/Infer/DataStreamName/DataStreamNames.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88

99
namespace Elastic.Clients.Elasticsearch
1010
{
11-
//public partial class DataStreamNames
12-
//{
13-
// // This is temporary
14-
// public DataStreamNames(IEnumerable<DataStreamName> names) => _dataStreamNameList.AddRange(names);
11+
// TODO - Implement properly
12+
public sealed partial class DataStreamNames : IUrlParameter
13+
{
14+
// This is temporary
15+
//public DataStreamNames(IEnumerable<DataStreamName> names) => _dataStreamNameList.AddRange(names);
1516

16-
// public string GetString(ITransportConfiguration settings) => throw new NotImplementedException();
17-
//}
17+
public string GetString(ITransportConfiguration settings) => throw new NotImplementedException();
18+
}
19+
20+
public sealed partial class DataStreamName : IUrlParameter
21+
{
22+
public string GetString(ITransportConfiguration settings) => throw new NotImplementedException();
23+
}
1824
}

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

Lines changed: 135 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -3,155 +3,151 @@
33
// See the LICENSE file in the project root for more information
44

55
using System;
6+
using System.Collections;
67
using System.Collections.Generic;
8+
using System.Diagnostics;
9+
using System.Linq;
10+
using System.Linq.Expressions;
11+
using System.Reflection;
712
using Elastic.Transport;
813

9-
namespace Elastic.Clients.Elasticsearch
14+
namespace Elastic.Clients.Elasticsearch;
15+
16+
[DebuggerDisplay("{DebugDisplay,nq}")]
17+
public partial class Fields : IUrlParameter, IEnumerable<Field>, IEquatable<Fields>
1018
{
11-
public partial class Fields
19+
internal readonly List<Field> ListOfFields;
20+
21+
internal Fields() => ListOfFields = new List<Field>();
22+
23+
internal Fields(IEnumerable<Field> fieldNames) => ListOfFields = fieldNames.ToList();
24+
25+
private string DebugDisplay =>
26+
$"Count: {ListOfFields.Count} [" +
27+
string.Join(",", ListOfFields.Select((t, i) => $"({i + 1}: {t?.DebugDisplay ?? "NULL"})")) + "]";
28+
29+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
30+
31+
public IEnumerator<Field> GetEnumerator() => ListOfFields.GetEnumerator();
32+
33+
public bool Equals(Fields other) => EqualsAllFields(ListOfFields, other?.ListOfFields);
34+
35+
string IUrlParameter.GetString(ITransportConfiguration settings)
1236
{
13-
// This is temporary
14-
public Fields(IEnumerable<Field> fields) => _fieldList.AddRange(fields);
37+
if (!(settings is IElasticsearchClientSettings elasticsearchClientSettings))
38+
{
39+
throw new ArgumentNullException(nameof(settings),
40+
$"Can not resolve {nameof(Fields)} if no {nameof(IElasticsearchClientSettings)} is provided");
41+
}
42+
43+
return string.Join(",",
44+
ListOfFields.Where(f => f != null).Select(f => ((IUrlParameter)f).GetString(elasticsearchClientSettings)));
45+
}
46+
47+
public override string ToString() => DebugDisplay;
48+
49+
public static implicit operator Fields(string[] fields) =>
50+
fields.IsEmpty() ? null : new Fields(fields.Select(f => new Field(f)));
1551

16-
public string GetString(ITransportConfiguration settings) => throw new NotImplementedException();
52+
public static implicit operator Fields(string field) => field.IsNullOrEmptyCommaSeparatedList(out var split)
53+
? null
54+
: new Fields(split.Select(f => new Field(f)));
55+
56+
public static implicit operator Fields(Expression[] fields) =>
57+
fields.IsEmpty() ? null : new Fields(fields.Select(f => new Field(f)));
58+
59+
public static implicit operator Fields(Expression field) =>
60+
field == null ? null : new Fields(new[] { new Field(field) });
61+
62+
public static implicit operator Fields(Field field) => field == null ? null : new Fields(new[] { field });
63+
64+
public static implicit operator Fields(PropertyInfo field) =>
65+
field == null ? null : new Fields(new Field[] { field });
66+
67+
public static implicit operator Fields(PropertyInfo[] fields) =>
68+
fields.IsEmpty() ? null : new Fields(fields.Select(f => new Field(f)));
69+
70+
public static implicit operator Fields(Field[] fields) => fields.IsEmpty() ? null : new Fields(fields);
71+
72+
public Fields And<T, TValue>(Expression<Func<T, TValue>> field, double? boost = null, string format = null)
73+
where T : class
74+
{
75+
ListOfFields.Add(new Field(field, boost, format));
76+
return this;
1777
}
1878

19-
//[DebuggerDisplay("{DebugDisplay,nq}")]
20-
//public partial class Fields : IUrlParameter, IEnumerable<Field>, IEquatable<Fields>
21-
//{
22-
// internal readonly List<Field> ListOfFields;
79+
public Fields And(string field, double? boost = null, string format = null)
80+
{
81+
ListOfFields.Add(new Field(field, boost, format));
82+
return this;
83+
}
2384

24-
// internal Fields() => ListOfFields = new List<Field>();
85+
public Fields And(PropertyInfo property, double? boost = null)
86+
{
87+
ListOfFields.Add(new Field(property, boost));
88+
return this;
89+
}
90+
91+
public Fields And<T>(params Expression<Func<T, object>>[] fields) where T : class
92+
{
93+
ListOfFields.AddRange(fields.Select(f => new Field(f)));
94+
return this;
95+
}
96+
97+
public Fields And(params string[] fields)
98+
{
99+
ListOfFields.AddRange(fields.Select(f => new Field(f)));
100+
return this;
101+
}
102+
103+
public Fields And(params PropertyInfo[] properties)
104+
{
105+
ListOfFields.AddRange(properties.Select(f => new Field(f)));
106+
return this;
107+
}
108+
109+
public Fields And(params Field[] fields)
110+
{
111+
ListOfFields.AddRange(fields);
112+
return this;
113+
}
114+
115+
public static bool operator ==(Fields left, Fields right) => Equals(left, right);
25116

26-
// internal Fields(IEnumerable<Field> fieldNames) => ListOfFields = fieldNames.ToList();
117+
public static bool operator !=(Fields left, Fields right) => !Equals(left, right);
27118

28-
// private string DebugDisplay =>
29-
// $"Count: {ListOfFields.Count} [" +
30-
// string.Join(",", ListOfFields.Select((t, i) => $"({i + 1}: {t?.DebugDisplay ?? "NULL"})")) + "]";
119+
public override bool Equals(object obj)
120+
{
121+
switch (obj)
122+
{
123+
case Fields f:
124+
return Equals(f);
125+
case string s:
126+
return Equals(s);
127+
case Field fn:
128+
return Equals(fn);
129+
case Field[] fns:
130+
return Equals(fns);
131+
case Expression e:
132+
return Equals(e);
133+
case Expression[] es:
134+
return Equals(es);
135+
default:
136+
return false;
137+
}
138+
}
139+
140+
private static bool EqualsAllFields(IReadOnlyList<Field> thisTypes, IReadOnlyList<Field> otherTypes)
141+
{
142+
if (thisTypes == null && otherTypes == null)
143+
return true;
144+
if (thisTypes == null || otherTypes == null)
145+
return false;
146+
if (thisTypes.Count != otherTypes.Count)
147+
return false;
148+
149+
return thisTypes.Count == otherTypes.Count && !thisTypes.Except(otherTypes).Any();
150+
}
31151

32-
// IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
33-
34-
// public IEnumerator<Field> GetEnumerator() => ListOfFields.GetEnumerator();
35-
36-
// public bool Equals(Fields other) => EqualsAllFields(ListOfFields, other?.ListOfFields);
37-
38-
// string IUrlParameter.GetString(ITransportConfiguration settings)
39-
// {
40-
// if (!(settings is IElasticsearchClientSettings Elastic.Clients.ElasticsearchSettings))
41-
// {
42-
// throw new ArgumentNullException(nameof(settings),
43-
// $"Can not resolve {nameof(Fields)} if no {nameof(IElasticsearchClientSettings)} is provided");
44-
// }
45-
46-
// return string.Join(",",
47-
// ListOfFields.Where(f => f != null).Select(f => ((IUrlParameter)f).GetString(Elastic.Clients.ElasticsearchSettings)));
48-
// }
49-
50-
// public override string ToString() => DebugDisplay;
51-
52-
// public static implicit operator Fields(string[] fields) =>
53-
// fields.IsEmpty() ? null : new Fields(fields.Select(f => new Field(f)));
54-
55-
// public static implicit operator Fields(string field) => field.IsNullOrEmptyCommaSeparatedList(out var split)
56-
// ? null
57-
// : new Fields(split.Select(f => new Field(f)));
58-
59-
// public static implicit operator Fields(Expression[] fields) =>
60-
// fields.IsEmpty() ? null : new Fields(fields.Select(f => new Field(f)));
61-
62-
// public static implicit operator Fields(Expression field) =>
63-
// field == null ? null : new Fields(new[] {new Field(field)});
64-
65-
// public static implicit operator Fields(Field field) => field == null ? null : new Fields(new[] {field});
66-
67-
// public static implicit operator Fields(PropertyInfo field) =>
68-
// field == null ? null : new Fields(new Field[] {field});
69-
70-
// public static implicit operator Fields(PropertyInfo[] fields) =>
71-
// fields.IsEmpty() ? null : new Fields(fields.Select(f => new Field(f)));
72-
73-
// public static implicit operator Fields(Field[] fields) => fields.IsEmpty() ? null : new Fields(fields);
74-
75-
// public Fields And<T, TValue>(Expression<Func<T, TValue>> field, double? boost = null, string format = null)
76-
// where T : class
77-
// {
78-
// ListOfFields.Add(new Field(field, boost, format));
79-
// return this;
80-
// }
81-
82-
// public Fields And(string field, double? boost = null, string format = null)
83-
// {
84-
// ListOfFields.Add(new Field(field, boost, format));
85-
// return this;
86-
// }
87-
88-
// public Fields And(PropertyInfo property, double? boost = null)
89-
// {
90-
// ListOfFields.Add(new Field(property, boost));
91-
// return this;
92-
// }
93-
94-
// public Fields And<T>(params Expression<Func<T, object>>[] fields) where T : class
95-
// {
96-
// ListOfFields.AddRange(fields.Select(f => new Field(f)));
97-
// return this;
98-
// }
99-
100-
// public Fields And(params string[] fields)
101-
// {
102-
// ListOfFields.AddRange(fields.Select(f => new Field(f)));
103-
// return this;
104-
// }
105-
106-
// public Fields And(params PropertyInfo[] properties)
107-
// {
108-
// ListOfFields.AddRange(properties.Select(f => new Field(f)));
109-
// return this;
110-
// }
111-
112-
// public Fields And(params Field[] fields)
113-
// {
114-
// ListOfFields.AddRange(fields);
115-
// return this;
116-
// }
117-
118-
// public static bool operator ==(Fields left, Fields right) => Equals(left, right);
119-
120-
// public static bool operator !=(Fields left, Fields right) => !Equals(left, right);
121-
122-
// public override bool Equals(object obj)
123-
// {
124-
// switch (obj)
125-
// {
126-
// case Fields f:
127-
// return Equals(f);
128-
// case string s:
129-
// return Equals(s);
130-
// case Field fn:
131-
// return Equals(fn);
132-
// case Field[] fns:
133-
// return Equals(fns);
134-
// case Expression e:
135-
// return Equals(e);
136-
// case Expression[] es:
137-
// return Equals(es);
138-
// default:
139-
// return false;
140-
// }
141-
// }
142-
143-
// private static bool EqualsAllFields(IReadOnlyList<Field> thisTypes, IReadOnlyList<Field> otherTypes)
144-
// {
145-
// if (thisTypes == null && otherTypes == null)
146-
// return true;
147-
// if (thisTypes == null || otherTypes == null)
148-
// return false;
149-
// if (thisTypes.Count != otherTypes.Count)
150-
// return false;
151-
152-
// return thisTypes.Count == otherTypes.Count && !thisTypes.Except(otherTypes).Any();
153-
// }
154-
155-
// public override int GetHashCode() => ListOfFields.GetHashCode();
156-
//}
152+
public override int GetHashCode() => ListOfFields.GetHashCode();
157153
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Licensed to Elasticsearch B.V under one or more agreements.
2+
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
3+
// See the LICENSE file in the project root for more information
4+
5+
using System;
6+
using Elastic.Transport;
7+
8+
namespace Elastic.Clients.Elasticsearch;
9+
10+
// TODO - Implement
11+
public class IndexAlias : IUrlParameter
12+
{
13+
public string GetString(ITransportConfiguration settings) => throw new NotImplementedException();
14+
}

0 commit comments

Comments
 (0)