Skip to content

Commit c03ce76

Browse files
committed
Bug fix: Ensure that null values and missing fields are not passed to the "_attributes" object. This bug only affected the output of "_attributes" and not the accuracy of the resolution job.
1 parent 9d5b6ae commit c03ce76

11 files changed

Lines changed: 140 additions & 89 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Once you have installed Elasticsearch, you can install zentity from a remote URL
3131

3232
Example:
3333

34-
`elasticsearch-plugin install https://zentity.io/releases/zentity-1.5.0-elasticsearch-7.3.2.zip`
34+
`elasticsearch-plugin install https://zentity.io/releases/zentity-1.5.1-beta1-elasticsearch-7.3.2.zip`
3535

3636
Read the [installation](https://zentity.io/docs/installation) docs for more details.
3737

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<zentity.author>Dave Moore</zentity.author>
1515
<zentity.classname>org.elasticsearch.plugin.zentity.ZentityPlugin</zentity.classname>
1616
<zentity.website>https://zentity.io</zentity.website>
17-
<zentity.version>1.5.0</zentity.version>
17+
<zentity.version>1.5.1-beta1</zentity.version>
1818
<!-- dependency versions -->
1919
<elasticsearch.version>7.3.2</elasticsearch.version>
2020
<jackson.core.version>2.9.9</jackson.core.version>

src/main/java/io/zentity/resolution/Job.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,10 +1094,6 @@ else if (!resolversClause.isEmpty())
10941094
if (this.input.model().attributes().get(attributeName) == null)
10951095
continue;
10961096
String attributeType = this.input.model().attributes().get(attributeName).type();
1097-
if (!docAttributes.containsKey(attributeName))
1098-
docAttributes.put(attributeName, new TreeSet<>());
1099-
if (!nextInputAttributes.containsKey(attributeName))
1100-
nextInputAttributes.put(attributeName, new Attribute(attributeName, attributeType));
11011097

11021098
// Get the attribute values from the doc.
11031099
if (doc.has("fields") && doc.get("fields").has(indexFieldName)) {
@@ -1114,6 +1110,10 @@ else if (!resolversClause.isEmpty())
11141110
if (vNode.isNull() || valueNode.isMissingNode())
11151111
continue;
11161112
Value value = Value.create(attributeType, vNode);
1113+
if (!docAttributes.containsKey(attributeName))
1114+
docAttributes.put(attributeName, new TreeSet<>());
1115+
if (!nextInputAttributes.containsKey(attributeName))
1116+
nextInputAttributes.put(attributeName, new Attribute(attributeName, attributeType));
11171117
docAttributes.get(attributeName).add(value);
11181118
nextInputAttributes.get(attributeName).values().add(value);
11191119
}
@@ -1123,6 +1123,10 @@ else if (!resolversClause.isEmpty())
11231123
docIndexFields.put(indexFieldName, valueNode);
11241124
} else {
11251125
Value value = Value.create(attributeType, valueNode);
1126+
if (!docAttributes.containsKey(attributeName))
1127+
docAttributes.put(attributeName, new TreeSet<>());
1128+
if (!nextInputAttributes.containsKey(attributeName))
1129+
nextInputAttributes.put(attributeName, new Attribute(attributeName, attributeType));
11261130
docAttributes.get(attributeName).add(value);
11271131
nextInputAttributes.get(attributeName).values().add(value);
11281132
docIndexFields.put(indexFieldName, valueNode);
@@ -1154,11 +1158,19 @@ else if (!resolversClause.isEmpty())
11541158
if (vNode.isNull() || valueNode.isMissingNode())
11551159
continue;
11561160
Value value = Value.create(attributeType, vNode);
1161+
if (!docAttributes.containsKey(attributeName))
1162+
docAttributes.put(attributeName, new TreeSet<>());
1163+
if (!nextInputAttributes.containsKey(attributeName))
1164+
nextInputAttributes.put(attributeName, new Attribute(attributeName, attributeType));
11571165
docAttributes.get(attributeName).add(value);
11581166
nextInputAttributes.get(attributeName).values().add(value);
11591167
}
11601168
} else {
11611169
Value value = Value.create(attributeType, valueNode);
1170+
if (!docAttributes.containsKey(attributeName))
1171+
docAttributes.put(attributeName, new TreeSet<>());
1172+
if (!nextInputAttributes.containsKey(attributeName))
1173+
nextInputAttributes.put(attributeName, new Attribute(attributeName, attributeType));
11621174
docAttributes.get(attributeName).add(value);
11631175
nextInputAttributes.get(attributeName).values().add(value);
11641176
}

