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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

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

张新星
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/1a26d1b4-d457-4dbb-b36e-caf469353d55%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Andrej
Hi,

there are QueryBuilder that can parse JSON, e.g. WrapperQueryBuilder 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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/780122c7-16b2-4f17-9c83-b77a6401e85f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

张新星
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. 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.<a href="http://javadoc.kyubu.de/elasticsearch/HEAD/org/elasticsearch/index/query/WrapperQueryBuilder.html" title="class in org.elasticsearch.index.query" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fjavadoc.kyubu.de%2Felasticsearch%2FHEAD%2Forg%2Felasticsearch%2Findex%2Fquery%2FWrapperQueryBuilder.html\46sa\75D\46sntz\0751\46usg\75AFQjCNEJrl-dImcL0VpabytaN5Fw67Ah1A';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fjavadoc.kyubu.de%2Felasticsearch%2FHEAD%2Forg%2Felasticsearch%2Findex%2Fquery%2FWrapperQueryBuilder.html\46sa\75D\46sntz\0751\46usg\75AFQjCNEJrl-dImcL0VpabytaN5Fw67Ah1A';return true;"> WrapperQueryBuilder 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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/e9593f26-cd85-4162-bb1c-1fedec92caa8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.