Issue
I have an entity that has a list of entities, i added @IndexedEmbedded
in this list to be able to search into it. So i want to search all entities that has the id 123 and the attribute x equals a given value. I tried with the code bellow but i have this error
Unable to find field bEntity.x in com.xx.xx.AEntity
@Entity
@Indexed
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class AEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Field
private String id;
@IndexedEmbedded
@ElementCollection
private Set<BEntity> bEntity;
}
@Entity
@IdClass(BPK.class)
public class BEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Field(name = "x_number")
private String x;
@Id
@Field(name = "y_number")
private String y;
}
QueryBuilder queryBuilder = getFullTextEntityManager().getSearchFactory().buildQueryBuilder().forEntity(AEntity.class).get();
Query query = queryBuilder.bool()
.must(queryBuilder.keyword().onField("id").matching("123").createQuery())
.must(queryBuilder.keyword().onField("bEntity.x").matching(str).createQuery())
.createQuery();
Solution
Your field is called bEntity.x_number
, not bEntity.x
:
@Field(name = "x_number")
That's why you're getting this error.
Use bEntity.x_number
instead of bEntity.x
in your query and you should be fine.
Answered By - yrodiere