# Validating a query

**URL:** <https://discuss.elastic.co/t/validating-a-query/9873>\
**Category:** Elasticsearch\
**Created:** [November 29, 2012, 12:04am UTC](https://discuss.elastic.co/t/validating-a-query/9873 "2012-11-29T00:04:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iamdlu](https://avatars.discourse-cdn.com/v4/letter/i/c0e974/32.png) [@iamdlu](https://discuss.elastic.co/u/iamdlu)\
**Post date:** [November 29, 2012, 12:04am UTC](https://discuss.elastic.co/t/validating-a-query/9873/1 "2012-11-29T00:04:39Z")

</div>

Hi, I'm trying to validate a query in Java. For example, I want to know  
when a user types in "test OR" before i send the query to the cluster. I  
tried using ValidateQueryRequest but the validate() method simply does a  
return null. Can someone please help me figure this out?

thanks.

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [November 29, 2012, 11:59am UTC](https://discuss.elastic.co/t/validating-a-query/9873/2 "2012-11-29T11:59:09Z")

</div>

For ValidateQuery request to work, it has to send the query to the server:

client.admin().indices().prepareValidateQuery("test").setQuery(QueryBuilders.queryString("test  
OR")).execute().actionGet().valid()

So, it makes sense only when you don't really need any data back and care  
only about validity of the query. For example, you can use this method  
before storing saved searches. If you are planning to execute this  
query immediately after the validation, it's faster to just send the query  
with search request right away and handle possible error response.

On Wednesday, November 28, 2012 7:04:39 PM UTC-5, iamdlu wrote:

> Hi, I'm trying to validate a query in Java. For example, I want to know  
> when a user types in "test OR" before i send the query to the cluster. I  
> tried using ValidateQueryRequest but the validate() method simply does a  
> return null. Can someone please help me figure this out?
> 
> thanks.

--

---

<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 6, 2017, 3:02am UTC](https://discuss.elastic.co/t/validating-a-query/9873/3 "2017-07-06T03:02:15Z")

</div>


