# Searching with uri request

**URL:** <https://discuss.elastic.co/t/searching-with-uri-request/10254>\
**Category:** Elasticsearch\
**Created:** [January 7, 2013, 8:50pm UTC](https://discuss.elastic.co/t/searching-with-uri-request/10254 "2013-01-07T20:50:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![emj11](https://avatars.discourse-cdn.com/v4/letter/e/ecc23a/32.png) [@emj11](https://discuss.elastic.co/u/emj11)\
**Post date:** [January 7, 2013, 8:50pm UTC](https://discuss.elastic.co/t/searching-with-uri-request/10254/1 "2013-01-07T20:50:38Z")

</div>

This will seem like a silly question, but I don't have much experience with  
http requests/responses.  
I am trying to run a query against elastic search using the Java  
URLConnection API:

The following gives me all documents:  
URL es = new URL("[http://localhostb:9200/messages/chat/\_search](http://localhostb:9200/messages/chat/_search));  
URLConnection yc = es.openConnection();

but this returns an error  
URL es = new URL("[http://localhostb:9200/messages/chat/\_search](http://localhostb:9200/messages/chat/_search) -d  
'{"query":{"term":{"from\_jid":"from0"}}}'");  
URLConnection yc = es.openConnection();

Can someone tell me what's wrong with this request?

Thanks.

--

---

<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:** [January 7, 2013, 9:21pm UTC](https://discuss.elastic.co/t/searching-with-uri-request/10254/2 "2013-01-07T21:21:11Z")

</div>

The last code is not a valid URL but looks like a curl request.  
You can not do that that way.

If you want to reinvent the wheel (i mean using Java URL API), you will have to manage the payload send process.

Why not using ES or REST Java client?

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

Le 7 janv. 2013 à 21:50, emj11 [jagdhar@gmail.com](mailto:jagdhar@gmail.com) a écrit :

This will seem like a silly question, but I don't have much experience with http requests/responses.  
I am trying to run a query against elastic search using the Java URLConnection API:

The following gives me all documents:  
URL es = new URL("[http://localhostb:9200/messages/chat/\_search](http://localhostb:9200/messages/chat/_search));  
URLConnection yc = es.openConnection();

but this returns an error  
URL es = new URL("[http://localhostb:9200/messages/chat/\_search](http://localhostb:9200/messages/chat/_search) -d '{"query":{"term":{"from\_jid":"from0"}}}'");  
URLConnection yc = es.openConnection();

Can someone tell me what's wrong with this request?

Thanks.

--

--

---

<div class="post-metadata">

**Author:** ![emj11](https://avatars.discourse-cdn.com/v4/letter/e/ecc23a/32.png) [@emj11](https://discuss.elastic.co/u/emj11)\
**Post date:** [January 7, 2013, 9:52pm UTC](https://discuss.elastic.co/t/searching-with-uri-request/10254/3 "2013-01-07T21:52:09Z")

</div>

Hi David, thanks for your response. Not a fan of reinventing the wheel.  
I would like to make these searches over http rather than tcp. If I use ES  
than it will be over tcp.

Sounds like I should use REST. But how do I use REST within Java to talk  
to the ES Server?

Thanks.

--

---

<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:** [January 8, 2013, 5:31am UTC](https://discuss.elastic.co/t/searching-with-uri-request/10254/4 "2013-01-08T05:31:51Z")

</div>

Have a look at [https://github.com/searchbox-io/Jest](https://github.com/searchbox-io/Jest)  
I'm also working on a SPORE specification for ES but it's not ready yet: [https://github.com/dadoonet/spore-elasticsearch](https://github.com/dadoonet/spore-elasticsearch)

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

Le 7 janv. 2013 à 22:52, emj11 [jagdhar@gmail.com](mailto:jagdhar@gmail.com) a écrit :

Hi David, thanks for your response. Not a fan of reinventing the wheel.  
I would like to make these searches over http rather than tcp. If I use ES than it will be over tcp.

Sounds like I should use REST. But how do I use REST within Java to talk to the ES Server?

## Thanks.

--

---

<div class="post-metadata">

**Author:** ![emj11](https://avatars.discourse-cdn.com/v4/letter/e/ecc23a/32.png) [@emj11](https://discuss.elastic.co/u/emj11)\
**Post date:** [January 8, 2013, 6:59pm UTC](https://discuss.elastic.co/t/searching-with-uri-request/10254/5 "2013-01-08T18:59:44Z")

</div>

Ok. Thanks David.

--

---

<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:57am UTC](https://discuss.elastic.co/t/searching-with-uri-request/10254/6 "2017-07-06T02:57:21Z")

</div>


