Skip to content

Commit 7d33f21

Browse files
committed
NIFI-14104 allow setting of HTTP Request Headers for Elasticsearch requests
1 parent e3fff91 commit 7d33f21

29 files changed

+538
-305
lines changed

nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service-api/src/main/java/org/apache/nifi/elasticsearch/ElasticSearchClientService.java

+35-17
Original file line numberDiff line numberDiff line change
@@ -262,18 +262,20 @@ public interface ElasticSearchClientService extends ControllerService, Verifiabl
262262
*
263263
* @param operation A document to index.
264264
* @param requestParameters A collection of URL request parameters. Optional.
265+
* @param requestHeaders A collection of request headers. Optional.
265266
* @return IndexOperationResponse if successful
266267
*/
267-
IndexOperationResponse add(IndexOperationRequest operation, Map<String, String> requestParameters);
268+
IndexOperationResponse add(IndexOperationRequest operation, Map<String, String> requestParameters, Map<String, String> requestHeaders);
268269

269270
/**
270271
* Bulk process multiple documents.
271272
*
272273
* @param operations A list of index operations.
273274
* @param requestParameters A collection of URL request parameters. Optional.
275+
* @param requestHeaders A collection of request headers. Optional.
274276
* @return IndexOperationResponse if successful.
275277
*/
276-
IndexOperationResponse bulk(List<IndexOperationRequest> operations, Map<String, String> requestParameters);
278+
IndexOperationResponse bulk(List<IndexOperationRequest> operations, Map<String, String> requestParameters, Map<String, String> requestHeaders);
277279

278280
/**
279281
* Count the documents that match the criteria.
@@ -282,9 +284,10 @@ public interface ElasticSearchClientService extends ControllerService, Verifiabl
282284
* @param index The index to target.
283285
* @param type The type to target. Will not be used in future versions of Elasticsearch.
284286
* @param requestParameters A collection of URL request parameters. Optional.
287+
* @param requestHeaders A collection of request headers. Optional.
285288
* @return number of documents matching the query
286289
*/
287-
Long count(String query, String index, String type, Map<String, String> requestParameters);
290+
Long count(String query, String index, String type, Map<String, String> requestParameters, Map<String, String> requestHeaders);
288291

289292
/**
290293
* Delete a document by its ID from an index.
@@ -293,9 +296,10 @@ public interface ElasticSearchClientService extends ControllerService, Verifiabl
293296
* @param type The type to target. Optional. Will not be used in future versions of Elasticsearch.
294297
* @param id The document ID to remove from the selected index.
295298
* @param requestParameters A collection of URL request parameters. Optional.
299+
* @param requestHeaders A collection of request headers. Optional.
296300
* @return A DeleteOperationResponse object if successful.
297301
*/
298-
DeleteOperationResponse deleteById(String index, String type, String id, Map<String, String> requestParameters);
302+
DeleteOperationResponse deleteById(String index, String type, String id, Map<String, String> requestParameters, Map<String, String> requestHeaders);
299303

300304

301305
/**
@@ -304,9 +308,10 @@ public interface ElasticSearchClientService extends ControllerService, Verifiabl
304308
* @param type The type to target. Optional. Will not be used in future versions of Elasticsearch.
305309
* @param ids A list of document IDs to remove from the selected index.
306310
* @param requestParameters A collection of URL request parameters. Optional.
311+
* @param requestHeaders A collection of request headers. Optional.
307312
* @return A DeleteOperationResponse object if successful.
308313
*/
309-
DeleteOperationResponse deleteById(String index, String type, List<String> ids, Map<String, String> requestParameters);
314+
DeleteOperationResponse deleteById(String index, String type, List<String> ids, Map<String, String> requestParameters, Map<String, String> requestHeaders);
310315

311316
/**
312317
* Delete documents by query.
@@ -315,9 +320,10 @@ public interface ElasticSearchClientService extends ControllerService, Verifiabl
315320
* @param index The index to target.
316321
* @param type The type to target within the index. Optional. Will not be used in future versions of Elasticsearch.
317322
* @param requestParameters A collection of URL request parameters. Optional.
323+
* @param requestHeaders A collection of request headers. Optional.
318324
* @return A DeleteOperationResponse object if successful.
319325
*/
320-
DeleteOperationResponse deleteByQuery(String query, String index, String type, Map<String, String> requestParameters);
326+
DeleteOperationResponse deleteByQuery(String query, String index, String type, Map<String, String> requestParameters, Map<String, String> requestHeaders);
321327

322328
/**
323329
* Update documents by query.
@@ -326,25 +332,29 @@ public interface ElasticSearchClientService extends ControllerService, Verifiabl
326332
* @param index The index to target.
327333
* @param type The type to target within the index. Optional. Will not be used in future versions of Elasticsearch.
328334
* @param requestParameters A collection of URL request parameters. Optional.
335+
* @param requestHeaders A collection of request headers. Optional.
329336
* @return An UpdateOperationResponse object if successful.
330337
*/
331-
UpdateOperationResponse updateByQuery(String query, String index, String type, Map<String, String> requestParameters);
338+
UpdateOperationResponse updateByQuery(String query, String index, String type, Map<String, String> requestParameters, Map<String, String> requestHeaders);
332339

