# How to query with JSON when use Java API in ElasticSearch?

**URL:** <https://discuss.elastic.co/t/how-to-query-with-json-when-use-java-api-in-elasticsearch/19781>\
**Category:** Elasticsearch\
**Created:** [September 15, 2014, 7:22am UTC](https://discuss.elastic.co/t/how-to-query-with-json-when-use-java-api-in-elasticsearch/19781 "2014-09-15T07:22:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11166](https://avatars.discourse-cdn.com/v4/letter/1/46a35a/32.png) [@11166](https://discuss.elastic.co/u/11166)\
**Post date:** [September 15, 2014, 7:22am UTC](https://discuss.elastic.co/t/how-to-query-with-json-when-use-java-api-in-elasticsearch/19781/1 "2014-09-15T07:22:45Z")

</div>

Hi all,  
I'm using ElasticSearch as a search service in Spring Web project. Now  
I'm using Transport Client to communicate with ES.  
I'm wondering if there exists a method which can construct a QueryBuilder  
from a JSON DSL. for example, convert this bool query DSL JSON  
{  
"query" : {  
"bool" : {  
"must" : { "match" : {"content" : "quick"},  
"should": { "match": {"content" : "lazy"}  
}  
}  
}

```
to a QueryBuilder. I need this function because I have to receive 

```

user's bool string input from web front-side, and parse this bool string to  
a QueryBuilder.  
However it not suit to use  
QueryBuilders.boolQuery().must(matchQB).should(shouldQB).must\_not(mustNotQB).  
Because we may need several must or non must keywords.

Thanks for your time! I'm really need some help.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1a26d1b4-d457-4dbb-b36e-caf469353d55%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1a26d1b4-d457-4dbb-b36e-caf469353d55%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Andrej](https://avatars.discourse-cdn.com/v4/letter/a/d9b06d/32.png) [@Andrej](https://discuss.elastic.co/u/Andrej)\
**Post date:** [September 15, 2014, 9:08am UTC](https://discuss.elastic.co/t/how-to-query-with-json-when-use-java-api-in-elasticsearch/19781/2 "2014-09-15T09:08:10Z")

</div>

Hi,

there are QueryBuilder that can parse JSON, e.g. WrapperQueryBuilder  
[http://javadoc.kyubu.de/elasticsearch/HEAD/org/elasticsearch/index/query/WrapperQueryBuilder.html](http://javadoc.kyubu.de/elasticsearch/HEAD/org/elasticsearch/index/query/WrapperQueryBuilder.html) wrapperQuery(java.lang.String source).  
This should do the job.

Greets,  
Andrej

PS: Still wondering why javadocs disappeared a while ago. This would be a  
great help if javadocs would be available for each version for download.

Am Montag, 15. September 2014 09:22:45 UTC+2 schrieb 张新星:

> Hi all,  
> I'm using Elasticsearch as a search service in Spring Web project.  
> Now I'm using Transport Client to communicate with ES.  
> I'm wondering if there exists a method which can construct a QueryBuilder  
> from a JSON DSL. for example, convert this bool query DSL JSON  
> {  
> "query" : {  
> "bool" : {  
> "must" : { "match" : {"content" : "quick"},  
> "should": { "match": {"content" : "lazy"}  
> }  
> }  
> }
> 
> ```
> to a QueryBuilder. I need this function because I have to receive 
> 
> ```
> 
> user's bool string input from web front-side, and parse this bool string to  
> a QueryBuilder.  
> However it not suit to use  
> QueryBuilders.boolQuery().must(matchQB).should(shouldQB).must\_not(mustNotQB).  
> Because we may need several must or non must keywords.
> 
> Thanks for your time! I'm really need some help.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/780122c7-16b2-4f17-9c83-b77a6401e85f%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/780122c7-16b2-4f17-9c83-b77a6401e85f%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![11166](https://avatars.discourse-cdn.com/v4/letter/1/46a35a/32.png) [@11166](https://discuss.elastic.co/u/11166)\
**Post date:** [September 23, 2014, 12:10pm UTC](https://discuss.elastic.co/t/how-to-query-with-json-when-use-java-api-in-elasticsearch/19781/3 "2014-09-23T12:10:52Z")

</div>

Hi Andrej,  
Thanks a lot for your kindly help. It's really give me a big progress.  
PS: I also found that QueryBuilders.wrapperQuery(String DSL) can do the  
same  
work. [How to construct QueryBuilder from JSON DSL when using Java API in ElasticSearch? - Stack Overflow](http://stackoverflow.com/questions/25859921/how-to-construct-querybuilder-from-json-dsl-when-using-java-api-in-elasticsearch)

在 2014年9月15日星期一UTC+8下午5时08分10秒，Andrej Rosenheinrich写道：

> Hi,
> 
> there are QueryBuilder that can parse JSON, e.g. WrapperQueryBuilder  
> [http://javadoc.kyubu.de/elasticsearch/HEAD/org/elasticsearch/index/query/WrapperQueryBuilder.html](http://javadoc.kyubu.de/elasticsearch/HEAD/org/elasticsearch/index/query/WrapperQueryBuilder.html) wrapperQuery(java.lang.String source).  
> This should do the job.
> 
> Greets,  
> Andrej
> 
> PS: Still wondering why javadocs disappeared a while ago. This would be a  
> great help if javadocs would be available for each version for download.
> 
> Am Montag, 15. September 2014 09:22:45 UTC+2 schrieb 张新星:
> 
> > Hi all,  
> > I'm using Elasticsearch as a search service in Spring Web project.  
> > Now I'm using Transport Client to communicate with ES.  
> > I'm wondering if there exists a method which can construct a QueryBuilder  
> > from a JSON DSL. for example, convert this bool query DSL JSON  
> > {  
> > "query" : {  
> > "bool" : {  
> > "must" : { "match" : {"content" : "quick"},  
> > "should": { "match": {"content" : "lazy"}  
> > }  
> > }  
> > }
> > 
> > ```
> > to a QueryBuilder. I need this function because I have to receive 
> > 
> > ```
> > 
> > user's bool string input from web front-side, and parse this bool string to  
> > a QueryBuilder.  
> > However it not suit to use  
> > QueryBuilders.boolQuery().must(matchQB).should(shouldQB).must\_not(mustNotQB).  
> > Because we may need several must or non must keywords.
> > 
> > Thanks for your time! I'm really need some help.

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e9593f26-cd85-4162-bb1c-1fedec92caa8%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e9593f26-cd85-4162-bb1c-1fedec92caa8%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 1:00am UTC](https://discuss.elastic.co/t/how-to-query-with-json-when-use-java-api-in-elasticsearch/19781/4 "2017-07-06T01:00:27Z")

</div>


