Skip to content

Commit c9b1132

Browse files
committed
Merge branch '4.0.x' into 4.1.x
2 parents 52277a4 + 0e44ac6 commit c9b1132

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

src/main/java/io/confluent/connect/elasticsearch/Mapping.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,12 @@ private static JsonNode inferPrimitive(String type, Object defaultValue) {
197197
break;
198198
case ElasticsearchSinkConnectorConstants.STRING_TYPE:
199199
case ElasticsearchSinkConnectorConstants.TEXT_TYPE:
200-
defaultValueNode = JsonNodeFactory.instance.textNode((String) defaultValue);
201-
break;
202200
case ElasticsearchSinkConnectorConstants.BINARY_TYPE:
203-
defaultValueNode = JsonNodeFactory.instance.binaryNode(bytes(defaultValue));
201+
// IGNORE default values for text and binary types as this is not supported by ES side.
202+
// see https://www.elastic.co/guide/en/elasticsearch/reference/current/text.html
203+
// https://www.elastic.co/guide/en/elasticsearch/reference/current/binary.html
204+
// for more details.
205+
//defaultValueNode = null;
204206
break;
205207
case ElasticsearchSinkConnectorConstants.BOOLEAN_TYPE:
206208
defaultValueNode = JsonNodeFactory.instance.booleanNode((boolean) defaultValue);

src/test/java/io/confluent/connect/elasticsearch/MappingTest.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package io.confluent.connect.elasticsearch;
1818

19+
import com.fasterxml.jackson.databind.JsonNode;
1920
import com.google.gson.JsonObject;
2021

2122
import org.apache.kafka.connect.data.Date;
@@ -51,6 +52,29 @@ public void testMapping() throws Exception {
5152
verifyMapping(schema, mapping);
5253
}
5354

55+
@Test
56+
public void testInferMapping() throws Exception {
57+
58+
Schema stringSchema = SchemaBuilder
59+
.struct()
60+
.name("record")
61+
.field("foo", SchemaBuilder.string().defaultValue("0").build())
62+
.build();
63+
JsonNode stringMapping = Mapping.inferMapping(client, stringSchema);
64+
65+
assertNull(stringMapping.get("properties").get("foo").get("null_value"));
66+
67+
Schema intSchema =SchemaBuilder
68+
.struct()
69+
.name("record")
70+
.field("foo", SchemaBuilder.int32().defaultValue(0).build())
71+
.build();
72+
73+
JsonNode intMapping = Mapping.inferMapping(client, intSchema);
74+
assertNotNull(intMapping.get("properties").get("foo").get("null_value"));
75+
assertEquals(0, intMapping.get("properties").get("foo").get("null_value").asInt());
76+
}
77+
5478
protected Schema createSchema() {
5579
Schema structSchema = createInnerSchema();
5680
return SchemaBuilder.struct().name("record")
@@ -96,7 +120,6 @@ private Schema createInnerSchema() {
96120
@SuppressWarnings("unchecked")
97121
private void verifyMapping(Schema schema, JsonObject mapping) throws Exception {
98122
String schemaName = schema.name();
99-
100123
Object type = mapping.get("type");
101124
if (schemaName != null) {
102125
switch (schemaName) {

0 commit comments

Comments
 (0)