Skip to content

Commit 394a57d

Browse files
committed
feat(search): include timestamp for entity metadata change
1 parent 52f71dd commit 394a57d

File tree

7 files changed

+47
-4
lines changed

7 files changed

+47
-4
lines changed

entity-registry/src/main/java/com/linkedin/metadata/models/SearchableFieldSpecExtractor.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ private void extractSearchableAnnotation(
176176
annotation.getNumValuesFieldName(),
177177
annotation.getWeightsPerFieldValue(),
178178
annotation.getFieldNameAliases(),
179-
annotation.isIncludeQueryEmptyAggregation());
179+
annotation.isIncludeQueryEmptyAggregation(),
180+
annotation.isIncludeSystemModifiedAt(),
181+
annotation.getSystemModifiedAtFieldName());
180182
}
181183
}
182184
log.debug("Searchable annotation for field: {} : {}", schemaPathSpec, annotation);

entity-registry/src/main/java/com/linkedin/metadata/models/annotation/SearchableAnnotation.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public class SearchableAnnotation {
6060
// only adds to query time not mapping
6161
boolean includeQueryEmptyAggregation;
6262

63+
boolean includeSystemModifiedAt;
64+
65+
Optional<String> systemModifiedAtFieldName;
66+
6367
public enum FieldType {
6468
KEYWORD,
6569
TEXT,
@@ -125,6 +129,10 @@ public static SearchableAnnotation fromPegasusAnnotationObject(
125129
final List<String> fieldNameAliases = getFieldNameAliases(map);
126130

127131
final FieldType resolvedFieldType = getFieldType(fieldType, schemaDataType);
132+
final Optional<Boolean> includeSystemModifiedAt =
133+
AnnotationUtils.getField(map, "includeSystemModifiedAt", Boolean.class);
134+
final Optional<String> systemModifiedAtFieldName =
135+
AnnotationUtils.getField(map, "systemModifiedAtFieldName", String.class);
128136
return new SearchableAnnotation(
129137
fieldName.orElse(schemaFieldName),
130138
resolvedFieldType,
@@ -139,7 +147,9 @@ public static SearchableAnnotation fromPegasusAnnotationObject(
139147
numValuesFieldName,
140148
weightsPerFieldValueMap.orElse(ImmutableMap.of()),
141149
fieldNameAliases,
142-
includeQueryEmptyAggregation.orElse(false));
150+
includeQueryEmptyAggregation.orElse(false),
151+
includeSystemModifiedAt.orElse(false),
152+
systemModifiedAtFieldName);
143153
}
144154

145155
private static FieldType getFieldType(

metadata-io/src/main/java/com/linkedin/metadata/search/elasticsearch/indexbuilder/MappingsBuilder.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,17 @@ private static Map<String, Object> getMappingsForField(
277277
.getNumValuesFieldName()
278278
.ifPresent(
279279
fieldName -> mappings.put(fieldName, ImmutableMap.of(TYPE, ESUtils.LONG_FIELD_TYPE)));
280+
281+
final String fieldName = searchableFieldSpec.getSearchableAnnotation().getFieldName();
282+
if (searchableFieldSpec.getSearchableAnnotation().isIncludeSystemModifiedAt()) {
283+
String modifiedAtFieldName =
284+
searchableFieldSpec
285+
.getSearchableAnnotation()
286+
.getSystemModifiedAtFieldName()
287+
.orElse(String.format("%sSystemModifiedAt", fieldName));
288+
mappings.put(modifiedAtFieldName, ImmutableMap.of(TYPE, ESUtils.DATE_FIELD_TYPE));
289+
}
290+
280291
mappings.putAll(getMappingsForFieldNameAliases(searchableFieldSpec));
281292

282293
return mappings;

metadata-io/src/main/java/com/linkedin/metadata/search/transformer/SearchDocumentTransformer.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ public void setSearchableValue(
255255
return;
256256
}
257257

258+
if (fieldSpec.getSearchableAnnotation().isIncludeSystemModifiedAt()) {
259+
String modifiedAtFieldName =
260+
fieldSpec
261+
.getSearchableAnnotation()
262+
.getSystemModifiedAtFieldName()
263+
.orElse(String.format("%sSystemModifiedAt", fieldName));
264+
searchDocument.set(
265+
modifiedAtFieldName,
266+
JsonNodeFactory.instance.numberNode((Long) System.currentTimeMillis()));
267+
}
268+
258269
if (isArray || (valueType == DataSchema.Type.MAP && !OBJECT_FIELD_TYPES.contains(fieldType))) {
259270
if (fieldType == FieldType.BROWSE_PATH_V2) {
260271
String browsePathV2Value = getBrowsePathV2Value(fieldValues);

metadata-models/src/main/pegasus/com/linkedin/businessattribute/BusinessAttributeAssociation.pdl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@ record BusinessAttributeAssociation {
55
/**
66
* Urn of the applied businessAttribute
77
*/
8+
@Searchable = {
9+
"fieldName": "schemaFieldBusinessAttribute",
10+
"includeSystemModifiedAt": true,
11+
"systemModifiedAtFieldName": "schemaFieldBusinessAttributeModifiedAt"
12+
}
813
businessAttributeUrn: BusinessAttributeUrn
914
}

metadata-models/src/main/pegasus/com/linkedin/common/GlossaryTermAssociation.pdl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ record GlossaryTermAssociation {
1616
"fieldType": "URN",
1717
"hasValuesFieldName": "hasGlossaryTerms",
1818
"addToFilters": true,
19-
"filterNameOverride": "Glossary Term"
19+
"filterNameOverride": "Glossary Term",
20+
"includeSystemModifiedAt": true,
21+
"systemModifiedAtFieldName": "termsModifiedAt"
2022
}
2123
urn: GlossaryTermUrn
2224

metadata-models/src/main/pegasus/com/linkedin/schema/EditableSchemaFieldInfo.pdl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ record EditableSchemaFieldInfo {
6767
"/terms/*/urn": {
6868
"fieldName": "editedFieldGlossaryTerms",
6969
"fieldType": "URN",
70-
"boostScore": 0.5
70+
"boostScore": 0.5,
71+
"includeSystemModifiedAt": true,
72+
"systemModifiedAtFieldName": "schemaFieldTermsModifiedAt"
7173
},
7274
"/terms/*/attribution/time": {
7375
"fieldName": "editedFieldTermAttributionDates",

0 commit comments

Comments
 (0)