Annotation Type IndexedEmbedded
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
- (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 structure
must be used,
but this has an impact on performance and how queries must be structured.
See the reference documentation for more information.
-
Nested Class Summary
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionString[]
The paths of index fields from the indexed-embedded element that should not be embedded.int
The number of levels of indexed-embedded that will have all their fields included by default.boolean
Whether the identifier of embedded objects should be included as an index field.String[]
The paths of index fields from the indexed-embedded element that should be embedded.Deprecated.Class
<?>
-
Element Details
-
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:
""
-
name
String name- Returns:
- The name of the object field created to represent this
@IndexedEmbedded
. Defaults to the property name. Must not be set ifprefix()
is set.
- Default:
""
-
includePaths
String[] includePathsThe paths of index fields from the indexed-embedded element that should be embedded.This takes precedence over
includeDepth()
.By default, if none of
includePaths
,excludePaths
orincludeDepth()
are defined, all index fields are included.Cannot be used when
excludePaths()
contains any paths.- 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()
. Paths must lead to a field and cannot end with someprefix used to construct a field name
.
- Default:
{}
-
excludePaths
The paths of index fields from the indexed-embedded element that should not be embedded.This takes precedence over
includeDepth()
.By default, if none of
includePaths
,excludePaths
orincludeDepth()
are defined, all index fields are included.Cannot be used when
includePaths()
contains any paths.- Returns:
- The paths of index fields to exclude explicitly.
Provided paths must be relative to the indexed-embedded element,
i.e. they must not include the
name()
. Paths must lead to a field and cannot end with someprefix used to construct a field name
.
- Default:
{}
-
includeDepth
int includeDepthThe 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 throughincludePaths
, unless these fields are excluded explicitly throughexcludePaths
:includeDepth=0
means fields of this indexed-embedded element are not included, nor is any field of nested indexed-embedded elements, unless these fields are included explicitly throughincludePaths()
.includeDepth=1
means fields of this indexed-embedded element are included, unless these fields are explicitly excluded throughexcludePaths
, but not fields of nested indexed-embedded elements (@IndexedEmbedded
within this@IndexedEmbedded
), unless these fields are included explicitly throughincludePaths()
.includeDepth=2
means fields of this indexed-embedded element are included, and so are fields of the immediately nested indexed-embedded elements (@IndexedEmbedded
within this@IndexedEmbedded
), unless these fields are explicitly excluded throughexcludePaths
, but not fields of nested indexed-embedded elements beyond that (@IndexedEmbedded
within an@IndexedEmbedded
within this@IndexedEmbedded
), unless these fields are included explicitly throughincludePaths()
.- And so on.
includePaths()
attributes:- if
includePaths()
is empty, the default isInteger.MAX_VALUE
(include all fields at every level) - if
includePaths()
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 includeEmbeddedObjectIdWhether the identifier of embedded objects should be included as an index field.The index field will be 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 referenced by the embedded type'sDocumentId
annotation, if any, or the default value bridge for the identifier property's 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 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:
- Default:
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:
- 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
-
name()
instead.