333340
/**
334341
* Refresh index/indices.
335342
*
336343
* @param index The index to target, if omitted then all indices will be updated.
337344
* @param requestParameters A collection of URL request parameters. Optional.
345+
* @param requestHeaders A collection of request headers. Optional.
338346
*/
339-
void refresh(final String index, final Map<String, String> requestParameters);
347+
void refresh(final String index, final Map<String, String> requestParameters, Map<String, String> requestHeaders);
340348

341349
/**
342350
* Check whether an index exists.
343351
*
344352
* @param index The index to check.
345353
* @param requestParameters A collection of URL request parameters. Optional.
354+
* @param requestHeaders A collection of request headers. Optional.
355+
* @return true if index exists, false otherwise
346356
*/
347-
boolean exists(final String index, final Map<String, String> requestParameters);
357+
boolean exists(final String index, final Map<String, String> requestParameters, Map<String, String> requestHeaders);
348358

349359
/**
350360
* Check whether a document exists.
@@ -353,8 +363,10 @@ public interface ElasticSearchClientService extends ControllerService, Verifiabl
353363
* @param type The document type. Optional. Will not be used in future versions of Elasticsearch.
354364
* @param id The document ID
355365
* @param requestParameters A collection of URL request parameters. Optional.
366+
* @param requestHeaders A collection of request headers. Optional.
367+
* @return true if doc exists in index, false otherwise
356368
*/
357-
boolean documentExists(final String index, final String type, final String id, final Map<String, String> requestParameters);
369+
boolean documentExists(final String index, final String type, final String id, final Map<String, String> requestParameters, Map<String, String> requestHeaders);
358370

359371
/**
360372
* Get a document by ID.
@@ -363,55 +375,61 @@ public interface ElasticSearchClientService extends ControllerService, Verifiabl
363375
* @param type The document type. Optional. Will not be used in future versions of Elasticsearch.
364376
* @param id The document ID
365377
* @param requestParameters A collection of URL request parameters. Optional.
378+
* @param requestHeaders A collection of request headers. Optional.
366379
* @return Map if successful, null if not found.
367380
*/
368-
Map<String, Object> get(String index, String type, String id, Map<String, String> requestParameters);
381+
Map<String, Object> get(String index, String type, String id, Map<String, String> requestParameters, Map<String, String> requestHeaders);
369382

370383
/**
371384
* Perform a search using the JSON DSL.
372385
*
373-
* @param query A JSON string reprensenting the query.
386+
* @param query A JSON string representing the query.
374387
* @param index The index to target. Optional.
375388
* @param type The type to target. Optional. Will not be used in future versions of Elasticsearch.
376389
* @param requestParameters A collection of URL request parameters. Optional.
390+
* @param requestHeaders A collection of request headers. Optional.
377391
* @return A SearchResponse object if successful.
378392
*/
379-
SearchResponse search(String query, String index, String type, Map<String, String> requestParameters);
393+
SearchResponse search(String query, String index, String type, Map<String, String> requestParameters, Map<String, String> requestHeaders);
380394

381395
/**
382396
* Retrieve next page of results from a Scroll.
383397
*
384398
* @param scroll A JSON string containing scrollId and optional scroll (keep alive) retention period.
399+
* @param requestHeaders A collection of request headers. Optional.
385400
* @return A SearchResponse object if successful.
386401
*/
387-
SearchResponse scroll(String scroll);
402+
SearchResponse scroll(String scroll, Map<String, String> requestHeaders);
388403

389404
/**
390405
* Initialise a Point in Time for paginated queries.
391406
* Requires Elasticsearch 7.10+ and XPack features.
392407
*
393408
* @param index Index targeted.
394409
* @param keepAlive Point in Time's retention period (maximum time Elasticsearch will retain the PiT between requests). Optional.
410+
* @param requestHeaders A collection of request headers. Optional.
395411
* @return the Point in Time Id (pit_id)
396412
*/
397-
String initialisePointInTime(String index, String keepAlive);
413+
String initialisePointInTime(String index, String keepAlive, Map<String, String> requestHeaders);
398414

399415
/**
400416
* Delete a Point in Time.
401417
* Requires Elasticsearch 7.10+ and XPack features.
402418
*
403419
* @param pitId Point in Time Id to be deleted.
420+
* @param requestHeaders A collection of request headers. Optional.
404421
* @return A DeleteOperationResponse object if successful.
405422
*/
406-
DeleteOperationResponse deletePointInTime(String pitId);
423+
DeleteOperationResponse deletePointInTime(String pitId, Map<String, String> requestHeaders);
407424

408425
/**
409426
* Delete a Scroll.
410427
*
411428
* @param scrollId Scroll Id to be deleted.
429+
* @param requestHeaders A collection of request headers. Optional.
412430
* @return A DeleteOperationResponse object if successful.
413431
*/
414-
DeleteOperationResponse deleteScroll(String scrollId);
432+
DeleteOperationResponse deleteScroll(String scrollId, Map<String, String> requestHeaders);
415433

416434
/**
417435
* Build a transit URL to use with the provenance reporter.

0 commit comments

Comments
 (0)