mirror of https://github.com/apache/nifi.git
NIFI-5500 Adding support for array fields when outputting to attributes when using QueryElasticsearchHttp
NIFI-5500 Optimised array-to-string conversion This closes #2942 Signed-off-by: Mike Thomsen <mikerthomsen@gmail.com>
This commit is contained in:
parent
af6039a5b0
commit
d59a07245f
|
@ -432,7 +432,18 @@ public class QueryElasticsearchHttp extends AbstractElasticsearchHttpProcessor {
|
|||
Map<String, String> attributes = new HashMap<>();
|
||||
for(Iterator<Entry<String, JsonNode>> it = source.fields(); it.hasNext(); ) {
|
||||
Entry<String, JsonNode> entry = it.next();
|
||||
attributes.put(ATTRIBUTE_PREFIX + entry.getKey(), entry.getValue().asText());
|
||||
|
||||
String textValue = "";
|
||||
if(entry.getValue().isArray()){
|
||||
ArrayList<String> text_values = new ArrayList<String>();
|
||||
for(Iterator<JsonNode> items = entry.getValue().iterator(); items.hasNext(); ) {
|
||||
text_values.add(items.next().asText());
|
||||
}
|
||||
textValue = StringUtils.join(text_values, ',');
|
||||
} else {
|
||||
textValue = entry.getValue().asText();
|
||||
}
|
||||
attributes.put(ATTRIBUTE_PREFIX + entry.getKey(), textValue);
|
||||
}
|
||||
documentFlowFile = session.putAllAttributes(documentFlowFile, attributes);
|
||||
}
|
||||
|
|
|
@ -141,6 +141,7 @@ public class TestQueryElasticsearchHttp {
|
|||
QueryElasticsearchHttp.REL_SUCCESS).get(0);
|
||||
assertNotNull(out);
|
||||
assertEquals("blah", new String(out.toByteArray()));
|
||||
assertEquals("arrays,are,supported,too", out.getAttribute("es.result.tags"));
|
||||
assertEquals("Twitter", out.getAttribute("es.result.source"));
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
"transit_uri": "file://cluster2/data/outgoing/S3/abc-97b.zip",
|
||||
"object_type": "Provenance Record",
|
||||
"version": "ASVsZu_vShwtGCJpGOObmuSqUJRUC3L_",
|
||||
"file_size": "3645525"
|
||||
"file_size": "3645525",
|
||||
"tags": ["arrays", "are", "supported", "too"]
|
||||
},
|
||||
"sort": [
|
||||
1469198828102
|
||||
|
@ -45,13 +46,14 @@
|
|||
"transit_uri": "file://cluster2/data/outgoing/S3/abc-a78.zip",
|
||||
"object_type": "Provenance Record",
|
||||
"version": "SjJkrwnv6edIRqJChEYzrE7PeT1hzioz",
|
||||
"file_size": "4480294"
|
||||
"file_size": "4480294",
|
||||
"tags": ["arrays", "are", "supported", "too"]
|
||||
},
|
||||
"sort": [
|
||||
1469198828101
|
||||
]
|
||||
|
||||
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
"transit_uri": "file://cluster2/data/outgoing/S3/abc-42a.zip",
|
||||
"object_type": "Provenance Record",
|
||||
"version": "ArPsIlGBKqDvfL6qQZOVpmDwUEB.nynh",
|
||||
"file_size": "18206872"
|
||||
"file_size": "18206872",
|
||||
"tags": ["arrays", "are", "supported", "too"]
|
||||
},
|
||||
"sort": [
|
||||
1469198828101
|
||||
|
@ -33,4 +34,4 @@
|
|||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue