File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -135,7 +135,7 @@ export interface ClientOptions {
135
135
* @defaultValue null */
136
136
agent ?: HttpAgentOptions | UndiciAgentOptions | agentFn | false
137
137
/** @property nodeFilter A custom function used by the connection pool to determine which nodes are qualified to receive a request
138
- * @defaultValue () => true */
138
+ * @defaultValue A function that uses the Connection `roles` property to avoid master-only nodes */
139
139
nodeFilter ?: nodeFilterFn
140
140
/** @property nodeSelector A custom function used by the connection pool to determine which node should receive the next request
141
141
* @defaultValue A "round robin" function that loops sequentially through each node in the pool. */
Original file line number Diff line number Diff line change @@ -77,6 +77,31 @@ test('Missing node(s)', t => {
77
77
t . end ( )
78
78
} )
79
79
80
+ test ( 'multi nodes with roles, using default node filter' , async t => {
81
+ const client = new Client ( {
82
+ nodes : [
83
+ {
84
+ url : new URL ( 'http://node1:9200' ) ,
85
+ roles : { master : true , data : false , ingest : false , ml : false }
86
+ } ,
87
+ {
88
+ url : new URL ( 'http://node2:9200' ) ,
89
+ roles : { master : true , data : true , ingest : false , ml : false }
90
+ } ,
91
+ ]
92
+ } )
93
+ const conn = client . connectionPool . getConnection ( {
94
+ now : Date . now ( ) + 1000 * 60 * 3 ,
95
+ requestId : 1 ,
96
+ name : 'elasticsearch-js' ,
97
+ context : null
98
+ } )
99
+
100
+ t . equal ( conn ?. url . hostname , 'node2' )
101
+
102
+ t . end ( )
103
+ } )
104
+
80
105
test ( 'Custom headers' , t => {
81
106
const client = new Client ( {
82
107
node : 'http://localhost:9200' ,
You can’t perform that action at this time.
0 commit comments