Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIFI-14104 allow setting of HTTP Request Headers for Elasticsearch requests #9606

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -292,157 +292,167 @@ public interface ElasticSearchClientService extends ControllerService, Verifiabl
* Index a document.
*
* @param operation A document to index.
* @param requestParameters A collection of URL request parameters. Optional.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
* @return IndexOperationResponse if successful
*/
IndexOperationResponse add(IndexOperationRequest operation, Map<String, String> requestParameters);
IndexOperationResponse add(IndexOperationRequest operation, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Bulk process multiple documents.
*
* @param operations A list of index operations.
* @param requestParameters A collection of URL request parameters. Optional.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
* @return IndexOperationResponse if successful.
*/
IndexOperationResponse bulk(List<IndexOperationRequest> operations, Map<String, String> requestParameters);
IndexOperationResponse bulk(List<IndexOperationRequest> operations, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Count the documents that match the criteria.
*
* @param query A query in the JSON DSL syntax
* @param index The index to target.
* @param type The type to target. Will not be used in future versions of Elasticsearch.
* @param requestParameters A collection of URL request parameters. Optional.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
* @return number of documents matching the query
*/
Long count(String query, String index, String type, Map<String, String> requestParameters);
Long count(String query, String index, String type, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Delete a document by its ID from an index.
*
* @param index The index to target.
* @param type The type to target. Optional. Will not be used in future versions of Elasticsearch.
* @param id The document ID to remove from the selected index.
* @param requestParameters A collection of URL request parameters. Optional.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
* @return A DeleteOperationResponse object if successful.
*/
DeleteOperationResponse deleteById(String index, String type, String id, Map<String, String> requestParameters);
DeleteOperationResponse deleteById(String index, String type, String id, ElasticsearchRequestOptions elasticsearchRequestOptions);


/**
* Delete multiple documents by ID from an index.
* @param index The index to target.
* @param type The type to target. Optional. Will not be used in future versions of Elasticsearch.
* @param ids A list of document IDs to remove from the selected index.
* @param requestParameters A collection of URL request parameters. Optional.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
* @return A DeleteOperationResponse object if successful.
*/
DeleteOperationResponse deleteById(String index, String type, List<String> ids, Map<String, String> requestParameters);
DeleteOperationResponse deleteById(String index, String type, List<String> ids, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Delete documents by query.
*
* @param query A valid JSON query to be used for finding documents to delete.
* @param index The index to target.
* @param type The type to target within the index. Optional. Will not be used in future versions of Elasticsearch.
* @param requestParameters A collection of URL request parameters. Optional.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
* @return A DeleteOperationResponse object if successful.
*/
DeleteOperationResponse deleteByQuery(String query, String index, String type, Map<String, String> requestParameters);
DeleteOperationResponse deleteByQuery(String query, String index, String type, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Update documents by query.
*
* @param query A valid JSON query to be used for finding documents to update.
* @param index The index to target.
* @param type The type to target within the index. Optional. Will not be used in future versions of Elasticsearch.
* @param requestParameters A collection of URL request parameters. Optional.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
* @return An UpdateOperationResponse object if successful.
*/
UpdateOperationResponse updateByQuery(String query, String index, String type, Map<String, String> requestParameters);
UpdateOperationResponse updateByQuery(String query, String index, String type, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Refresh index/indices.
*
* @param index The index to target, if omitted then all indices will be updated.
* @param requestParameters A collection of URL request parameters. Optional.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
*/
void refresh(final String index, final Map<String, String> requestParameters);
void refresh(String index, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Check whether an index exists.
*
* @param index The index to check.
* @param requestParameters A collection of URL request parameters. Optional.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
* @return true if index exists, false otherwise
*/
boolean exists(final String index, final Map<String, String> requestParameters);
boolean exists(String index, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Check whether a document exists.
*
* @param index The index that holds the document.
* @param type The document type. Optional. Will not be used in future versions of Elasticsearch.
* @param id The document ID
* @param requestParameters A collection of URL request parameters. Optional.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
* @return true if doc exists in index, false otherwise
*/
boolean documentExists(final String index, final String type, final String id, final Map<String, String> requestParameters);
boolean documentExists(String index, String type, String id, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Get a document by ID.
*
* @param index The index that holds the document.
* @param type The document type. Optional. Will not be used in future versions of Elasticsearch.
* @param id The document ID
* @param requestParameters A collection of URL request parameters. Optional.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
* @return Map if successful, null if not found.
*/
Map<String, Object> get(String index, String type, String id, Map<String, String> requestParameters);
Map<String, Object> get(String index, String type, String id, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Perform a search using the JSON DSL.
*
* @param query A JSON string representing the query.
* @param index The index to target. Optional.
* @param type The type to target. Optional. Will not be used in future versions of Elasticsearch.
* @param requestParameters A collection of URL request parameters. Optional.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
* @return A SearchResponse object if successful.
*/
SearchResponse search(String query, String index, String type, Map<String, String> requestParameters);
SearchResponse search(String query, String index, String type, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Retrieve next page of results from a Scroll.
*
* @param scroll A JSON string containing scrollId and optional scroll (keep alive) retention period.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
* Request Parameters will be ignored from the Request Options as unusable for this API.
* @return A SearchResponse object if successful.
*/
SearchResponse scroll(String scroll);
SearchResponse scroll(String scroll, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Initialise a Point in Time for paginated queries.
* Requires Elasticsearch 7.10+ and XPack features.
*
* @param index Index targeted.
* @param keepAlive Point in Time's retention period (maximum time Elasticsearch will retain the PiT between requests). Optional.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
* Request Parameters will be ignored from the Request Options as unusable for this API.
* @return the Point in Time Id (pit_id)
*/
String initialisePointInTime(String index, String keepAlive);
String initialisePointInTime(String index, String keepAlive, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Delete a Point in Time.
* Requires Elasticsearch 7.10+ and XPack features.
*
* @param pitId Point in Time Id to be deleted.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
* Request Parameters will be ignored from the Request Options as unusable for this API.
* @return A DeleteOperationResponse object if successful.
*/
DeleteOperationResponse deletePointInTime(String pitId);
DeleteOperationResponse deletePointInTime(String pitId, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Delete a Scroll.
*
* @param scrollId Scroll Id to be deleted.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
* Request Parameters will be ignored from the Request Options as unusable for this API.
* @return A DeleteOperationResponse object if successful.
*/
DeleteOperationResponse deleteScroll(String scrollId);
DeleteOperationResponse deleteScroll(String scrollId, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Build a transit URL to use with the provenance reporter.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.nifi.elasticsearch;

import java.util.HashMap;
import java.util.Map;

public class ElasticsearchRequestOptions {
private final Map<String, String> requestParameters;
private final Map<String, String> requestHeaders;

public ElasticsearchRequestOptions(final Map<String, String> requestParameters, final Map<String, String> requestHeaders) {
this.requestParameters = requestParameters == null ? new HashMap<>() : requestParameters;
this.requestHeaders = requestHeaders == null ? new HashMap<>() : requestHeaders;
}

public ElasticsearchRequestOptions() {
this(new HashMap<>(), new HashMap<>());
}

public Map<String, String> getRequestParameters() {
return requestParameters;
}

public Map<String, String> getRequestHeaders() {
return requestHeaders;
}
}
Loading