Pass JSON query to get selected records using java api

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Pass JSON query to get selected records using java api

Ankit Jain
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 [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: Pass JSON query to get selected records using java api

dadoonet
What error do you get?

--
David ;-)
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 28 nov. 2013 à 15:57, Ankit Jain <[hidden email]> 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 [hidden email].
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 [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: Pass JSON query to get selected records using java api

Ankit Jain
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 <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="skYAWCOlZaAJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">ankitj...@...> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="skYAWCOlZaAJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">elasticsearc...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/elasticsearch/c15fdf26-36f0-44a9-8c09-231c066f739b%40googlegroups.com" target="_blank" onmousedown="this.href='https://groups.google.com/d/msgid/elasticsearch/c15fdf26-36f0-44a9-8c09-231c066f739b%40googlegroups.com';return true;" onclick="this.href='https://groups.google.com/d/msgid/elasticsearch/c15fdf26-36f0-44a9-8c09-231c066f739b%40googlegroups.com';return true;">https://groups.google.com/d/msgid/elasticsearch/c15fdf26-36f0-44a9-8c09-231c066f739b%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/groups/opt_out" target="_blank" onmousedown="this.href='https://groups.google.com/groups/opt_out';return true;" onclick="this.href='https://groups.google.com/groups/opt_out';return true;">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 [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|

Re: Pass JSON query to get selected records using java api

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


Le 29 novembre 2013 at 08:08:58, Ankit Jain ([hidden email]) 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 <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="skYAWCOlZaAJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">ankitj...@...> 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="skYAWCOlZaAJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">elasticsearc...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/elasticsearch/c15fdf26-36f0-44a9-8c09-231c066f739b%40googlegroups.com" target="_blank" onmousedown="this.href='https://groups.google.com/d/msgid/elasticsearch/c15fdf26-36f0-44a9-8c09-231c066f739b%40googlegroups.com';return true;" onclick="this.href='https://groups.google.com/d/msgid/elasticsearch/c15fdf26-36f0-44a9-8c09-231c066f739b%40googlegroups.com';return true;"> https://groups.google.com/d/msgid/elasticsearch/c15fdf26-36f0-44a9-8c09-231c066f739b%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/groups/opt_out" target="_blank" onmousedown="this.href='https://groups.google.com/groups/opt_out';return true;" onclick="this.href='https://groups.google.com/groups/opt_out';return true;"> 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 [hidden email].
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 [hidden email].
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.