Pass JSON query to get selected records using java api

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.
To view this discussion on the web visit 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.

What error do you get?

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

Le 28 nov. 2013 à 15:57, Ankit Jain 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.
To view this discussion on the web visit 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.

--
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.
To view this discussion on the web visit 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.

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 :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 28 nov. 2013 à 15:57, Ankit Jain <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 <javascript:>.
To view this discussion on the web visit
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.

--
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.
To view this discussion on the web visit 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.

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

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" -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
@dadoonet | @elasticsearchfr

Le 29 novembre 2013 at 08:08:58, Ankit Jain (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 :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 28 nov. 2013 à 15:57, Ankit Jain 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.
To view this discussion on the web visit 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.

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.
To view this discussion on the web visit 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.

--
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.
To view this discussion on the web visit 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.