# Pass JSON query to get selected records using java api

**URL:** <https://discuss.elastic.co/t/pass-json-query-to-get-selected-records-using-java-api/14632>\
**Category:** Elasticsearch\
**Created:** [November 28, 2013, 2:57pm UTC](https://discuss.elastic.co/t/pass-json-query-to-get-selected-records-using-java-api/14632 "2013-11-28T14:57:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ankit\_Jain](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@Ankit\_Jain](https://discuss.elastic.co/u/Ankit_Jain)\
**Post date:** [November 28, 2013, 2:57pm UTC](https://discuss.elastic.co/t/pass-json-query-to-get-selected-records-using-java-api/14632/1 "2013-11-28T14:57:41Z")

</div>

Hi All,

I am firing below query to retrieve the selected records with selected  
fields from ES index.

I am getting error while executing below query.

SearchResponse searchResponse = client.prepareSearch(nameSpace)  
.setQuery(

_"{\n" + ""fields" : ["Address1"],\n" +  
""query" : {\n" + " "match"  
: {\n" + " "invocationId" : "123"\n" +  
" }\n" + "}\n" + "}"_  
).execute().actionGet();

Regards,  
Ankit Jain

--  
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/c15fdf26-36f0-44a9-8c09-231c066f739b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c15fdf26-36f0-44a9-8c09-231c066f739b%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 28, 2013, 3:34pm UTC](https://discuss.elastic.co/t/pass-json-query-to-get-selected-records-using-java-api/14632/2 "2013-11-28T15:34:05Z")

</div>

What error do you get?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 28 nov. 2013 à 15:57, Ankit Jain [ankitjaincs06@gmail.com](mailto:ankitjaincs06@gmail.com) a écrit :

> Hi All,
> 
> I am firing below query to retrieve the selected records with selected fields from ES index.
> 
> I am getting error while executing below query.
> 
> SearchResponse searchResponse = client.prepareSearch(nameSpace)  
> .setQuery("{\n" +  
> ""fields" : ["Address1"],\n" +  
> ""query" : {\n" +  
> " "match" : {\n" +  
> " "invocationId" : "123"\n" +  
> " }\n" +  
> "}\n" +  
> "}").execute().actionGet();
> 
> Regards,  
> Ankit Jain
> 
> --  
> 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/c15fdf26-36f0-44a9-8c09-231c066f739b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c15fdf26-36f0-44a9-8c09-231c066f739b%40googlegroups.com).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/960BB51C-76F1-436C-9B6E-38300410D0F2%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/960BB51C-76F1-436C-9B6E-38300410D0F2%40pilato.fr).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Ankit\_Jain](https://avatars.discourse-cdn.com/v4/letter/a/96bed5/32.png) [@Ankit\_Jain](https://discuss.elastic.co/u/Ankit_Jain)\
**Post date:** [November 29, 2013, 7:08am UTC](https://discuss.elastic.co/t/pass-json-query-to-get-selected-records-using-java-api/14632/3 "2013-11-29T07:08:54Z")

</div>

Hi David,

I am getting below exception:

Parse Failure [Failed to parse source  
[{"query\_binary":"eyJxdWVyeSIgOiB7CiAgICAibWF0Y2giIDogewogICAgICAgICJpbnZvY2F0aW9uSWQiIDogIjEyMyIKICAgIH0KfX0=","fields":"\*"}]]

Regards,  
Ankit Jain

On Thursday, 28 November 2013 21:04:05 UTC+5:30, David Pilato wrote:

> What error do you get?
> 
> --  
> David 😉  
> Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs
> 
> Le 28 nov. 2013 à 15:57, Ankit Jain \<[ankitj...@gmail.com](mailto:ankitj...@gmail.com) \<javascript:\>\> a  
> écrit :
> 
> Hi All,
> 
> I am firing below query to retrieve the selected records with selected  
> fields from ES index.
> 
> I am getting error while executing below query.
> 
> SearchResponse searchResponse = client.prepareSearch(nameSpace)  
> .setQuery(
> 
> _"{\n" + ""fields" : ["Address1"],\n" +  
> ""query" : {\n" + "  
> "match" : {\n" + " "invocationId" :  
> "123"\n" + " }\n" +  
> "}\n" + "}"_).execute().actionGet();
> 
> Regards,  
> Ankit Jain
> 
> --  
> 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com) \<javascript:\>.  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/c15fdf26-36f0-44a9-8c09-231c066f739b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c15fdf26-36f0-44a9-8c09-231c066f739b%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/f09b3cf8-1a79-445e-a432-403973544a43%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f09b3cf8-1a79-445e-a432-403973544a43%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [November 29, 2013, 7:48am UTC](https://discuss.elastic.co/t/pass-json-query-to-get-selected-records-using-java-api/14632/4 "2013-11-29T07:48:19Z")

</div>

My head was hitting the wall before I found your error! 🙂

when you setQuery(String) you need to give only the QUERY part of the full query.  
I mean that if you query is:  
curl -XPOST "[http://localhost:9200/\_search](http://localhost:9200/_search)" -d'  
{  
"fields" : ["Address1"],  
"query" : {  
"match" : {  
"invocationId" : "123"  
}  
}  
}'

The query part is:  
{  
"match" : {  
"invocationId" : "123"  
}  
}

To set fields, you need to use .addField() method.

HTH

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet | @elasticsearchfr

Le 29 novembre 2013 at 08:08:58, Ankit Jain ([ankitjaincs06@gmail.com](mailto:ankitjaincs06@gmail.com)) a écrit:

Hi David,

I am getting below exception:

Parse Failure [Failed to parse source [{"query\_binary":"eyJxdWVyeSIgOiB7CiAgICAibWF0Y2giIDogewogICAgICAgICJpbnZvY2F0aW9uSWQiIDogIjEyMyIKICAgIH0KfX0=","fields":"\*"}]]

Regards,  
Ankit Jain

On Thursday, 28 November 2013 21:04:05 UTC+5:30, David Pilato wrote:  
What error do you get?

--  
David 😉  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 28 nov. 2013 à 15:57, Ankit Jain [ankitj...@gmail.com](mailto:ankitj...@gmail.com) a écrit :

Hi All,

I am firing below query to retrieve the selected records with selected fields from ES index.

I am getting error while executing below query.

SearchResponse searchResponse = client.prepareSearch(nameSpace)  
.setQuery("{\n" +  
""fields" : ["Address1"],\n" +  
""query" : {\n" +  
" "match" : {\n" +  
" "invocationId" : "123"\n" +  
" }\n" +  
"}\n" +  
"}").execute().actionGet();

Regards,  
Ankit Jain

## -- 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 [elasticsearc...@googlegroups.com](mailto:elasticsearc...@googlegroups.com). To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/c15fdf26-36f0-44a9-8c09-231c066f739b%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/c15fdf26-36f0-44a9-8c09-231c066f739b%40googlegroups.com). For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

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/f09b3cf8-1a79-445e-a432-403973544a43%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f09b3cf8-1a79-445e-a432-403973544a43%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/etPan.529846c3.71c91298.3e14%40MacBook-Air-de-David.local](https://groups.google.com/d/msgid/elasticsearch/etPan.529846c3.71c91298.3e14%40MacBook-Air-de-David.local).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:04am UTC](https://discuss.elastic.co/t/pass-json-query-to-get-selected-records-using-java-api/14632/5 "2017-07-06T02:04:14Z")

</div>


