Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce ElasticsearchRequestOptions to allow for per-request parame…
Browse files Browse the repository at this point in the history
…ters and headers in Elasticsearch operations
ChrisSamo632 committed Jan 24, 2025
1 parent 8745743 commit afa6bb2
Showing 25 changed files with 378 additions and 323 deletions.
Original file line number Diff line number Diff line change
@@ -261,175 +261,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 requestHeaders A collection of request headers. Optional.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
* @return IndexOperationResponse if successful
*/
IndexOperationResponse add(IndexOperationRequest operation, Map<String, String> requestParameters, Map<String, String> requestHeaders);
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 requestHeaders A collection of request headers. 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, Map<String, String> requestHeaders);
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 requestHeaders A collection of request headers. 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, Map<String, String> requestHeaders);
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 requestHeaders A collection of request headers. 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, Map<String, String> requestHeaders);
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 requestHeaders A collection of request headers. 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, Map<String, String> requestHeaders);
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 requestHeaders A collection of request headers. 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, Map<String, String> requestHeaders);
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 requestHeaders A collection of request headers. 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, Map<String, String> requestHeaders);
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 requestHeaders A collection of request headers. Optional.
* @param elasticsearchRequestOptions A collection of request options (parameters and header). Optional.
*/
void refresh(final String index, final Map<String, String> requestParameters, Map<String, String> requestHeaders);
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 requestHeaders A collection of request headers. 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, Map<String, String> requestHeaders);
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 requestHeaders A collection of request headers. 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, Map<String, String> requestHeaders);
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 requestHeaders A collection of request headers. 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, String> requestHeaders);
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 requestHeaders A collection of request headers. 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, Map<String, String> requestHeaders);
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 requestHeaders A collection of request headers. 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 A SearchResponse object if successful.
*/
SearchResponse scroll(String scroll, Map<String, String> requestHeaders);
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 requestHeaders A collection of request headers. 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, Map<String, String> requestHeaders);
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 requestHeaders A collection of request headers. 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 A DeleteOperationResponse object if successful.
*/
DeleteOperationResponse deletePointInTime(String pitId, Map<String, String> requestHeaders);
DeleteOperationResponse deletePointInTime(String pitId, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Delete a Scroll.
*
* @param scrollId Scroll Id to be deleted.
* @param requestHeaders A collection of request headers. 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 A DeleteOperationResponse object if successful.
*/
DeleteOperationResponse deleteScroll(String scrollId, Map<String, String> requestHeaders);
DeleteOperationResponse deleteScroll(String scrollId, ElasticsearchRequestOptions elasticsearchRequestOptions);

/**
* Build a transit URL to use with the provenance reporter.
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

0 comments on commit afa6bb2

Please sign in to comment.