You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "vjgorla (via GitHub)" <gi...@apache.org> on 2025/03/16 10:41:23 UTC

[PR] NIFI-10304 Added a config item to SearchElasticsearch processor to control if the processor restarts on query finish. Also removed query expiration for SEARCH_AFTER pagination type [nifi]

vjgorla opened a new pull request, #9806:
URL: https://github.com/apache/nifi/pull/9806

   <!-- 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. -->
   
   # Summary
   
   [NIFI-10304](https://issues.apache.org/jira/browse/NIFI-10304)
   
   # Tracking
   
   Please complete the following tracking steps prior to pull request creation.
   
   ### Issue Tracking
   
   - [x] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI-10304) issue created
   
   ### Pull Request Tracking
   
   - [x] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
   - [x] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
   
   ### Pull Request Formatting
   
   - [x] Pull Request based on current revision of the `main` branch
   - [x] Pull Request refers to a feature branch with one commit containing changes
   
   # Verification
   
   Please indicate the verification steps performed prior to pull request creation.
   
   ### Build
   
   - [x] Build completed using `mvn clean install -P contrib-check`
   - [x] JDK 21
   
   ### Licensing
   
   - [x] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
   - [x] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
   
   ### Documentation
   
   - [x] Documentation formatting appears as expected in rendered files
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [NIFI-10304] [NIFI-14351] Added a config item to SearchElasticsearch processor to control if the processor restarts on query finish. Also removed query expiration for SEARCH_AFTER pagination type [nifi]

Posted by "ChrisSamo632 (via GitHub)" <gi...@apache.org>.
ChrisSamo632 commented on code in PR #9806:
URL: https://github.com/apache/nifi/pull/9806#discussion_r1999263953


##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/SearchElasticsearch.java:
##########
@@ -88,26 +90,40 @@ public class SearchElasticsearch extends AbstractPaginatedJsonQueryElasticsearch
     static final String STATE_PAGE_EXPIRATION_TIMESTAMP = "pageExpirationTimestamp";
     static final String STATE_PAGE_COUNT = "pageCount";
     static final String STATE_HIT_COUNT = "hitCount";
+    static final String STATE_FINISHED = "finished";
 
     static final PropertyDescriptor QUERY = new PropertyDescriptor.Builder().fromPropertyDescriptor(ElasticsearchRestProcessor.QUERY)
             .description("A query in JSON syntax, not Lucene syntax. Ex: {\"query\":{\"match\":{\"somefield\":\"somevalue\"}}}. " +
                     "If the query is empty, a default JSON Object will be used, which will result in a \"match_all\" query in Elasticsearch.")
             .build();
 
-    private static final Set<Relationship> relationships = Set.of(REL_HITS, REL_AGGREGATIONS);
+    static final PropertyDescriptor RESTART_ON_FINISH = new PropertyDescriptor.Builder()

Review Comment:
   `ConsumeElasticsearch` already satisfies this use case I think, is this additional property and logic achieving anything different?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [NIFI-10304] [NIFI-14351] Added a config item to SearchElasticsearch processor to control if the processor restarts on query finish. Also removed query expiration for SEARCH_AFTER pagination type [nifi]

Posted by "vjgorla (via GitHub)" <gi...@apache.org>.
vjgorla commented on code in PR #9806:
URL: https://github.com/apache/nifi/pull/9806#discussion_r1999932538


##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/SearchElasticsearch.java:
##########
@@ -88,26 +90,40 @@ public class SearchElasticsearch extends AbstractPaginatedJsonQueryElasticsearch
     static final String STATE_PAGE_EXPIRATION_TIMESTAMP = "pageExpirationTimestamp";
     static final String STATE_PAGE_COUNT = "pageCount";
     static final String STATE_HIT_COUNT = "hitCount";
+    static final String STATE_FINISHED = "finished";
 
     static final PropertyDescriptor QUERY = new PropertyDescriptor.Builder().fromPropertyDescriptor(ElasticsearchRestProcessor.QUERY)
             .description("A query in JSON syntax, not Lucene syntax. Ex: {\"query\":{\"match\":{\"somefield\":\"somevalue\"}}}. " +
                     "If the query is empty, a default JSON Object will be used, which will result in a \"match_all\" query in Elasticsearch.")
             .build();
 
-    private static final Set<Relationship> relationships = Set.of(REL_HITS, REL_AGGREGATIONS);
+    static final PropertyDescriptor RESTART_ON_FINISH = new PropertyDescriptor.Builder()

Review Comment:
   The use case is when you know that query will not match any new data once it reaches the end of the result set (e.g. reading all logs from yesterday). Problem with using `ConsumeElasticsearch` for this use case is
   
   * Having to provide an additional range field
   * Elastic API calls would continue to be made even after reaching the end of the result set, putting load on elastic
   * Processor does not yield after reaching the end of the result set, putting load on NiFi
   
   On a separate note, `ConsumeElasticsearch` requires range field to have unique values. It should support multiple fields, one of them a tie breaker, similar to `search_after`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [NIFI-10304] [NIFI-14351] Added a config item to SearchElasticsearch processor to control if the processor restarts on query finish. Also removed query expiration for SEARCH_AFTER pagination type [nifi]

