SelfReferencingObject
Terminal object field representing a self-referencing relationship in an Elasticsearch document.
This class is automatically generated by the Metalastic annotation processor when a document or object field references itself, either directly or through a complex type. Self-referencing fields would create infinite recursion in the metamodel hierarchy, so they are terminated at this point to maintain a safe, traversable type structure.
When This Is Generated
The processor generates a SelfReferencingObject when:
A
@Documentclass has a field of its own typeAn object field references its containing class
Circular dependencies exist in the document structure
Example Scenario
@Document(indexName = "category")
data class Category(
@Field(type = FieldType.Keyword)
val id: String,
@Field(type = FieldType.Text)
val name: String,
@Field(type = FieldType.Object)
val parentCategory: Category? // Self-reference
)Generated metamodel:
class QCategory<T : Any?>(
parent: ObjectField<*>? = null,
name: String = "",
nested: Boolean = false,
fieldType: KType
) : Document<T>(...) {
@JvmField
val id: KeywordField<String> = keywordField("id")
@JvmField
val name: TextField<String> = textField("name")
// Terminates here to avoid infinite recursion
@JvmField
val parentCategory: SelfReferencingObject<Category?> =
SelfReferencingObject(this, "parentCategory", false, typeOf<Category?>())
}Usage
You can still use the field for path construction and queries:
val category = Metamodels.category
category.parentCategory.path() // Returns "parentCategory"
category.parentCategory.isNestedPath() // Works correctlyHowever, you cannot traverse further into the referenced type's properties since that would require infinite nesting.
Parameters
The parent object field in the hierarchy
The Elasticsearch field name
Whether this field is marked as nested in Elasticsearch
The Kotlin type information for runtime type safety
Type Parameters
The type of the self-referencing field
See also
Functions
Declares a child AliasField named fieldName, modeling the alias field type.
Declares a child AnnotatedTextField named fieldName, modeling the annotated_text field type.
Declares a child BinaryField named fieldName, modeling the binary field type.
Declares a child BooleanField named fieldName, modeling the boolean field type.
Declares a child CompletionField named fieldName, modeling the completion field type.
Declares a child ConstantKeywordField named fieldName, modeling the constant_keyword field type.
Declares a child DateNanosField named fieldName, modeling the date_nanos field type.
Declares a child DateRangeField named fieldName, modeling the date_range field type.
Declares a child DenseVectorField named fieldName, modeling the dense_vector field type.
Declares a child DoubleField named fieldName, modeling the double field type.
Declares a child DoubleRangeField named fieldName, modeling the double_range field type.
Returns the KClass for this field's type, or null if the type is not a concrete class (e.g., if it's a type parameter or complex type intersection).
Declares a child FlattenedField named fieldName, modeling the flattened field type.
Declares a child FloatField named fieldName, modeling the float field type.
Declares a child FloatRangeField named fieldName, modeling the float_range field type.
Declares a child HalfFloatField named fieldName, modeling the half_float field type.
Declares a child IntegerField named fieldName, modeling the integer field type.
Declares a child IntegerRangeField named fieldName, modeling the integer_range field type.
Declares a child IpRangeField named fieldName, modeling the ip_range field type.
Returns true if any ancestor container is marked as nested in Elasticsearch.
Declares a child KeywordField named fieldName, modeling the keyword field type.
Declares a child LongRangeField named fieldName, modeling the long_range field type.
Declares a child MatchOnlyTextField named fieldName, modeling the match_only_text field type.
Declares a child Murmur3Field named fieldName, modeling the murmur3 field type.
Returns the paths of the ancestor containers that are marked as nested, closest first.
Returns the direct parent container in the metamodel hierarchy, or null for a root.
Declares a child PercolatorField named fieldName, modeling the percolator field type.
Declares a child PointField named fieldName, modeling the point field type.
Declares a child RankFeatureField named fieldName, modeling the rank_feature field type.
Declares a child RankFeaturesField named fieldName, modeling the rank_features field type.
Declares a child ScaledFloatField named fieldName, modeling the scaled_float field type.
Declares a child SearchAsYouTypeField named fieldName, modeling the search_as_you_type field type.
Declares a child ShapeField named fieldName, modeling the shape field type.
Declares a child ShortField named fieldName, modeling the short field type.
Declares a child TokenCountField named fieldName, modeling the token_count field type.
Declares a child VersionField named fieldName, modeling the version field type.
Declares a child WildcardField named fieldName, modeling the wildcard field type.