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
Bookentities. But we added the@IndexedEmbeddedannotation to theauthorsproperty, so Hibernate Search will embed this data in aauthorsfield of documents created forBookentities.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
- (first element)
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 structuremust be used, but this has an impact on performance and how queries must be structured. See the reference documentation for more information.
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description ContainerExtractionextractionintincludeDepthThe number of levels of indexed-embedded that will have all their fields included by default.booleanincludeEmbeddedObjectIdWhether the identifier of embedded objects should be included as an index field.String[]includePathsThe paths of index fields from the indexed-embedded element that should be embedded.StringnameStringprefixDeprecated.Usename()instead.ObjectStructurestructureClass<?>targetType
-
-
-
Element Detail
-
prefix
@Deprecated @Search5DeprecatedAPI String prefix
- 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 ifname()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
includePathsnorincludeDepth()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.includeDepthis 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 throughincludePaths:includeDepth=0means fields of the indexed-embedded element are not included, nor is any field of nested indexed-embedded elements, unless these fields are included explicitly throughincludePaths().includeDepth=1means fields of the indexed-embedded element are included, but not fields of nested indexed-embedded elements, unless these fields are included explicitly throughincludePaths().- And so on.
includePaths()attribute: ifincludePaths()is empty, the default isInteger.MAX_VALUE(include all fields at every level) ifincludePaths()is not empty, the default is0(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 usingDocumentIdif 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
GenericFieldor a similar field annotation, and make sure the field is included by@IndexedEmbeddedby configuringincludeDepth()and/orincludePaths().- 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
-
-