Posted by "ChrisSamo632 (via GitHub)" <gi...@apache.org>.
ChrisSamo632 commented on code in PR #9806:
URL: https://github.com/apache/nifi/pull/9806#discussion_r2029933465


##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/SearchElasticsearch.java:
##########
@@ -88,26 +90,40 @@ public class SearchElasticsearch extends AbstractPaginatedJsonQueryElasticsearch
     static final String STATE_PAGE_EXPIRATION_TIMESTAMP = "pageExpirationTimestamp";
     static final String STATE_PAGE_COUNT = "pageCount";
     static final String STATE_HIT_COUNT = "hitCount";
+    static final String STATE_FINISHED = "finished";
 
     static final PropertyDescriptor QUERY = new PropertyDescriptor.Builder().fromPropertyDescriptor(ElasticsearchRestProcessor.QUERY)
             .description("A query in JSON syntax, not Lucene syntax. Ex: {\"query\":{\"match\":{\"somefield\":\"somevalue\"}}}. " +
                     "If the query is empty, a default JSON Object will be used, which will result in a \"match_all\" query in Elasticsearch.")
             .build();
 
-    private static final Set<Relationship> relationships = Set.of(REL_HITS, REL_AGGREGATIONS);
+    static final PropertyDescriptor RESTART_ON_FINISH = new PropertyDescriptor.Builder()

Review Comment:
   @vjgorla thanks for the clarification and thoughtful comment.
   
   I will endeavour to review this properly soon, unless someone else beats me to it
   
   Could you, however, follow the PR template/guidelines and rebase this branch to a single initial commit, as it makes the review & merge process simpler?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [NIFI-10304] [NIFI-14351] Added a config item to SearchElasticsearch processor to control if the processor restarts on query finish. Also removed query expiration for SEARCH_AFTER pagination type [nifi]

Posted by "ChrisSamo632 (via GitHub)" <gi...@apache.org>.
ChrisSamo632 commented on PR #9806:
URL: https://github.com/apache/nifi/pull/9806#issuecomment-2785590220

   Thanks for applying the suggested changes @vjgorla.
   
   Can you `rebase` the branch to avoid having `merge` commits please, as it will make it a lot easier to contribute this back to `main` then?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [NIFI-10304] [NIFI-14351] Added a config item to SearchElasticsearch processor to control if the processor restarts on query finish. Also removed query expiration for SEARCH_AFTER pagination type [nifi]

Posted by "ChrisSamo632 (via GitHub)" <gi...@apache.org>.
ChrisSamo632 commented on code in PR #9806:
URL: https://github.com/apache/nifi/pull/9806#discussion_r2029933465


##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/SearchElasticsearch.java:
##########
@@ -88,26 +90,40 @@ public class SearchElasticsearch extends AbstractPaginatedJsonQueryElasticsearch
     static final String STATE_PAGE_EXPIRATION_TIMESTAMP = "pageExpirationTimestamp";
     static final String STATE_PAGE_COUNT = "pageCount";
     static final String STATE_HIT_COUNT = "hitCount";
+    static final String STATE_FINISHED = "finished";
 
     static final PropertyDescriptor QUERY = new PropertyDescriptor.Builder().fromPropertyDescriptor(ElasticsearchRestProcessor.QUERY)
             .description("A query in JSON syntax, not Lucene syntax. Ex: {\"query\":{\"match\":{\"somefield\":\"somevalue\"}}}. " +
                     "If the query is empty, a default JSON Object will be used, which will result in a \"match_all\" query in Elasticsearch.")
             .build();
 
-    private static final Set<Relationship> relationships = Set.of(REL_HITS, REL_AGGREGATIONS);
+    static final PropertyDescriptor RESTART_ON_FINISH = new PropertyDescriptor.Builder()

Review Comment:
   @vjgorla thanks for the clarification and thoughtful comment.
   
   I will endeavour to review this properly soon, unless someone else beats me to it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [NIFI-10304] [NIFI-14351] Added a config item to SearchElasticsearch processor to control if the processor restarts on query finish. Also removed query expiration for SEARCH_AFTER pagination type [nifi]

Posted by "ChrisSamo632 (via GitHub)" <gi...@apache.org>.
ChrisSamo632 commented on code in PR #9806:
URL: https://github.com/apache/nifi/pull/9806#discussion_r2031824343


##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/SearchElasticsearch.java:
##########
@@ -122,17 +138,34 @@ Scope getStateScope() {
         return Scope.LOCAL;
     }
 
