Skip to content

Commit cbaaa51

Browse files
committed
Bug fix: When a document retrieved from Elasticsearch lacks an index field defined in the entity model, skip the field and attempt to extract the other fields. Previously, jobs were failing when index fields were missing from documents. But it's entirely valid for documents in Elasticsearch to lack fields that are defined in the index mapping.
1 parent f4e629c commit cbaaa51

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/main/java/io/zentity/model/IndexField.java

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

3+
import com.fasterxml.jackson.core.JsonPointer;
34
import com.fasterxml.jackson.databind.JsonNode;
45
import io.zentity.common.Json;
56
import io.zentity.common.Patterns;
@@ -19,8 +20,8 @@ public class IndexField {
1920

2021
private final String index;
2122
private final String name;
22-
private String path;
23-
private String pathParent;
23+
private JsonPointer path;
24+
private JsonPointer pathParent;
2425
private String attribute;
2526
private String matcher;
2627

@@ -48,11 +49,11 @@ public String name() {
4849
return this.name;
4950
}
5051

51-
public String path() {
52+
public JsonPointer path() {
5253
return this.path;
5354
}
5455

55-
public String pathParent() {
56+
public JsonPointer pathParent() {
5657
return this.pathParent;
5758
}
5859

@@ -76,9 +77,9 @@ public void matcher(JsonNode value) throws ValidationException {
7677

7778
private void nameToPaths(String name) {
7879
String[] parts = Patterns.PERIOD.split(name);
79-
this.path = "/" + String.join("/", parts);
80+
this.path = JsonPointer.compile("/" + String.join("/", parts));
8081
if (parts.length > 1)
81-
this.pathParent = "/" + String.join("/", Arrays.copyOf(parts, parts.length - 1));
82+
this.pathParent = JsonPointer.compile("/" + String.join("/", Arrays.copyOf(parts, parts.length - 1)));
8283
}
8384

8485
private void validateName(String value) throws ValidationException {

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

Lines changed: 10 additions & 6 deletions
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.core.JsonProcessingException;
45
import com.fasterxml.jackson.databind.JsonNode;
56
import com.fasterxml.jackson.databind.node.ArrayNode;
@@ -1119,13 +1120,16 @@ else if (!resolversClause.isEmpty())
11191120
// The index field name might not refer to the _source property.
11201121
// If it's not in the _source, remove the last part of the index field name from the dot notation.
11211122
// Index field names can reference multi-fields, which are not returned in the _source.
1122-
String path = this.input.model().indices().get(indexName).fields().get(indexFieldName).path();
1123-
String pathParent = this.input.model().indices().get(indexName).fields().get(indexFieldName).pathParent();
1123+
// If the document does not contain a given index field, skip that field.
1124+
JsonPointer path = this.input.model().indices().get(indexName).fields().get(indexFieldName).path();
1125+
JsonPointer pathParent = this.input.model().indices().get(indexName).fields().get(indexFieldName).pathParent();
11241126
JsonNode valueNode = doc.get("_source").at(path);
1125-
if (valueNode.isMissingNode())
1126-
valueNode = doc.get("_source").at(pathParent);
1127-
if (valueNode.isMissingNode())
1128-
continue;
1127+
if (valueNode.isMissingNode()) {
1128+
if (pathParent != null)
1129+
valueNode = doc.get("_source").at(pathParent);
1130+
else
1131+
continue;
1132+
}
11291133
docAttributes.put(attributeName, valueNode);
11301134
Value value = Value.create(attributeType, valueNode);
11311135
nextInputAttributes.get(attributeName).values().add(value);

0 commit comments

Comments
 (0)