@@ -9,6 +9,7 @@ namespace Nest.Resolvers
99 public class IdResolver
1010 {
1111 private readonly IConnectionSettingsValues _connectionSettings ;
12+ private ConcurrentDictionary < Type , Func < object , string > > LocalIdDelegates = new ConcurrentDictionary < Type , Func < object , string > > ( ) ;
1213 private static ConcurrentDictionary < Type , Func < object , string > > IdDelegates = new ConcurrentDictionary < Type , Func < object , string > > ( ) ;
1314 private static MethodInfo MakeDelegateMethodInfo = typeof ( IdResolver ) . GetMethod ( "MakeDelegate" , BindingFlags . Static | BindingFlags . NonPublic ) ;
1415
@@ -56,7 +57,14 @@ public string GetIdFor<T>(T @object)
5657
5758 var type = typeof ( T ) ;
5859 Func < object , string > cachedLookup ;
59- if ( IdDelegates . TryGetValue ( type , out cachedLookup ) )
60+ string propertyName ;
61+
62+ var preferLocal = this . _connectionSettings . IdProperties . TryGetValue ( type , out propertyName ) ;
63+
64+ if ( LocalIdDelegates . TryGetValue ( type , out cachedLookup ) )
65+ return cachedLookup ( @object ) ;
66+
67+ if ( ! preferLocal && IdDelegates . TryGetValue ( type , out cachedLookup ) )
6068 return cachedLookup ( @object ) ;
6169
6270 var idProperty = GetInferredId ( type ) ;
@@ -75,7 +83,10 @@ public string GetIdFor<T>(T @object)
7583 var v = func ( obj ) ;
7684 return v != null ? v . ToString ( ) : null ;
7785 } ;
78- IdDelegates . TryAdd ( type , cachedLookup ) ;
86+ if ( preferLocal )
87+ LocalIdDelegates . TryAdd ( type , cachedLookup ) ;
88+ else
89+ IdDelegates . TryAdd ( type , cachedLookup ) ;
7990 return cachedLookup ( @object ) ;
8091 }
8192 catch
0 commit comments