Not indexing includepaths


i have an objectA with a List property

public class ObjectA {
    @OneToMany(mappedBy = "objecta", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW)
	private List<ObjectB> objectBList = new ArrayList<>();

and an objectB

public class ObjectB {
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "objectCid")
	@IndexedEmbedded(includePaths = {"id","name", "name_sort"})
	@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW)
	private ObjectC objectc;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
	@JoinColumn(name = "objectaid", nullable = false)
	@IndexedEmbedded(includePaths = {"id"})
	private ObjectA objecta;
public class ObjectC {
	@ScaledNumberField(decimalScale = 0, sortable = Sortable.YES)
	private BigInteger id;

	@GenericField(name = "name_sort", sortable = Sortable.YES)
	private String name;

Saving the objectA i cant search by Always got empty list.


Is the problem the includePaths or not ?

Thank you

Probably not. If the includePaths doesn’t work, you’ll get an exception on startup.

Keep in mind that your using ReindexOnUpdate.SHALLOW means the document for ObjectA/ObjectB won’t be updated when the name of ObjectC changes, and the document for ObjectA won’t be updated when ObjectB#objectc changes, so it could lead to out-of-sync indexes and thus problems such as this.

If that’s not your problem, I will need a more complete reproducer to help. See here for templates to get you started.

Edit the 1st comment and add some extra code !
For my example:

Firstly, do massindexer and the below return a correct result


After i edit an existing objectA and add new ObjectB and ObjectC

ObjectA objecta = repository.findbyid(objectaId);
ObjectB objectb = new ObjectB();
objectC objectc = new ObjectC();

Updating the objecta, the above not works :confused:

Like I I said:

It’s really all there is to say.

1 Like

is the solution to remove ReindexOnUpdate.SHALLOW from objectA and to add @IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW) on objectB from property objecta ? I tried everything and my problem remains !

If you want changes to ObjectC to trigger reindexing of ObjectB (and by extension, of ObjectA), Hibernate Search needs a way to retrieve the ObjectB corresponding to a given ObjectC. So if that’s the problem, then yes, you need to remove ReindexOnUpdate.SHALLOW, and introduce ObjectC#objectB to model the inverse side of the association ObjectB#objectC. It’s all explained in details in the documentation: Hibernate Search 6.1.8.Final: Reference Documentation

If that’s not your problem, then as I said above, I need a reproducer to help you. And by that I mean an actual project that compiles and a test that shows the problem, so I can debug it: