NIFI-6403: Adding Elasticsearch7 support to HTTP processors#4153
NIFI-6403: Adding Elasticsearch7 support to HTTP processors#4153gresockj wants to merge 1 commit intoapache:masterfrom
Conversation
|
@gresockj Are you aware of the "REST API Bundle" processors that NiFi has that use the official Elastic REST client? |
ijokarumawak
left a comment
There was a problem hiding this comment.
@gresockj I took a look the changes and left several comments. Please check. Thanks for your contribution!
| .required(false) | ||
| .description("The type of this document (if empty, the first document matching the identifier across all types will be retrieved). " | ||
| + "This must be empty (check 'Set empty string') or '_doc' for Elasticsearch 7.0+.") | ||
| .required(true) |
There was a problem hiding this comment.
Do we need to make it mandatory?? If so, would you elaborate why? I guess ElasticsearchTypeValidator should be enough. Probably you want it to align with other processors. If so, I'd suggest make it optional in all this processor family because ElasticsearchTypeValidator can handle it properly. And users will not have to set empty string.
There was a problem hiding this comment.
I agree this should be optional everywhere and a sensible (cross-ES version) operation/value provided where this is unset, e.g. omit _type from bulk operations, no effect for queries, use _all for GET (Fetch) for backward compatability (users using ES 7+ will need to set this to an appropriate value, e.g. _doc)
| new AllowableValue(ElasticsearchVersion.ES_7.name(), "7.x", "Elasticsearch version 7.x")) | ||
| .defaultValue(ElasticsearchVersion.ES_LESS_THAN_7.name()) | ||
| .addValidator(StandardValidators.NON_EMPTY_VALIDATOR) | ||
| .build(); |
There was a problem hiding this comment.
I understand that using allowable value vs supporting Expression language doesn't go well together, but users would expect this property supports Expression language so that they can change ES versions in different environments. Especially in case they want to upgrade ES while NiFi workflow has lots of processors.
There was a problem hiding this comment.
I'd probably suggest not having this property at all.
Instead, change the processors so that they can support users calling different versions of ES and let ES deal with its own specific logic.
For example, call ES 7 with a type (other than _doc) - it's actually still allowed but is deprecated and is warned about on the ES side (but would recommend not trying to relocate that logic in nifi as it'll be different again in later versions). This also means the change becomes a lot simpler - make _type optional and omit it from relevant ES calls. Maybe add/update documentation where appropriate (e.g. GET needs _doc or _source)
| .required(false) | ||
| .description("The type of this document (if empty, searches across all types). " | ||
| + "This must be empty (check 'Set empty string') or '_doc' for Elasticsearch 7.0+.") | ||
| .required(true) |
There was a problem hiding this comment.
This may not be mandatory. Please see the previous comment.
|
@MikeThomsen it's been a while for me to review NiFi processors.. So please forgive my ignorance . But what did you mean by the "REST API Bundle processors"?? #4153 (comment) |
See processors in https://github.com/apache/nifi/tree/main/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors, which use https://github.com/apache/nifi/tree/main/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-client-service Think these may need updating too, although a quick look suggests that I raised NIFI-8001 to add the ability to specify dynamic properties for query string parameters on the REST API ES processors (as this is something I believe to be missing but useful) NIFI-8002 also to provide a scroll/pit/search_after processor using the REST API ES approach (although users could create this in a flow already with a combination of existing processors, but would need some relatively complex loop logic); and NIFI-8003 to create an _update_by_query (like the existing _delete_by_query) |
| ElasticsearchVersion esVersion = ElasticsearchVersion.valueOf(context | ||
| .getProperty(ES_VERSION).getValue()); | ||
| if (esVersion == ElasticsearchVersion.ES_7) { | ||
| return new ValidationResult.Builder().valid(org.apache.commons.lang3.StringUtils.isBlank(input) || "_doc".equals(input)) |
There was a problem hiding this comment.
_source is also Valid here for ES 7 in a GET document request (i.e. the Fetch processor)
| sb.append("\", \"_type\": \""); | ||
| sb.append(StringEscapeUtils.escapeJson(docType)); | ||
| sb.append("\""); | ||
| if (!(StringUtils.isEmpty(docType) | docType == null)){ |
There was a problem hiding this comment.
Should probably use isBlank rather than isEmpty her and no need for the additional null (also use ||, not |)
Same comment for similar changes before
|
|
||
| protected String getFieldIncludeParameter(ElasticsearchVersion esVersion) { | ||
| return esVersion.equals(ElasticsearchVersion.ES_LESS_THAN_7) | ||
| ? FIELD_INCLUDE_QUERY_PARAM : FIELD_INCLUDE_QUERY_PARAM_ES7; |
There was a problem hiding this comment.
This change was actually added in ES 6, not 7
Suggest simply using _source parameter instead as that's the same for all versions. If users want to use the _source_include(s) (or excludes) parameters instead, they can use dynamic properties on the processors
| ? FIELD_INCLUDE_QUERY_PARAM : FIELD_INCLUDE_QUERY_PARAM_ES7; | ||
| } | ||
|
|
||
| static class ElasticsearchTypeValidator implements Validator { |
There was a problem hiding this comment.
Not needed if the ES version parameter goes away
|
Created PR #4667 to address the above comments, in case the alternate approach is favoured. |
This closes apache#4153. Signed-off-by: Koji Kawamura <ijokarumawak@apache.org>
This closes apache#4153. Signed-off-by: Koji Kawamura <ijokarumawak@apache.org>
Thank you for submitting a contribution to Apache NiFi.
Please provide a short description of the PR here:
Description of PR
Allows Elasticsearch 7 in Elasticsearch HTTP processors.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
For all changes:
Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
Has your PR been rebased against the latest commit within the target branch (typically
master)?[x Is your initial contribution a single, squashed commit? Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not
squashor use--forcewhen pushing to allow for clean monitoring of changes.For code changes:
mvn -Pcontrib-check clean installat the rootnififolder?LICENSEfile, including the mainLICENSEfile undernifi-assembly?NOTICEfile, including the mainNOTICEfile found undernifi-assembly?.displayNamein addition to .name (programmatic access) for each of the new properties?For documentation related changes:
Note:
Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.