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)) 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 "Levianthan Wakes":- title = Levianthan 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 = Levianthan 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 ContainerExtractionextractionString[]includePathsThe paths of index fields from the indexed-embedded element that should be embedded.intmaxDepthThe max recursion depth for indexed-embedded processing.StringnameStringprefixDeprecated.Usename()instead.ObjectFieldStoragestorageDeprecated.Usestructure()instead.ObjectStructurestructureClass<?>targetType
-
-
-
Element Detail
-
prefix
@Deprecated 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
maxDepth().By default, if neither
includePathsnormaxDepth()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:
- {}
-
-
-
maxDepth
int maxDepth
The max recursion depth for indexed-embedded processing.maxDepthis 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:maxDepth=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().maxDepth=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(no limit) ifincludePaths()is not empty, the default is0(only include fields included explicitly).- Returns:
- The max depth size.
- Default:
- -1
-
-
-
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
-
-
-
storage
@Deprecated ObjectFieldStorage storage
Deprecated.Usestructure()instead.- Returns:
- How the structure of the object field created for this indexed-embedded is preserved upon indexing.
- See Also:
ObjectFieldStorage
- Default:
- org.hibernate.search.engine.backend.document.model.dsl.ObjectFieldStorage.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
-
-