Hello there,
I have a the following data:
@ManyToMany(fetch = FetchType.EAGER, cascade = {CascadeType.MERGE, CascadeType.PERSIST})
@JoinTable(name="configuration_tags",
joinColumns=@JoinColumn(name="configuration_id", referencedColumnName="id"),
inverseJoinColumns=@JoinColumn(name="tag_id", referencedColumnName="id"))
@IndexedEmbedded(storage = ObjectFieldStorage.FLATTENED)
@NotAudited
private Set<Tag> tags = new HashSet<>();
When I try to save more than one tag I get the following exception
dimension "tags.label" is not multiValued, but it appears more than once in this document
Is this something that can be configured via annotation? I had a look at the TypeBinder
@Override
public void bind(TypeBindingContext context) {
context.getDependencies()
/* ... (declaration of dependencies, not relevant) ... */
IndexSchemaElement schemaElement = context.getIndexSchemaElement();
context.setBridge( new Bridge(
schemaElement.field( "names", f -> f.asString().analyzer( "name" ) )
.multiValued()
.toReference()
) );
}
However Bridge isn’t available as a class in 6.0.0.Beta6. Also according to the release notes Hibernate search will auto detect multi value fields (unless I’m mistaken).
Any help would be appreciated.
Thanks
Also according to the release notes Hibernate search will auto detect multi value fields (unless I’m mistaken).
That’s right, it should.
dimension “tags.label” is not multiValued, but it appears more than once in this document
It looks like something related to the implementation of aggregations. Are you using the Lucene backend, and is tags.label
marked as Aggregable.YES
?
If so, that explains the problem; aggregations with the Lucene backend do not support multi-valued properties yet, and it has been the case for ages (HSEARCH-1929). Fortunately this was solved recently in the master branch and the fix will be released in 6.0.0.Beta7
.
Hi there
Yes I was using Aggregable.YES
for the tag label field. For my local testing I use Lucene but when deployed we will be using Elasticsearch. I’ve created a custom type binder to set it to multi valued which works. Not sure if this is the right approach or wait for the next release.
Thanks
Sure your approach will work, as long as the multi-valued field is not marked as “aggregable”.
I’d recommend leaving a TODO somewhere, as type binders are easy to get wrong; you should probably switch back to @IndexedEmbedded
as soon as the fix is available.
I do the following in my code
IndexSchemaObjectField tagsField =
schemaElement.objectField(
"tags",
ObjectFieldStorage.FLATTENED
);
IndexFieldType<String> tagFieldType = context.getTypeFactory()
.asString()
.aggregable(Aggregable.YES)
.searchable(Searchable.YES)
.toIndexFieldType();
context.setBridge( new Bridge(tagsField.toReference(),
tagsField.field( "label", tagFieldType )
.multiValued()
.toReference()));
But I’ll leave a TODO to remove it once there is a release.
Thanks