Curl -xget works, but fail when use RESTful client in java
I tried to send http/get to my elasticsearch server.if I query: curl 'http://localhost:9200/index/_search?scroll=1msize=50pretty' -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=1msize=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=1msize=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=1msize=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 elasticsearch+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/c7495d9d-bace-4c09-9f58-6b49c4888cc1%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Curl -xget works, but fail when use RESTful client in java
Got the answer! It turns out that just add an between the url and encoded json body. String string1={\query\ : {\match_all\ : {}}}; WebResource webResource = client .resource(http://localhost:9200/obd2/_search?scroll=1msize=50+ URLEncoder.encode(string1)); then the http/get was successfully transferred and return the query result. On Friday, August 1, 2014 2:10:26 PM UTC-7, Brian wrote: Well, the curl command uses the -d option to specify the content data to pass to the server. It is not part of the URL. Your mistake is trying to take a curl command-line and treat the entire thing as a URL, when in fact the URL is only part of the request. I don't know how the JerseyGetClient works, but here is one example I found that might help, or at least provide a starting point. http://crunchify.com/create-very-simple-jersey-rest-service-and-send-json-data-from-java-client/ The idea is that a typical HTTP request in Java accepts the URL at one string, or perhaps even two strings (the server/port, and then the URI path), and then the content type and data as separately specified values elsewhere in the API. Brian On Friday, August 1, 2014 4:59:10 PM UTC-4, Chia-Eng Chang wrote: 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=1msize=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=1msize=50pretty' -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=1msize=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=1msize=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=1msize=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 elasticsearch+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/c5f9d940-4301-4423-9861-3dbb6da781cb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Remote access through SSH
I tried curl -XGET http://IPADDRESS:9200/.. http://IPADDRESS:9200/.. but it failed. Actually I cant even telnet port 9200 on my machine. My guess is that elasticsearch port 9200 is hidden behind ssh port 22. So I use ssh tunnel forwarding port 9200 on the server to my machine. Like : ssh -Lmy-port:target-machine:target-port user@target-machine Then I can simply apply curl -get localhost:9200 to query elasticsearch on my cloud server. The java api transpot client might need the same setting to make it work. On Wednesday, July 30, 2014 5:48:28 PM UTC-7, Mark Walkom wrote: You can also curl from your local machine to the server, without having to SSH to it - curl -XGET http://IPADDRESS:9200/ You don't need to provide SSH credentials for that transport client example. Regards, Mark Walkom Infrastructure Engineer Campaign Monitor email: ma...@campaignmonitor.com javascript: web: www.campaignmonitor.com On 31 July 2014 10:35, Chia-Eng Chang chia...@uci.edu javascript: wrote: Thank you for the links. Yeah, I am new to ES. (and http rest) What I understand is that if I want to get the index documents on my SSH server, I can SSH log in the server. And then rest http get from localhost:9200. Could you explain more about use SSH directly for it? I think what I want to do is close to this transport client example http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/client.html#transport-client But I have to provide ssh credential. On Wednesday, July 30, 2014 4:47:22 PM UTC-7, Mark Walkom wrote: You may want to look at http://www.elasticsearch. org/guide/en/elasticsearch/reference/current/search.html If you are just learning ES, then check out http:// exploringelasticsearch.com/ Regards, Mark Walkom Infrastructure Engineer Campaign Monitor email: ma...@campaignmonitor.com web: www.campaignmonitor.com On 31 July 2014 09:35, Chia-Eng Chang chia...@uci.edu wrote: Thanks @Mark I have a public key on server and I know how to SSH to server then get the index from localhost:9200. But what I want to do is remotely obtain the index on the SSH server (which I know its public IP) On Wednesday, July 30, 2014 3:56:04 PM UTC-7, Mark Walkom wrote: You need to use SSH directly for it, curl won't work. ssh user@host -i ~/.ssh/id_rsa.pub Assuming you have a public key on the server. Regards, Mark Walkom Infrastructure Engineer Campaign Monitor email: ma...@campaignmonitor.com web: www.campaignmonitor.com On 31 July 2014 08:47, Chia-Eng Chang chia...@uci.edu wrote: About the HTTP API, I wonder if I want to remote access a cluster on SSH server, what should I include in my http rest command: example as mapping: curl -XGET ' http://localhost:9200/ index /_mapping/ type ' I tried something like below but got failed: curl -XGET -u user_name: --key ~/.ssh/id_rsa --pubkey ~/.ssh/id_rsa.pub 'xx.xxx.xxx.xxx:9200/index/_mapping/type' Is there anyone knows the solution? -- 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/31b4e835-8ebb-4dc7-bc2b-c8fa09414f12%40goo glegroups.com https://groups.google.com/d/msgid/elasticsearch/31b4e835-8ebb-4dc7-bc2b-c8fa09414f12%40googlegroups.com?utm_medium=emailutm_source=footer . For more options, visit https://groups.google.com/d/optout. -- 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/d6404d32-6b0f-4670-8626-f38b1284809d% 40googlegroups.com https://groups.google.com/d/msgid/elasticsearch/d6404d32-6b0f-4670-8626-f38b1284809d%40googlegroups.com?utm_medium=emailutm_source=footer . For more options, visit https://groups.google.com/d/optout. -- 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/3d1ad9da-e964-482b-89ac-75ad35b68227%40googlegroups.com https://groups.google.com/d/msgid/elasticsearch/3d1ad9da-e964-482b-89ac-75ad35b68227%40googlegroups.com?utm_medium=emailutm_source=footer . For more options, visit https://groups.google.com/d/optout. -- 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+unsubscr
Remote access through SSH
About the HTTP API, I wonder if I want to remote access a cluster on SSH server, what should I include in my http rest command: example as mapping: curl -XGET ' http://localhost:9200/ index /_mapping/ type ' I tried something like below but got failed: curl -XGET -u user_name: --key ~/.ssh/id_rsa --pubkey ~/.ssh/id_rsa.pub 'xx.xxx.xxx.xxx:9200/index/_mapping/type' Is there anyone knows the solution? -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/31b4e835-8ebb-4dc7-bc2b-c8fa09414f12%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Remote access through SSH
Thank you for the links. Yeah, I am new to ES. (and http rest) What I understand is that if I want to get the index documents on my SSH server, I can SSH log in the server. And then rest http get from localhost:9200. Could you explain more about use SSH directly for it? I think what I want to do is close to this transport client example http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/client.html#transport-client But I have to provide ssh credential. On Wednesday, July 30, 2014 4:47:22 PM UTC-7, Mark Walkom wrote: You may want to look at http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search.html If you are just learning ES, then check out http://exploringelasticsearch.com/ Regards, Mark Walkom Infrastructure Engineer Campaign Monitor email: ma...@campaignmonitor.com javascript: web: www.campaignmonitor.com On 31 July 2014 09:35, Chia-Eng Chang chia...@uci.edu javascript: wrote: Thanks @Mark I have a public key on server and I know how to SSH to server then get the index from localhost:9200. But what I want to do is remotely obtain the index on the SSH server (which I know its public IP) On Wednesday, July 30, 2014 3:56:04 PM UTC-7, Mark Walkom wrote: You need to use SSH directly for it, curl won't work. ssh user@host -i ~/.ssh/id_rsa.pub Assuming you have a public key on the server. Regards, Mark Walkom Infrastructure Engineer Campaign Monitor email: ma...@campaignmonitor.com web: www.campaignmonitor.com On 31 July 2014 08:47, Chia-Eng Chang chia...@uci.edu wrote: About the HTTP API, I wonder if I want to remote access a cluster on SSH server, what should I include in my http rest command: example as mapping: curl -XGET ' http://localhost:9200/ index /_mapping/ type ' I tried something like below but got failed: curl -XGET -u user_name: --key ~/.ssh/id_rsa --pubkey ~/.ssh/id_rsa.pub 'xx.xxx.xxx.xxx:9200/index/_mapping/type' Is there anyone knows the solution? -- 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/31b4e835-8ebb-4dc7-bc2b-c8fa09414f12% 40googlegroups.com https://groups.google.com/d/msgid/elasticsearch/31b4e835-8ebb-4dc7-bc2b-c8fa09414f12%40googlegroups.com?utm_medium=emailutm_source=footer . For more options, visit https://groups.google.com/d/optout. -- 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/d6404d32-6b0f-4670-8626-f38b1284809d%40googlegroups.com https://groups.google.com/d/msgid/elasticsearch/d6404d32-6b0f-4670-8626-f38b1284809d%40googlegroups.com?utm_medium=emailutm_source=footer . For more options, visit https://groups.google.com/d/optout. -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/3d1ad9da-e964-482b-89ac-75ad35b68227%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Use java Api to set a document's field as _id
I want to ask if the unique field _id be assigned by certain field within document. I see with Rest, it can achieve by path: { tweet : { _id : { path : post_id } } } But if I want to do it with java API, is there any way to achieve it? MapString, Object MapA= new HashMapString, Object(); MapA=MapProcessor(MapA); client.prepareIndex(index,type).setSource(MapA).execute().actionGet(); How could I modify my code to assign certain field in Map to become _id of this type? -- 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+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/3f9fe5df-cd96-4083-b21b-610dbe265e38%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.