# Indexing Inheritance Hierarchy

**URL:** <https://discourse.hibernate.org/t/indexing-inheritance-hierarchy/6940>\
**Category:** Hibernate Search\
**Created:** [November 21, 2022, 6:50pm UTC](https://discourse.hibernate.org/t/indexing-inheritance-hierarchy/6940 "2022-11-21T18:50:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rob](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@rob](https://discourse.hibernate.org/u/rob)\
**Post date:** [November 21, 2022, 6:50pm UTC](https://discourse.hibernate.org/t/indexing-inheritance-hierarchy/6940/1 "2022-11-21T18:50:49Z")

</div>

The docs are not great on this. I have a Content base class then different types, strategy is JOINED. So should not make base class @Indexed but can annotate fields. Fine. But then I end up with different indexes for every subtype? Total nonstarter?

---

<div class="post-metadata">

**Author:** ![gsmet](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/gsmet/32/9_2.png) [@gsmet](https://discourse.hibernate.org/u/gsmet)\
**Post date:** [November 21, 2022, 7:08pm UTC](https://discourse.hibernate.org/t/indexing-inheritance-hierarchy/6940/2 "2022-11-21T19:08:14Z")

</div>

The indexes are per type but you can target the base class for searches. The fact that the indexes are separate is just an implementation detail from the user point of view.

Typically, if you have `Associate` extending `Person` and `Manager` extending `Person`, you can target `Person` for your search and it will return both `Person` and `Manager` instances matching the query.

---

<div class="post-metadata">

**Author:** ![rob](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@rob](https://discourse.hibernate.org/u/rob)\
**Post date:** [November 21, 2022, 7:10pm UTC](https://discourse.hibernate.org/t/indexing-inheritance-hierarchy/6940/3 "2022-11-21T19:10:20Z")

</div>

Ok great, is there a sample? or a part of the docs you could point me to? I have been through the docs I thought.

---

<div class="post-metadata">

**Author:** ![gsmet](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/gsmet/32/9_2.png) [@gsmet](https://discourse.hibernate.org/u/gsmet)\
**Post date:** [November 21, 2022, 7:28pm UTC](https://discourse.hibernate.org/t/indexing-inheritance-hierarchy/6940/4 "2022-11-21T19:28:04Z")

</div>

The documentation about how to query multiple entity types is here: [Hibernate Search 6.1.7.Final: Reference Documentation](https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#search-dsl-query-targeting-multiple) .

As you can see it’s transparent for you.

---

<div class="post-metadata">

**Author:** ![rob](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@rob](https://discourse.hibernate.org/u/rob)\
**Post date:** [November 21, 2022, 7:52pm UTC](https://discourse.hibernate.org/t/indexing-inheritance-hierarchy/6940/5 "2022-11-21T19:52:43Z")

</div>

Ok, yeah I got that to compile, but still have issues with my test per my other ticket the mass indexer is not seeing entities to index, even though findAll sees them there. Was hoping this would be more turnkey.

---

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [November 24, 2022, 7:14am UTC](https://discourse.hibernate.org/t/indexing-inheritance-hierarchy/6940/6 "2022-11-24T07:14:35Z")

</div>

Apparently solved, quoting:

> [@Writing Tests that Exercise Hibernate Search](https://discourse.hibernate.org/t/writing-tests-that-exercise-hibernate-search/6933/5):
>
> Also, on my other ticket, I did get that sorted: indexing subs but fetching abstract base types. So pretty happy. Thanks for the help.

---

<div class="post-metadata">

**Author:** ![yaaraaja4](https://avatars.discourse-cdn.com/v4/letter/y/58956e/32.png) [@yaaraaja4](https://discourse.hibernate.org/u/yaaraaja4)\
**Post date:** [December 1, 2022, 10:10am UTC](https://discourse.hibernate.org/t/indexing-inheritance-hierarchy/6940/7 "2022-12-01T10:10:53Z")

</div>

One of the sites I work on has this. We’ve been seeing CPU Bottlenecks due to some very long queries. We didn’t get crazy with subclassing, but it did get crazy with the number of foreignkeys and many to many’s on the subclass which seems to be causing an excessive amount of queries. I don’t have much experience with the other way you defined, at scale, so I can’t really say if its worse or not.
