Updated.
I figured out that I need to do url-encode to process some characters like
{ , } ," ...
so I change part my code to:
String string1="-d {\"query\" : {\"match_all\" : {}}}";
WebResource webResource = client
.resource("http://localhost:9200/obd2/_search?scroll=1m&size=50"+
URLEncoder.encode(string1));
Now I get the respones:
java.lang.RuntimeException: Failed : HTTP error code : 400
Is that mean my get/request was successfully sent to the server.
The new error was triggered by some other reasons such as firewall...etc
On Friday, August 1, 2014 12:25:27 PM UTC-7, Chia-Eng Chang wrote:
>
> I tried to send http/get to my elasticsearch server.if I query:
>
> curl 'http://localhost:9200/index/_search?scroll=1m&size=50&pretty'
> -d '{"query" : {"match_all" : {}}}'
>
> it works perfect. But when I tried to use jersy to build my client, I did
> the follwoing:
>
> public class JerseyClientGet {
>
> public static void main(String[] args) {
>
> Client client = Client.create();
> WebResource webResource = client
> .resource("http://localhost:9200/index/_search?scroll=1m&size=50 -d
> '{\"query\" : {\"match_all\" : {}}}'");
> ......
> }
> }
>
> And I got these error message:
>
> java.lang.IllegalArgumentException: Illegal character in query at
> index 52: http://localhost:9200/obd2/_search?scroll=1m&size=50 -d
> '{"query" : {"match_all" : {}}}'
> at java.net.URI.create(URI.java:859)
> at com.sun.jersey.api.client.Client.resource(Client.java:433)
> at JerseyClientGet.main(JerseyClientGet.java:20)
> Caused by: java.net.URISyntaxException: Illegal character in
> query at index 52: http://localhost:9200/index/_search?scroll=1m&size=50
> -d '{"query" : {"match_all" : {}}}'
> at java.net.URI$Parser.fail(URI.java:2829)
> at java.net.URI$Parser.checkChars(URI.java:3002)
> at java.net.URI$Parser.parseHierarchical(URI.java:3092)
> at java.net.URI$Parser.parse(URI.java:3034)
> at java.net.URI.<init>(URI.java:595)
> at java.net.URI.create(URI.java:857)
> ... 2 more
>
> The "-d" seems to be an illegal character?
> Anyone knows what's the problem with my format?
> PS: I can use java API to query, just use this RESTful for some test.
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/06200e63-aeff-4bf8-87ef-ce20ee7f0086%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.