You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "agturley (via GitHub)" <gi...@apache.org> on 2026/05/31 22:16:39 UTC

[PR] NIFI-15985 - Add per-document Index Field and Timestamp Field extraction to PutElasticsearchJson [nifi]

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

   <!-- 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-15985](https://issues.apache.org/jira/browse/NIFI-15985)
   
   # Tracking
   
   Please complete the following tracking steps prior to pull request creation.
   
   ### Issue Tracking
   
   - [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
   
   ### Pull Request Tracking
   
   - Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
   - Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
   - Pull request contains [commits signed](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) with a registered key indicating `Verified` status
   
   ### Pull Request Formatting
   
   - Pull Request based on current revision of the `main` branch
   - 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 `./mvnw clean install -P contrib-check`
     - [x] JDK 21
     - [ ] JDK 25
   
   ### 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-15985 - Add per-document Index Field and Timestamp Field extraction to PutElasticsearchJson [nifi]

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


##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchJson.java:
##########
@@ -245,6 +249,67 @@ public class PutElasticsearchJson extends AbstractPutElasticsearch {
             .dependsOn(INPUT_FORMAT, InputFormat.NDJSON, InputFormat.JSON_ARRAY)
             .build();
 
+    static final PropertyDescriptor RETAIN_IDENTIFIER_FIELD = new PropertyDescriptor.Builder()
+            .name("Retain Identifier Field")
+            .description("""
+                    Whether to keep the Identifier Field in the document body after extracting it \
+                    for use as the Elasticsearch document ID. \
+                    When false (default), the field is removed from the document before indexing.\
+                    """)
+            .required(true)
+            .allowableValues("true", "false")
+            .defaultValue("false")

Review Comment:
   agreed, switched them all to default to true for consistency as well.



-- 
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-15985 - Add per-document Index Field and Timestamp Field extraction to PutElasticsearchJson [nifi]

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


##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchJson.java:
##########
@@ -931,6 +1131,41 @@ private String resolveId(final Map<String, Object> contentMap, final String idAt
         return StringUtils.isNotBlank(flowFileIdAttribute) ? flowFileIdAttribute : null;
     }
 
+    /**
+     * Extracts the index name from a pre-parsed {@link JsonNode}.
+     * Used for JSON Array Index/Create operations where the node is already available.
+     * Falls back to {@code fallbackIndex} when the field is absent or blank.
+     */
+    private String extractIndex(final JsonNode node, final String indexField, final String fallbackIndex) {
+        if (StringUtils.isBlank(indexField)) {
+            return fallbackIndex;
+        }
+        final JsonNode indexNode = node.get(indexField);
+        if (indexNode != null && !indexNode.isNull()) {
+            final String value = indexNode.asText();
+            return StringUtils.isNotBlank(value) ? value : fallbackIndex;
+        }
+        return fallbackIndex;
+    }
+
+    /**
+     * Resolves the index name from an already-parsed content Map.
+     * Used for Update/Delete/Upsert operations and suppression-enabled Index/Create paths
+     * where the Map is already available. Falls back to {@code fallbackIndex} when the
+     * field is absent or blank.
+     */
+    private String resolveIndex(final Map<String, Object> contentMap, final String indexField, final String fallbackIndex) {
+        if (StringUtils.isBlank(indexField)) {
+            return fallbackIndex;
+        }
+        final Object indexObj = contentMap.get(indexField);
+        if (indexObj != null) {
+            final String value = indexObj.toString();

Review Comment:
   They match for normal strings but I found an actual bug while looking - if the field value is null, the NDJSON path was using the literal string "null" as the index, while the other two paths fell back correctly. Pulled all the id/index extraction through a couple of shared helpers so they behave the same: scalars use their text value, null/objects/arrays fall back. Added a couple tests for a numeric value and a null value to cover 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-15985 - Add per-document Index Field and Timestamp Field extraction to PutElasticsearchJson [nifi]

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


##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchJson.java:
##########
@@ -245,6 +249,67 @@ public class PutElasticsearchJson extends AbstractPutElasticsearch {
             .dependsOn(INPUT_FORMAT, InputFormat.NDJSON, InputFormat.JSON_ARRAY)
             .build();
 
+    static final PropertyDescriptor RETAIN_IDENTIFIER_FIELD = new PropertyDescriptor.Builder()
+            .name("Retain Identifier Field")
+            .description("""
+                    Whether to keep the Identifier Field in the document body after extracting it \
+                    for use as the Elasticsearch document ID. \
+                    When false (default), the field is removed from the document before indexing.\
+                    """)
+            .required(true)
+            .allowableValues("true", "false")
+            .defaultValue("false")

Review Comment:
   Today the Identifier Field is kept in the indexed document. Should Retain Identifier Field default to true so existing flows keep the same document shape after upgrade?



##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchJson.java:
##########
@@ -245,6 +249,67 @@ public class PutElasticsearchJson extends AbstractPutElasticsearch {
             .dependsOn(INPUT_FORMAT, InputFormat.NDJSON, InputFormat.JSON_ARRAY)
             .build();
 
+    static final PropertyDescriptor RETAIN_IDENTIFIER_FIELD = new PropertyDescriptor.Builder()
+            .name("Retain Identifier Field")
+            .description("""
+                    Whether to keep the Identifier Field in the document body after extracting it \
+                    for use as the Elasticsearch document ID. \
+                    When false (default), the field is removed from the document before indexing.\
+                    """)
+            .required(true)
+            .allowableValues("true", "false")
+            .defaultValue("false")
+            .dependsOn(INPUT_FORMAT, InputFormat.NDJSON, InputFormat.JSON_ARRAY)
+            .build();
+
+    static final PropertyDescriptor INDEX_FIELD = new PropertyDescriptor.Builder()
+            .name("Index Field")
+            .description("""
+                    The name of the field within each document to use as the Elasticsearch index name. \
+                    If the field is not present in a document or this property is left blank, \
+                    the configured Index property value is used as the fallback.\
+                    """)
+            .required(false)
+            .expressionLanguageSupported(ExpressionLanguageScope.ENVIRONMENT)
+            .addValidator(StandardValidators.NON_BLANK_VALIDATOR)
+            .build();
+
+    static final PropertyDescriptor RETAIN_INDEX_FIELD = new PropertyDescriptor.Builder()
+            .name("Retain Index Field")
+            .description("""
+                    Whether to keep the Index Field in the document body after extracting it \
+                    for use as the Elasticsearch index name. \
+                    When false (default), the field is removed from the document before indexing.\
+                    """)
+            .required(true)
+            .allowableValues("true", "false")
+            .defaultValue("false")
+            .build();

Review Comment:
   Should Retain Index Field use dependsOn(INDEX_FIELD), and Retain Timestamp Field use dependsOn(TIMESTAMP_FIELD), so the toggle is hidden when no source field is set?



##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchJson.java:
##########
@@ -931,6 +1131,41 @@ private String resolveId(final Map<String, Object> contentMap, final String idAt
         return StringUtils.isNotBlank(flowFileIdAttribute) ? flowFileIdAttribute : null;
     }
 
+    /**
+     * Extracts the index name from a pre-parsed {@link JsonNode}.
+     * Used for JSON Array Index/Create operations where the node is already available.
+     * Falls back to {@code fallbackIndex} when the field is absent or blank.
+     */
+    private String extractIndex(final JsonNode node, final String indexField, final String fallbackIndex) {
+        if (StringUtils.isBlank(indexField)) {
+            return fallbackIndex;
+        }
+        final JsonNode indexNode = node.get(indexField);
+        if (indexNode != null && !indexNode.isNull()) {
+            final String value = indexNode.asText();
+            return StringUtils.isNotBlank(value) ? value : fallbackIndex;
+        }
+        return fallbackIndex;
+    }
+
+    /**
+     * Resolves the index name from an already-parsed content Map.
+     * Used for Update/Delete/Upsert operations and suppression-enabled Index/Create paths
+     * where the Map is already available. Falls back to {@code fallbackIndex} when the
+     * field is absent or blank.
+     */
+    private String resolveIndex(final Map<String, Object> contentMap, final String indexField, final String fallbackIndex) {
+        if (StringUtils.isBlank(indexField)) {
+            return fallbackIndex;
+        }
+        final Object indexObj = contentMap.get(indexField);
+        if (indexObj != null) {
+            final String value = indexObj.toString();

Review Comment:
   resolveIndex uses toString() while extractIndex uses asText(). Could a non-string index field value produce a different index name between the Map path and the JsonNode path?



##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchJson.java:
##########
@@ -450,17 +526,36 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
                             final IndexOperationRequest opRequest;
                             final long docBytes;
                             if (o == IndexOperationRequest.Operation.Index || o == IndexOperationRequest.Operation.Create) {
-                                final String id = extractId(trimmedLine, documentIdField, flowFileIdAttribute);
                                 final byte[] rawJsonBytes;
-                                if (suppressingWriter != null) {
-                                    // Parse to Map so NON_NULL/NON_EMPTY inclusion filters apply during serialization.
-                                    // JsonNode tree serialization bypasses JsonInclude filters.
-                                    rawJsonBytes = suppressingWriter.writeValueAsBytes(mapReader.readValue(trimmedLine));
+                                final String id;
+                                final String docIndex;
+                                final boolean stripId = !retainIdentifierField && StringUtils.isNotBlank(documentIdField);
+                                final boolean stripIdx = !retainIndexField && StringUtils.isNotBlank(documentIndexField);
+                                final boolean needsTimestamp = StringUtils.isNotBlank(documentTimestampField);
+                                if (suppressingWriter != null || stripId || stripIdx || needsTimestamp) {
+                                    // Map is needed anyway — extract both fields from the Map directly.
+                                    final Map<String, Object> contentMap = mapReader.readValue(trimmedLine);
+                                    id = resolveId(contentMap, documentIdField, flowFileIdAttribute);
+                                    docIndex = resolveIndex(contentMap, documentIndexField, index);
+                                    if (stripId) {
+                                        contentMap.remove(documentIdField);
+                                    }
+                                    if (stripIdx) {
+                                        contentMap.remove(documentIndexField);
+                                    }
+                                    applyTimestamp(contentMap, documentTimestampField, retainTimestampField);

Review Comment:
   Can we add PutElasticsearchJsonTest coverage for the new Index Field, Timestamp Field, and the three Retain toggles across NDJSON, JSON Array, and Single JSON, so the extraction and field stripping behavior is locked in?



-- 
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-15985 - Add per-document Index Field and Timestamp Field extraction to PutElasticsearchJson [nifi]

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


##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchJson.java:
##########
@@ -245,6 +249,67 @@ public class PutElasticsearchJson extends AbstractPutElasticsearch {
             .dependsOn(INPUT_FORMAT, InputFormat.NDJSON, InputFormat.JSON_ARRAY)
             .build();
 
+    static final PropertyDescriptor RETAIN_IDENTIFIER_FIELD = new PropertyDescriptor.Builder()
+            .name("Retain Identifier Field")
+            .description("""
+                    Whether to keep the Identifier Field in the document body after extracting it \
+                    for use as the Elasticsearch document ID. \
+                    When false (default), the field is removed from the document before indexing.\
+                    """)
+            .required(true)
+            .allowableValues("true", "false")
+            .defaultValue("false")
+            .dependsOn(INPUT_FORMAT, InputFormat.NDJSON, InputFormat.JSON_ARRAY)
+            .build();
+
+    static final PropertyDescriptor INDEX_FIELD = new PropertyDescriptor.Builder()
+            .name("Index Field")
+            .description("""
+                    The name of the field within each document to use as the Elasticsearch index name. \
+                    If the field is not present in a document or this property is left blank, \
+                    the configured Index property value is used as the fallback.\
+                    """)
+            .required(false)
+            .expressionLanguageSupported(ExpressionLanguageScope.ENVIRONMENT)
+            .addValidator(StandardValidators.NON_BLANK_VALIDATOR)
+            .build();
+
+    static final PropertyDescriptor RETAIN_INDEX_FIELD = new PropertyDescriptor.Builder()
+            .name("Retain Index Field")
+            .description("""
+                    Whether to keep the Index Field in the document body after extracting it \
+                    for use as the Elasticsearch index name. \
+                    When false (default), the field is removed from the document before indexing.\
+                    """)
+            .required(true)
+            .allowableValues("true", "false")
+            .defaultValue("false")
+            .build();

Review Comment:
   Added. Each retain flag now depends on its field, so they're hidden until you set the field. Turned out onTrigger was also reading those properties even when the field wasn't set, which isn't allowed once a dependsOn is in place, so I fixed those reads too.



-- 
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-15985 - Add per-document Index Field and Timestamp Field extraction to PutElasticsearchJson [nifi]

Posted by "pvillard31 (via GitHub)" <gi...@apache.org>.
pvillard31 merged PR #11299:
URL: https://github.com/apache/nifi/pull/11299


-- 
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-15985 - Add per-document Index Field and Timestamp Field extraction to PutElasticsearchJson [nifi]

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


##########
nifi-extension-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchJson.java:
##########
@@ -450,17 +526,36 @@ public void onTrigger(final ProcessContext context, final ProcessSession session
                             final IndexOperationRequest opRequest;
                             final long docBytes;
                             if (o == IndexOperationRequest.Operation.Index || o == IndexOperationRequest.Operation.Create) {
-                                final String id = extractId(trimmedLine, documentIdField, flowFileIdAttribute);
                                 final byte[] rawJsonBytes;
-                                if (suppressingWriter != null) {
-                                    // Parse to Map so NON_NULL/NON_EMPTY inclusion filters apply during serialization.
-                                    // JsonNode tree serialization bypasses JsonInclude filters.
-                                    rawJsonBytes = suppressingWriter.writeValueAsBytes(mapReader.readValue(trimmedLine));
+                                final String id;
+                                final String docIndex;
+                                final boolean stripId = !retainIdentifierField && StringUtils.isNotBlank(documentIdField);
+                                final boolean stripIdx = !retainIndexField && StringUtils.isNotBlank(documentIndexField);
+                                final boolean needsTimestamp = StringUtils.isNotBlank(documentTimestampField);
+                                if (suppressingWriter != null || stripId || stripIdx || needsTimestamp) {
+                                    // Map is needed anyway — extract both fields from the Map directly.
+                                    final Map<String, Object> contentMap = mapReader.readValue(trimmedLine);
+                                    id = resolveId(contentMap, documentIdField, flowFileIdAttribute);
+                                    docIndex = resolveIndex(contentMap, documentIndexField, index);
+                                    if (stripId) {
+                                        contentMap.remove(documentIdField);
+                                    }
+                                    if (stripIdx) {
+                                        contentMap.remove(documentIndexField);
+                                    }
+                                    applyTimestamp(contentMap, documentTimestampField, retainTimestampField);

Review Comment:
   Added unit tests covering Index Field, Timestamp Field, and all three Retain toggles across NDJSON, JSON Array, and Single JSON — extraction, retain-by-default, stripping when Retain=false, and fallback to the Index property when the field is absent.



-- 
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-15985 - Add per-document Index Field and Timestamp Field extraction to PutElasticsearchJson [nifi]

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

   Latest LGTM but you need to rebase on top of main for Github checks to execute


-- 
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