Not indexing includepaths

Hi,

i have an objectA with a List property

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

and an objectB

@Indexed
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;
}
@Indexed
public class ObjectC {
    @Id
	@ScaledNumberField(decimalScale = 0, sortable = Sortable.YES)
	private BigInteger id;

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

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

pf.match().field(objectc.name).matching(token);

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

pf.match().field(objectc.name).matching(token);

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();
objectc.setId(1);
objectc.setName("Test");
objectb.setObjectc(objectc);
objecta.getObjectB().add(objectb);
repository.save(objecta);
objecta.addAll(objectbList);

Updating the objecta, the above not works :confused:

Like I I said:

It’s really all there is to say.

1 Like

Goodmornig,
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: https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#mapper-orm-reindexing-basics

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: