Skip to content
Permalink
Browse files

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.
  • Loading branch information...
davemoore- committed Sep 22, 2019
1 parent 9d5b6ae commit c03ce7657399cbab3ab0b72510e063be2109fb6d
@@ -31,7 +31,7 @@ Once you have installed Elasticsearch, you can install zentity from a remote URL

Example:

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

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

@@ -14,7 +14,7 @@
<zentity.author>Dave Moore</zentity.author>
<zentity.classname>org.elasticsearch.plugin.zentity.ZentityPlugin</zentity.classname>
<zentity.website>https://zentity.io</zentity.website>
<zentity.version>1.5.0</zentity.version>
<zentity.version>1.5.1-beta1</zentity.version>
<!-- dependency versions -->
<elasticsearch.version>7.3.2</elasticsearch.version>
<jackson.core.version>2.9.9</jackson.core.version>
@@ -1094,10 +1094,6 @@ else if (!resolversClause.isEmpty())
if (this.input.model().attributes().get(attributeName) == null)
continue;
String attributeType = this.input.model().attributes().get(attributeName).type();
if (!docAttributes.containsKey(attributeName))
docAttributes.put(attributeName, new TreeSet<>());
if (!nextInputAttributes.containsKey(attributeName))
nextInputAttributes.put(attributeName, new Attribute(attributeName, attributeType));

// Get the attribute values from the doc.
if (doc.has("fields") && doc.get("fields").has(indexFieldName)) {
@@ -1114,6 +1110,10 @@ else if (!resolversClause.isEmpty())
if (vNode.isNull() || valueNode.isMissingNode())
continue;
Value value = Value.create(attributeType, vNode);
if (!docAttributes.containsKey(attributeName))
docAttributes.put(attributeName, new TreeSet<>());
if (!nextInputAttributes.containsKey(attributeName))
nextInputAttributes.put(attributeName, new Attribute(attributeName, attributeType));
docAttributes.get(attributeName).add(value);
nextInputAttributes.get(attributeName).values().add(value);
}
@@ -1123,6 +1123,10 @@ else if (!resolversClause.isEmpty())
docIndexFields.put(indexFieldName, valueNode);
} else {
Value value = Value.create(attributeType, valueNode);
if (!docAttributes.containsKey(attributeName))
docAttributes.put(attributeName, new TreeSet<>());
if (!nextInputAttributes.containsKey(attributeName))
nextInputAttributes.put(attributeName, new Attribute(attributeName, attributeType));
docAttributes.get(attributeName).add(value);
nextInputAttributes.get(attributeName).values().add(value);
docIndexFields.put(indexFieldName, valueNode);
@@ -1154,11 +1158,19 @@ else if (!resolversClause.isEmpty())
if (vNode.isNull() || valueNode.isMissingNode())
continue;
Value value = Value.create(attributeType, vNode);
if (!docAttributes.containsKey(attributeName))
docAttributes.put(attributeName, new TreeSet<>());
if (!nextInputAttributes.containsKey(attributeName))
nextInputAttributes.put(attributeName, new Attribute(attributeName, attributeType));
docAttributes.get(attributeName).add(value);
nextInputAttributes.get(attributeName).values().add(value);
}
} else {
Value value = Value.create(attributeType, valueNode);
if (!docAttributes.containsKey(attributeName))
docAttributes.put(attributeName, new TreeSet<>());
if (!nextInputAttributes.containsKey(attributeName))
nextInputAttributes.put(attributeName, new Attribute(attributeName, attributeType));
docAttributes.get(attributeName).add(value);
nextInputAttributes.get(attributeName).values().add(value);
}
@@ -1,5 +1,6 @@
package io.zentity.resolution;

import com.fasterxml.jackson.core.JsonPointer;
import com.fasterxml.jackson.databind.JsonNode;
import io.zentity.common.Json;
import org.apache.commons.io.IOUtils;
@@ -703,6 +704,14 @@ public void testJobNoScope() throws Exception {
Response response = client.performRequest(postResolution);
JsonNode json = Json.MAPPER.readTree(response.getEntity().getContent());
assertEquals(json.get("hits").get("total").asInt(), 40);
JsonPointer pathAttributes = JsonPointer.compile("/_attributes");
JsonPointer pathNull = JsonPointer.compile("/_attributes/attribute_type_string_null");
JsonPointer pathUnused = JsonPointer.compile("/_attributes/attribute_type_string_unused");
for (JsonNode doc : json.get("hits").get("hits")) {
assertEquals(doc.at(pathAttributes).isMissingNode(), false);
assertEquals(doc.at(pathNull).isMissingNode(), true);
assertEquals(doc.at(pathUnused).isMissingNode(), true);
}
} finally {
destroyTestResources(testResourceSet);
}
@@ -1692,7 +1701,7 @@ public void testJobArrays() throws Exception {
switch (doc.get("_id").asText()) {
case "1":
attributesExpected = "{\"array\":[\"111\",\"222\",\"333\",\"444\"],\"string\":[\"abc\"]}";
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\":{}}]}";
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\":{}}]}";
break;
case "2":
attributesExpected = "{\"array\":[\"444\",\"555\"],\"string\":[\"xyz\"]}";

0 comments on commit c03ce76

Please sign in to comment.
You can’t perform that action at this time.