1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
using Newtonsoft . Json ;
3
4
4
5
namespace Nest
@@ -20,41 +21,38 @@ public IUpdateResponse Update<T, K>(Action<UpdateDescriptor<T, K>> updateSelecto
20
21
var path = this . CreateUpdatePath < T , K > ( updateDescriptor ) ;
21
22
return this . _Update ( path , data ) ;
22
23
}
23
- private string CreateUpdatePath < T , K > ( UpdateDescriptor < T , K > s )
24
- where T : class
25
- where K : class
26
- {
27
- var index = s . _Index ?? this . IndexNameResolver . GetIndexForType < T > ( ) ;
28
- var type = s . _Type != null ? s . _Type . Resolve ( this . Settings ) : this . GetTypeNameFor < T > ( ) ;
29
- var id = s . _Id ?? this . IdResolver . GetIdFor ( s . _Object ) ;
30
-
31
- index . ThrowIfNullOrEmpty ( "index" ) ;
32
- type . ThrowIfNullOrEmpty ( "type" ) ;
33
- id . ThrowIfNullOrEmpty ( "id" ) ;
34
-
35
- var path = this . PathResolver . CreateIndexTypeIdPath ( index , type , id , "_update" ) + "/?" ;
36
- if ( s . _Consistency . HasValue )
37
- path += "consistency=" + Enum . GetName ( typeof ( Consistency ) , s . _Consistency . Value ) ;
38
- if ( s . _Replication . HasValue )
39
- path += "replication=" + Enum . GetName ( typeof ( Replication ) , s . _Replication . Value ) ;
40
- if ( s . _Refresh . HasValue )
41
- path += "refresh=" + s . _Refresh . Value . ToString ( ) . ToLower ( ) ;
42
-
43
- if ( s . _Timeout . HasValue )
44
- path += "timeout=" + s . _Timeout . ToString ( ) ;
45
- if ( s . _Timeout . HasValue )
46
- path += "timeout=" + s . _Timeout . ToString ( ) ;
24
+ private string CreateUpdatePath < T , K > ( UpdateDescriptor < T , K > s )
25
+ where T : class
26
+ where K : class
27
+ {
28
+ var index = s . _Index ?? this . IndexNameResolver . GetIndexForType < T > ( ) ;
29
+ var type = s . _Type != null ? s . _Type . Resolve ( this . Settings ) : this . GetTypeNameFor < T > ( ) ;
30
+ var id = s . _Id ?? this . IdResolver . GetIdFor ( s . _Object ) ;
47
31
48
- if ( ! string . IsNullOrWhiteSpace ( s . _Percolate ) )
49
- path += "percolate=" + s . _Percolate ;
32
+ index . ThrowIfNullOrEmpty ( "index" ) ;
33
+ type . ThrowIfNullOrEmpty ( "type" ) ;
34
+ id . ThrowIfNullOrEmpty ( "id" ) ;
50
35
51
- if ( ! string . IsNullOrWhiteSpace ( s . _Parent ) )
52
- path += "parent=" + s . _Parent ;
36
+ var querystringPairs = new List < string > ( ) ;
53
37
54
- if ( ! string . IsNullOrWhiteSpace ( s . _Routing ) )
55
- path += "routing=" + s . _Routing ;
38
+ if ( s . _Consistency . HasValue )
39
+ querystringPairs . Add ( "consistency=" + Enum . GetName ( typeof ( Consistency ) , s . _Consistency . Value ) ) ;
40
+ if ( s . _Replication . HasValue )
41
+ querystringPairs . Add ( "replication=" + Enum . GetName ( typeof ( Replication ) , s . _Replication . Value ) ) ;
42
+ if ( s . _Refresh . HasValue )
43
+ querystringPairs . Add ( "refresh=" + s . _Refresh . Value . ToString ( ) . ToLower ( ) ) ;
44
+ if ( s . _Timeout . HasValue )
45
+ querystringPairs . Add ( "timeout=" + s . _Timeout ) ;
46
+ if ( ! string . IsNullOrWhiteSpace ( s . _Percolate ) )
47
+ querystringPairs . Add ( "percolate=" + s . _Percolate ) ;
48
+ if ( ! string . IsNullOrWhiteSpace ( s . _Parent ) )
49
+ querystringPairs . Add ( "parent=" + s . _Parent ) ;
50
+ if ( ! string . IsNullOrWhiteSpace ( s . _Routing ) )
51
+ querystringPairs . Add ( "routing=" + s . _Routing ) ;
52
+ if ( s . _RetriesOnConflict . HasValue )
53
+ querystringPairs . Add ( "retries_on_conflict=" + s . _RetriesOnConflict ) ;
56
54
57
- return path ;
55
+ return this . PathResolver . CreateIndexTypeIdPath ( index , type , id , "_update" ) + "/?" + string . Join ( "&" , querystringPairs ) ;
58
56
}
59
57
60
58
0 commit comments