How to configure type name or filter by type query with Elasticsearch integration?

Viewed 106

I'm using Hibernate Search with Elasticsearch integration with the versions 5.8.2 and 5.6 respectively.

Let's say I have 2 applications which use the same database and I want to search for Person entity. Both of the applications will update indexes but only one of them will read.

Since, by default Hibernate Search uses fully qualified class names for types, I end up with 2 different types for the same entity like:

Person -> com.example.x.Person

Person -> com.example.y.Person

In the application I'm performing the search, while constructing the search query, Hibernate Search automatically add filter query for type like:

"filter": {
    "type": {"value": "com.example.x.Person"}
}

thus search results don't contain the records from com.example.y.Person type.

Is there any way that I can customize type names?

Or, is there any way to disable/customize added filter query?

1 Answers

You can't do it for now.

Funnily enough, we just had a very similar question a few days ago: Override Elasticsearch _type in Hibernate Search .

My advice is the following: if it's the exact same entity, you should extract it in a common jar and use the same entity in both of your applications (if you cannot extract it, you can still use the same package but I would recommend to extract it so that you're sure it's exactly the same).

Related