# How to test elasticsearch queries?

**URL:** <https://discuss.elastic.co/t/how-to-test-elasticsearch-queries/55864>\
**Category:** Elasticsearch\
**Created:** [July 19, 2016, 11:06am UTC](https://discuss.elastic.co/t/how-to-test-elasticsearch-queries/55864 "2016-07-19T11:06:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![siddharthgoel88](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/siddharthgoel88/32/10616_2.png) [@siddharthgoel88](https://discuss.elastic.co/u/siddharthgoel88)\
**Post date:** [July 19, 2016, 11:06am UTC](https://discuss.elastic.co/t/how-to-test-elasticsearch-queries/55864/1 "2016-07-19T11:06:25Z")

</div>

I want to test the queries are written in my project. I want to write some integration test which could test the correctness of my queries that I have written. What could be the best way/best practice to do the same?

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [July 20, 2016, 7:50am UTC](https://discuss.elastic.co/t/how-to-test-elasticsearch-queries/55864/2 "2016-07-20T07:50:33Z")

</div>

Hi @siddharthgoel88,

we do this ourselves in the Elasticsearch project and have specific test infrastructure for that. Basically, your test needs to extend from `ESIntegTestCase`. This test case will start a test cluster in the same JVM where you can add documents via the Java API (just call the `client()` method to get a client)).

For an example see [SearchQueryIT](https://github.com/elastic/elasticsearch/blob/master/core/src/test/java/org/elasticsearch/search/query/SearchQueryIT.java) on Github.

Daniel

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:34pm UTC](https://discuss.elastic.co/t/how-to-test-elasticsearch-queries/55864/3 "2017-07-05T22:34:10Z")

</div>


