-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathIndexNameResolver.cs
45 lines (37 loc) · 1.09 KB
/
IndexNameResolver.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.Concurrent;
using System.Reflection;
using Elasticsearch.Net;
namespace Nest.Resolvers
{
public class IndexNameResolver
{
private readonly IConnectionSettingsValues _connectionSettings;
public IndexNameResolver(IConnectionSettingsValues connectionSettings)
{
connectionSettings.ThrowIfNull("hasDefaultIndices");
this._connectionSettings = connectionSettings;
}
public string GetIndexForType<T>()
{
return this.GetIndexForType(typeof(T));
}
public string GetIndexForType(Type type)
{
var defaultIndices = this._connectionSettings.DefaultIndices;
if (defaultIndices == null)
return this._connectionSettings.DefaultIndex;
string value;
if (defaultIndices.TryGetValue(type, out value) && !string.IsNullOrWhiteSpace(value))
return value;
return this._connectionSettings.DefaultIndex;
}
internal string GetIndexForType(IndexNameMarker i)
{
return i.Name ?? this.GetIndexForType(i.Type);
}
}
}