# Hibernate Search 6 + Elastic Search 7+ Integration Test

**URL:** <https://discourse.hibernate.org/t/hibernate-search-6-elastic-search-7-integration-test/4606>\
**Category:** Hibernate Search\
**Created:** [September 24, 2020, 6:55am UTC](https://discourse.hibernate.org/t/hibernate-search-6-elastic-search-7-integration-test/4606 "2020-09-24T06:55:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Swarnkar](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@Swarnkar](https://discourse.hibernate.org/u/Swarnkar)\
**Post date:** [September 24, 2020, 6:55am UTC](https://discourse.hibernate.org/t/hibernate-search-6-elastic-search-7-integration-test/4606/1 "2020-09-24T06:55:33Z")

</div>

Hi,  
So everything seems working in live application however when we wrote Integration test we have all the test cases failing without any exceptions.  
It seems like since we are using remote Elastic server for indexing and in test cases when we modify the entities and the reflected indexes are before updating test will ask for data and thus it is failing.  
Can we have any workaround for this as we are working in agile team and integration tests are must.

---

<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:** [September 24, 2020, 7:04am UTC](https://discourse.hibernate.org/t/hibernate-search-6-elastic-search-7-integration-test/4606/2 "2020-09-24T07:04:26Z")

</div>

Elasticsearch is a near-real-time platform. When you change something in the index, Elasticsearch will return a response and tell you everything was indexed, but the changes will not be visible when searching immediately. By default it will take about one second for the changes to be visible in a search query.

This is the behavior of **Elasticsearch** , not Hibernate Search, and it behaves that way for performance reasons.

In integration tests this behavior is inconvenient since you want to check the changes had an effect right away.  
Thus, **for tests** , (not in production!), you might want to tell Hibernate Search to make changes visible immediately after they are performed. This can be achieved by setting this property:

```auto
hibernate.search.automatic_indexing.synchronization.strategy = sync

```

Again, **you should not do this in production environments** : indexing throughput will decrease significantly.

I encourage you to read the documentation for more information about this behavior, in particular [this section](https://docs.jboss.org/hibernate/search/6.0/reference/en-US/html_single/#mapper-orm-indexing-automatic-synchronization).

---

<div class="post-metadata">

**Author:** ![Swarnkar](https://avatars.discourse-cdn.com/v4/letter/s/f4b2a3/32.png) [@Swarnkar](https://discourse.hibernate.org/u/Swarnkar)\
**Post date:** [September 24, 2020, 10:55am UTC](https://discourse.hibernate.org/t/hibernate-search-6-elastic-search-7-integration-test/4606/3 "2020-09-24T10:55:29Z")

</div>

@yrodiere thanks for suggestion however I tried it and tests were still failing!  
though I have done one trick to update index for test cases  
In before method explicitly put to reindex data and that way its working .  
I know this is not good approach however I haven’t find anything except this to overcome this issue.  
Please suggest if u have anything to share on this  
Thnaks

---

<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:** [September 24, 2020, 12:35pm UTC](https://discourse.hibernate.org/t/hibernate-search-6-elastic-search-7-integration-test/4606/4 "2020-09-24T12:35:36Z")

</div>

How do you initialize your database for tests?

If you use SQL commands, or JPQL, or if you restore a database snapshot, then Hibernate Search is not aware of the data you put into the database. In that case, then yes, mass indexing is the way to go.