+    @Override
+    @OnScheduled
+    public void onScheduled(final ProcessContext context) {
+        super.onScheduled(context);
+        if (context.getProperty(RESTART_ON_FINISH).asBoolean() != null) {

Review Comment:
   ```suggestion
           if (context.getProperty(RESTART_ON_FINISH) != null) {
   ```
   
   No need for the type conversion for a null check



##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/SearchElasticsearch.java:
##########
@@ -88,26 +90,40 @@ public class SearchElasticsearch extends AbstractPaginatedJsonQueryElasticsearch
     static final String STATE_PAGE_EXPIRATION_TIMESTAMP = "pageExpirationTimestamp";
     static final String STATE_PAGE_COUNT = "pageCount";
     static final String STATE_HIT_COUNT = "hitCount";
+    static final String STATE_FINISHED = "finished";
 
     static final PropertyDescriptor QUERY = new PropertyDescriptor.Builder().fromPropertyDescriptor(ElasticsearchRestProcessor.QUERY)
             .description("A query in JSON syntax, not Lucene syntax. Ex: {\"query\":{\"match\":{\"somefield\":\"somevalue\"}}}. " +
                     "If the query is empty, a default JSON Object will be used, which will result in a \"match_all\" query in Elasticsearch.")
             .build();
 
-    private static final Set<Relationship> relationships = Set.of(REL_HITS, REL_AGGREGATIONS);
+    static final PropertyDescriptor RESTART_ON_FINISH = new PropertyDescriptor.Builder()
+            .name("restart-on-finish")
+            .displayName("Restart On Finish?")
+            .description("Should the processor start from the beginning when the query finishes?")

Review Comment:
   ```suggestion
               .description("Whether the should processor start another search with the same query once a paginated search has completed.")
   ```
   
   Property Descriptors aren't usually written as questions



##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/SearchElasticsearch.java:
##########
@@ -88,26 +90,40 @@ public class SearchElasticsearch extends AbstractPaginatedJsonQueryElasticsearch
     static final String STATE_PAGE_EXPIRATION_TIMESTAMP = "pageExpirationTimestamp";
     static final String STATE_PAGE_COUNT = "pageCount";
     static final String STATE_HIT_COUNT = "hitCount";
+    static final String STATE_FINISHED = "finished";
 
     static final PropertyDescriptor QUERY = new PropertyDescriptor.Builder().fromPropertyDescriptor(ElasticsearchRestProcessor.QUERY)
             .description("A query in JSON syntax, not Lucene syntax. Ex: {\"query\":{\"match\":{\"somefield\":\"somevalue\"}}}. " +
                     "If the query is empty, a default JSON Object will be used, which will result in a \"match_all\" query in Elasticsearch.")
             .build();
 
-    private static final Set<Relationship> relationships = Set.of(REL_HITS, REL_AGGREGATIONS);
+    static final PropertyDescriptor RESTART_ON_FINISH = new PropertyDescriptor.Builder()
+            .name("restart-on-finish")
+            .displayName("Restart On Finish?")
+            .description("Should the processor start from the beginning when the query finishes?")
+            .addValidator(StandardValidators.BOOLEAN_VALIDATOR)
+            .allowableValues(Boolean.TRUE.toString(), Boolean.FALSE.toString())
+            .defaultValue(Boolean.TRUE.toString()) // maintain existing behavior

Review Comment:
   ```suggestion
               .defaultValue(Boolean.TRUE.toString())
   ```
   
   While this comment is helpful in terms of a PR, I don't think it's useful for the future, the field setting is self-ecident



##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/SearchElasticsearch.java:
##########
@@ -122,17 +138,34 @@ Scope getStateScope() {
         return Scope.LOCAL;
     }
 
+    @Override
+    @OnScheduled
+    public void onScheduled(final ProcessContext context) {
+        super.onScheduled(context);
+        if (context.getProperty(RESTART_ON_FINISH).asBoolean() != null) {
+            this.restartOnFinish = context.getProperty(RESTART_ON_FINISH).asBoolean();
+        }
+    }
+
     @Override
     PaginatedJsonQueryParameters buildJsonQueryParameters(final FlowFile input, final ProcessContext context, final ProcessSession session) throws IOException {
+        final StateMap stateMap = context.getStateManager().getState(getStateScope());
+
+        final boolean finished = stateMap.get(STATE_FINISHED) == null ? false : Boolean.parseBoolean(stateMap.get(STATE_FINISHED));

Review Comment:
   ```suggestion
           final boolean finished = stateMap.get(STATE_FINISHED) != null && Boolean.parseBoolean(stateMap.get(STATE_FINISHED))
   ```
   
   Boolean logic can be simplified



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [NIFI-10304] [NIFI-14351] Added a config item to SearchElasticsearch processor to control if the processor restarts on query finish. Also removed query expiration for SEARCH_AFTER pagination type [nifi]

Posted by "asfgit (via GitHub)" <gi...@apache.org>.
asfgit closed pull request #9806: [NIFI-10304] [NIFI-14351] Added a config item to SearchElasticsearch processor to control if the processor restarts on query finish. Also removed query expiration for SEARCH_AFTER pagination type
URL: https://github.com/apache/nifi/pull/9806


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org