src/test/java/io/zentity/resolution/JobIT.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.zentity.resolution;
22

3+
import com.fasterxml.jackson.core.JsonPointer;
34
import com.fasterxml.jackson.databind.JsonNode;
45
import io.zentity.common.Json;
56
import org.apache.commons.io.IOUtils;
@@ -703,6 +704,14 @@ public void testJobNoScope() throws Exception {
703704
Response response = client.performRequest(postResolution);
704705
JsonNode json = Json.MAPPER.readTree(response.getEntity().getContent());
705706
assertEquals(json.get("hits").get("total").asInt(), 40);
707+
JsonPointer pathAttributes = JsonPointer.compile("/_attributes");
708+
JsonPointer pathNull = JsonPointer.compile("/_attributes/attribute_type_string_null");
709+
JsonPointer pathUnused = JsonPointer.compile("/_attributes/attribute_type_string_unused");
710+
for (JsonNode doc : json.get("hits").get("hits")) {
711+
assertEquals(doc.at(pathAttributes).isMissingNode(), false);
712+
assertEquals(doc.at(pathNull).isMissingNode(), true);
713+
assertEquals(doc.at(pathUnused).isMissingNode(), true);
714+
}
706715
} finally {
707716
destroyTestResources(testResourceSet);
708717
}
@@ -1692,7 +1701,7 @@ public void testJobArrays() throws Exception {
16921701
switch (doc.get("_id").asText()) {
16931702
case "1":
16941703
attributesExpected = "{\"array\":[\"111\",\"222\",\"333\",\"444\"],\"string\":[\"abc\"]}";
1695-
explanationExpected = "{\"resolvers\":{\"array\":{\"attributes\":[\"array\"]},\"string\":{\"attributes\":[\"string\"]}},\"matches\":[{\"attribute\":\"array\",\"target_field\":\"array_2\",\"target_value\":[\"222\",\"222\"],\"input_value\":\"222\",\"input_matcher\":\"exact\",\"input_matcher_params\":{}},{\"attribute\":\"array\",\"target_field\":\"array_4\",\"target_value\":[\"222\",\"333\",\"444\"],\"input_value\":\"222\",\"input_matcher\":\"exact\",\"input_matcher_params\":{}},{\"attribute\":\"string\",\"target_field\":\"string\",\"target_value\":\"abc\",\"input_value\":\"abc\",\"input_matcher\":\"exact\",\"input_matcher_params\":{}}]}";
1704+
explanationExpected = "{\"resolvers\":{\"array\":{\"attributes\":[\"array\"]},\"string\":{\"attributes\":[\"string\"]}},\"matches\":[{\"attribute\":\"array\",\"target_field\":\"array_2\",\"target_value\":[\"222\",null,\"222\"],\"input_value\":\"222\",\"input_matcher\":\"exact\",\"input_matcher_params\":{}},{\"attribute\":\"array\",\"target_field\":\"array_4\",\"target_value\":[\"222\",\"333\",\"444\"],\"input_value\":\"222\",\"input_matcher\":\"exact\",\"input_matcher_params\":{}},{\"attribute\":\"string\",\"target_field\":\"string\",\"target_value\":\"abc\",\"input_value\":\"abc\",\"input_matcher\":\"exact\",\"input_matcher_params\":{}}]}";
16961705
break;
16971706
case "2":
16981707
attributesExpected = "{\"array\":[\"444\",\"555\"],\"string\":[\"xyz\"]}";

0 commit comments

Comments
 (0)