ChrisSamo632 commented on a change in pull request #5193:
URL: https://github.com/apache/nifi/pull/5193#discussion_r689363718



##########
File path: 
nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/ConsumeElasticsearch.java
##########
@@ -0,0 +1,194 @@
+/*
+ * 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.processors.elasticsearch;
+
+import org.apache.nifi.annotation.behavior.InputRequirement;
+import org.apache.nifi.annotation.behavior.Stateful;
+import org.apache.nifi.annotation.behavior.SystemResource;
+import org.apache.nifi.annotation.behavior.SystemResourceConsideration;
+import org.apache.nifi.annotation.behavior.TriggerSerially;
+import org.apache.nifi.annotation.behavior.WritesAttribute;
+import org.apache.nifi.annotation.behavior.WritesAttributes;
+import org.apache.nifi.annotation.configuration.DefaultSchedule;
+import org.apache.nifi.annotation.documentation.CapabilityDescription;
+import org.apache.nifi.annotation.documentation.Tags;
+import org.apache.nifi.components.PropertyDescriptor;
+import org.apache.nifi.components.state.Scope;
+import org.apache.nifi.components.state.StateMap;
+import org.apache.nifi.elasticsearch.SearchResponse;
+import org.apache.nifi.expression.ExpressionLanguageScope;
+import org.apache.nifi.flowfile.FlowFile;
+import org.apache.nifi.processor.ProcessContext;
+import org.apache.nifi.processor.ProcessSession;
+import org.apache.nifi.processor.Relationship;
+import 
org.apache.nifi.processors.elasticsearch.api.PaginatedJsonQueryParameters;
+import org.apache.nifi.util.StringUtils;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+@WritesAttributes({
+    @WritesAttribute(attribute = "mime.type", description = 
"application/json"),
+    @WritesAttribute(attribute = "aggregation.name", description = "The name 
of the aggregation whose results are in the output flowfile"),
+    @WritesAttribute(attribute = "aggregation.number", description = "The 
number of the aggregation whose results are in the output flowfile"),
+    @WritesAttribute(attribute = "page.number", description = "The number of 
the page (request) in which the results were returned that are in the output 
flowfile"),
+    @WritesAttribute(attribute = "hit.count", description = "The number of 
hits that are in the output flowfile")
+})
+@InputRequirement(InputRequirement.Requirement.INPUT_FORBIDDEN)
+@TriggerSerially
+@DefaultSchedule(period="1 min")
+@Tags({"elasticsearch", "elasticsearch 5", "query", "scroll", "page", 
"consume", "json"})
+@CapabilityDescription("A processor that allows the user to repeatedly run a 
paginated query (with aggregations) written with the Elasticsearch JSON DSL. " +
+        "Search After/Point in Time queries must include a valid \"sort\" 
field.")
+@Stateful(scopes = Scope.LOCAL, description = "The pagination state (scrollId, 
searchAfter, pitId, hitCount, pageCount, expirationTimestamp) " +
+        "is retained in between invocations of this processor until the 
Scroll/PiT has expired " +
+        "(when the current time is later than the last query execution plus 
the Pagination Keep Alive interval).")
+@SystemResourceConsideration(resource = SystemResource.MEMORY, description = 
"Care should be taken on the size of each page because each response " +
+        "from Elasticsearch will be loaded into memory all at once and 
converted into the resulting flowfiles.")
+public class ConsumeElasticsearch extends 
AbstractPaginatedJsonQueryElasticsearch implements ElasticsearchRestProcessor {

Review comment:
       [NIFI-9050](https://issues.apache.org/jira/browse/NIFI-9050) raised to 
cover a possible issue discovered with using the `ProcessSession#*State` 
methods in place of `ProcessContext#getStateManager#*State` (introduced via 
NIFI-8136).
   
   I think this was a timing issue with using the ProcessSession State methods 
- AbstractProcessor uses `commitAsync` (not `commit`) and the quick (1 sec) 
sceduling of the processor used here meant that the State hadn't actually been 
persisted and thus the processor was doing the wrong thing when determining 
which page of data to try and obtain, etc.
   
   Also, there was no need to log an ERROR/WARNING for the fact that a 
{{deleteScroll}}/{{deletePointInTime}} function had been called with an Id that 
no longer existed in Elasticsearch (e.g. after an old query had expired then 
the processor restarted). In fact there's no need to try and delete should 
resources from Elasticsearch because it does that itself automatically, instead 
we should just delete them after we know there's no more data to be pulled from 
Elasticsearch (but the Scroll/PiT are still active within Elasticsearch).
   
   
   ... changes made and pushed.




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to