|
29 | 29 | from pyatlan.utils import ComparisonCategory, is_comparable_type |
30 | 30 |
|
31 | 31 |
|
| 32 | +class AtlanSearchableFieldType(str, Enum): |
| 33 | + """ |
| 34 | + Enum to specify which field index to use when checking for existence of a value |
| 35 | + in a KeywordTextField. This is particularly useful for the has_any_value() method. |
| 36 | + """ |
| 37 | + |
| 38 | + KEYWORD = "KEYWORD" |
| 39 | + """ |
| 40 | + Use the keyword field index (e.g., userDescription.keyword). |
| 41 | + Note: Elasticsearch does not index .keyword for text exceeding 5K characters. |
| 42 | + """ |
| 43 | + |
| 44 | + TEXT = "TEXT" |
| 45 | + """ |
| 46 | + Use the text field index (e.g., userDescription.text or userDescription). |
| 47 | + This should be used when field values may exceed 5K characters. |
| 48 | + """ |
| 49 | + |
| 50 | + |
32 | 51 | class AtlanField(ABC): |
33 | 52 | """ |
34 | 53 | Base enumeration of all attributes that exist in Atlan, so you do not have to remember their |
@@ -75,13 +94,28 @@ def __init__(self, atlan_field_name: StrictStr, elastic_field_name: StrictStr): |
75 | 94 | def internal_field_name(self): |
76 | 95 | return self.atlan_field_name |
77 | 96 |
|
78 | | - def has_any_value(self) -> Query: |
| 97 | + def has_any_value( |
| 98 | + self, |
| 99 | + field_type: Optional[AtlanSearchableFieldType] = None, |
| 100 | + ) -> Query: |
79 | 101 | """ |
80 | 102 | Returns a query that will only match assets that have some non-null, non-empty value |
81 | 103 | (no matter what actual value) for the field. |
82 | 104 |
|
| 105 | + Note: When text exceeds a particular length (5K characters), the keyword field on an |
| 106 | + attribute can be empty while the text field on the same attribute is populated. |
| 107 | + For KeywordTextField types, use field_type=AtlanSearchableFieldType.TEXT to check |
| 108 | + the text field instead. For other field types, this parameter is ignored. |
| 109 | +
|
| 110 | + :param field_type: optional field type to check for existence (KEYWORD or TEXT). |
| 111 | + Only applicable for KeywordTextField types. |
| 112 | + Defaults to KEYWORD (None) for backwards compatibility. |
83 | 113 | :returns: a query that will only match assets that have some non-null, non-empty value for the field |
84 | 114 | """ |
| 115 | + if field_type == AtlanSearchableFieldType.TEXT and hasattr( |
| 116 | + self, "_text_field_name" |
| 117 | + ): |
| 118 | + return Exists(field=self._text_field_name) |
85 | 119 | return Exists(field=self.elastic_field_name) |
86 | 120 |
|
87 | 121 | def order(self, order: SortOrder = SortOrder.ASCENDING) -> SortItem: |
|
0 commit comments