This is an automated email from the ASF dual-hosted git repository.
kdoran pushed a commit to branch support/nifi-1.x
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/support/nifi-1.x by this push:
new 63bb245a2a NIFI-11274 only add @timestamp to PutElasticsearchRecord
document if not null
63bb245a2a is described below
commit 63bb245a2a9512fd28677e85d49754d3754565a3
Author: Chris Sampson <[email protected]>
AuthorDate: Mon Mar 13 14:08:14 2023 +0000
NIFI-11274 only add @timestamp to PutElasticsearchRecord document if not
null
This closes #7036.
Signed-off-by: Kevin Doran <[email protected]>
---
.../nifi/processors/elasticsearch/PutElasticsearchRecord.java | 4 +++-
.../processors/elasticsearch/PutElasticsearchRecordTest.groovy | 9 ++++-----
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git
a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchRecord.java
b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchRecord.java
index 2b682c2c24..d70a615915 100644
---
a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchRecord.java
+++
b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/main/java/org/apache/nifi/processors/elasticsearch/PutElasticsearchRecord.java
@@ -373,7 +373,9 @@ public class PutElasticsearchRecord extends
AbstractPutElasticsearch {
final Map<String, Object> contentMap = (Map<String, Object>)
DataTypeUtils
.convertRecordFieldtoObject(record,
RecordFieldType.RECORD.getRecordDataType(record.getSchema()));
formatDateTimeFields(contentMap, record);
- contentMap.putIfAbsent("@timestamp", timestamp);
+ if (timestamp != null) {
+ contentMap.putIfAbsent("@timestamp", timestamp);
+ }
operationList.add(new IndexOperationRequest(idx, t, id,
contentMap, o));
originals.add(record);
diff --git
a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/groovy/org/apache/nifi/processors/elasticsearch/PutElasticsearchRecordTest.groovy
b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/groovy/org/apache/nifi/processors/elasticsearch/PutElasticsearchRecordTest.groovy
index 3c0426023a..5e976a31d3 100644
---
a/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/groovy/org/apache/nifi/processors/elasticsearch/PutElasticsearchRecordTest.groovy
+++
b/nifi-nar-bundles/nifi-elasticsearch-bundle/nifi-elasticsearch-restapi-processors/src/test/groovy/org/apache/nifi/processors/elasticsearch/PutElasticsearchRecordTest.groovy
@@ -30,7 +30,6 @@ import org.apache.nifi.serialization.RecordReaderFactory
import org.apache.nifi.serialization.record.MockRecordParser
import org.apache.nifi.serialization.record.MockSchemaRegistry
import org.apache.nifi.serialization.record.RecordFieldType
-import org.apache.nifi.util.MockFlowFile
import org.apache.nifi.util.StringUtils
import org.apache.nifi.util.TestRunner
import org.apache.nifi.util.TestRunners
@@ -425,7 +424,7 @@ class PutElasticsearchRecordTest {
[ id: "rec-2", op: "create", index: "bulk_b", type: "message",
msg: "Hello" ],
[ id: "rec-3", op: "update", index: "bulk_a", type: "message",
msg: "Hello" ],
[ id: "rec-4", op: "upsert", index: "bulk_b", type: "message",
msg: "Hello" ],
- [ id: "rec-5", op: "create", index: "bulk_a", type: "message",
msg: "Hello" ],
+ [ id: "rec-5", op: "create", index: "bulk_a", type: "message",
msg: "Hello", code: null ],
[ id: "rec-6", op: "delete", index: "bulk_b", type: "message",
msg: "Hello", code: 101L ]
]))
@@ -436,7 +435,7 @@ class PutElasticsearchRecordTest {
int upsert = items.findAll { it.operation ==
IndexOperationRequest.Operation.Upsert }.size()
int delete = items.findAll { it.operation ==
IndexOperationRequest.Operation.Delete }.size()
def timestampCount = items.findAll { it.fields.get("@timestamp")
== 101L }.size()
- def noTimestampCount = items.findAll { it.fields.get("@timestamp")
== null }.size()
+ def noTimestampCount = items.findAll {
!it.fields.containsKey("@timestamp") }.size()
assertEquals(1, index)
assertEquals(2, create)
assertEquals(1, update)
@@ -487,7 +486,7 @@ class PutElasticsearchRecordTest {
clientService.evalClosure = { List<IndexOperationRequest> items ->
def nullIdCount = items.findAll { it.id == null }.size()
- def noTimestampCount = items.findAll {
it.fields.containsKey("@timestamp") }.size()
+ def noTimestampCount = items.findAll {
!it.fields.containsKey("@timestamp") }.size()
assertEquals(1, nullIdCount)
assertEquals(1, noTimestampCount)
}
@@ -512,7 +511,7 @@ class PutElasticsearchRecordTest {
clientService.evalClosure = { List<IndexOperationRequest> items ->
def nullIdCount = items.findAll { it.id == null }.size()
- def noTimestampCount = items.findAll {
it.fields.containsKey("@timestamp") }.size()
+ def noTimestampCount = items.findAll {
!it.fields.containsKey("@timestamp") }.size()
assertEquals(1, nullIdCount)
assertEquals(1, noTimestampCount)
}