Annotation Type IndexedEmbedded


  • @Documented
    @Repeatable(List.class)
    @Target({METHOD,FIELD})
    @Retention(RUNTIME)
    @PropertyMapping(processor=@PropertyMappingAnnotationProcessorRef(type=org.hibernate.search.mapper.pojo.mapping.definition.annotation.processing.impl.IndexedEmbeddedProcessor.class,retrieval=CONSTRUCTOR))
    public @interface IndexedEmbedded
    Maps a property to an object field whose fields are the same as those defined in the property type.

    This allows search queries on a single index to use data from multiple entities.

    For example, let's consider this (incomplete) mapping:

    
     {@literal @}Indexed
     public class Book {
         {@literal @}GenericField
         private String title;
         {@literal @}IndexedEmbedded
         private List<Author> authors;
     }
     public class Author {
         {@literal @}GenericField
         private String firstName;
         {@literal @}GenericField
         private String lastName;
         private List<Book> books;
     }
     

    The names of authors are stored in different objects, thus by default they would not be included in documents created for Book entities. But we added the @IndexedEmbedded annotation to the authors property, so Hibernate Search will embed this data in a authors field of documents created for Book entities.

    How exactly this embedding will happen depends on the configured structure. Let's consider this representation of the book "Leviathan Wakes":

    • title = Leviathan Wakes
    • authors =
      • (first element)
        • firstName = Daniel
        • lastName = Abraham
      • (second element)
        • firstName = Ty
        • lastName = Frank

    With the default flattened structure (more efficient), the document structure will be a little different from what one would expect:

    • title = Leviathan Wakes
    • authors.firstName =
      • (first element) Daniel
      • (second element) Ty
    • authors.lastName =
      • (first element) Abraham
      • (second element) Frank

    To get the original structure, the nested structure must be used, but this has an impact on performance and how queries must be structured. See the reference documentation for more information.

    • Element Detail

      • prefix

        @Deprecated
        @Search5DeprecatedAPI
        String prefix
        Deprecated.
        Use name() instead. Note that name() does not allow dots.
        Returns:
        The prefix used when embedding. Defaults to <property name>., meaning an object field with the same name as the property will be defined in the parent document to host the value of the child document. Must not be set if name() is set.
        Default:
        ""
      • name

        String name
        Returns:
        The name of the object field created to represent this @IndexedEmbedded. Defaults to the property name. Must not be set if prefix() is set.
        Default:
        ""
      • includePaths

        String[] includePaths
        The paths of index fields from the indexed-embedded element that should be embedded.

        This takes precedence over includeDepth().

        By default, if neither includePaths nor includeDepth() is defined, all index fields are included.

        Returns:
        The paths of index fields to include explicitly. Provided paths must be relative to the indexed-embedded element, i.e. they must not include the name().
        Default:
        {}
      • includeDepth

        int includeDepth
        The number of levels of indexed-embedded that will have all their fields included by default.

        includeDepth is the number of `@IndexedEmbedded` that will be traversed and for which all fields of the indexed-embedded element will be included, even if these fields are not included explicitly through includePaths:

        • includeDepth=0 means fields of the indexed-embedded element are not included, nor is any field of nested indexed-embedded elements, unless these fields are included explicitly through includePaths().
        • includeDepth=1 means fields of the indexed-embedded element are included, but not fields of nested indexed-embedded elements, unless these fields are included explicitly through includePaths().
        • And so on.
        The default value depends on the value of the includePaths() attribute: if includePaths() is empty, the default is Integer.MAX_VALUE (include all fields at every level) if includePaths() is not empty, the default is 0 (only include fields included explicitly).
        Returns:
        The number of levels of indexed-embedded that will have all their fields included by default.
        Default:
        -1
      • includeEmbeddedObjectId

        boolean includeEmbeddedObjectId
        Whether the identifier of embedded objects should be included as an index field.

        The index field will defined as if the following annotation was put on the identifier property of the embedded type: @GenericField(searchable = Searchable.YES, projectable = Projectable.YES). The name of the index field will be the name of the identifier property. Its bridge will be the identifier bridge applied to the identifier property using DocumentId if any, or the default value bridge for the property type by default.

        If you need more advanced mapping (custom name, custom bridge, sortable, ...), define the field explicitly in the embedded type by annotating the identifier property with GenericField or a similar field annotation, and make sure the field is included by @IndexedEmbedded by configuring includeDepth() and/or includePaths().

        Returns:
        Whether the identifier of embedded objects should be included as an index field.
        Default:
        false
      • structure

        ObjectStructure structure
        Returns:
        How the structure of the object field created for this indexed-embedded is preserved upon indexing.
        See Also:
        ObjectStructure
        Default:
        org.hibernate.search.engine.backend.types.ObjectStructure.DEFAULT
      • extraction

        ContainerExtraction extraction
        Returns:
        A definition of container extractors to be applied to the property, allowing the definition of an indexed-embedded for container elements. This is useful when the property is of container type, for example a Map<TypeA, TypeB>: defining the extraction as @ContainerExtraction(BuiltinContainerExtractors.MAP_KEY) allows referencing map keys instead of map values. By default, Hibernate Search will try to apply a set of extractors for common container types.
        See Also:
        ContainerExtraction
        Default:
        @org.hibernate.search.mapper.pojo.extractor.mapping.annotation.ContainerExtraction
      • targetType

        Class<?> targetType
        Returns:
        A type indexed-embedded elements should be cast to. When relying on container extraction, the extracted values are cast, not the container. By default, no casting occurs.
        Default:
        void.class