# ES GET Query in C#

**URL:** <https://discuss.elastic.co/t/es-get-query-in-c/9122>\
**Category:** Elasticsearch\
**Created:** [September 24, 2012, 5:37pm UTC](https://discuss.elastic.co/t/es-get-query-in-c/9122 "2012-09-24T17:37:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheOutlander\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theoutlander_2/32/2614_2.png) [@TheOutlander\_2](https://discuss.elastic.co/u/TheOutlander_2)\
**Post date:** [September 24, 2012, 5:37pm UTC](https://discuss.elastic.co/t/es-get-query-in-c/9122/1 "2012-09-24T17:37:45Z")

</div>

I'm not sure how to send a GET request with a JSON payload in C#. The  
framework will throw an error when I try to get a RequestStream to write to  
it.

Can someone explain how I can emulate the CURL GET command (curl -GET  
"[http://localhost:9200/index/type/\_search](http://localhost:9200/index/type/_search)" -d "{ "query" : .... }") in C#?

I was looking at NEST and it seems like it uses Thrift. Is there a  
requirement that in C# I would need to use Thrift instead of an HTTP GET  
Request with a payload??

Also, I've heard that GET with a payload is invalid, but read somewhere  
that HTTP RFC says that it's ok.

Thanks,  
Nick

--

---

<div class="post-metadata">

**Author:** ![Raffaele\_Sena](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raffaele_sena/32/1759_2.png) [@Raffaele\_Sena](https://discuss.elastic.co/u/Raffaele_Sena)\
**Post date:** [September 24, 2012, 5:45pm UTC](https://discuss.elastic.co/t/es-get-query-in-c/9122/2 "2012-09-24T17:45:48Z")

</div>

POST should work too.

On Mon, Sep 24, 2012 at 10:37 AM, TheOutlander [theoutlander@gmail.com](mailto:theoutlander@gmail.com) wrote:

> I'm not sure how to send a GET request with a JSON payload in C#. The  
> framework will throw an error when I try to get a RequestStream to write to  
> it.
> 
> Can someone explain how I can emulate the CURL GET command (curl -GET  
> "[http://localhost:9200/index/type/\_search](http://localhost:9200/index/type/_search)" -d "{ "query" : .... }") in C#?
> 
> I was looking at NEST and it seems like it uses Thrift. Is there a  
> requirement that in C# I would need to use Thrift instead of an HTTP GET  
> Request with a payload??
> 
> Also, I've heard that GET with a payload is invalid, but read somewhere  
> that HTTP RFC says that it's ok.
> 
> Thanks,  
> Nick
> 
> --

--

---

<div class="post-metadata">

**Author:** ![TheOutlander\_2](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theoutlander_2/32/2614_2.png) [@TheOutlander\_2](https://discuss.elastic.co/u/TheOutlander_2)\
**Post date:** [September 24, 2012, 6:14pm UTC](https://discuss.elastic.co/t/es-get-query-in-c/9122/3 "2012-09-24T18:14:18Z")

</div>

I tried that in curl but I don't get any hits.... I'm not sure if it works.  
Have you tried it?

Thanks for the quick response!

On Monday, September 24, 2012 10:45:50 AM UTC-7, Raffaele Sena wrote:

> POST should work too.
> 
> On Mon, Sep 24, 2012 at 10:37 AM, TheOutlander \<[theout...@gmail.com](mailto:theout...@gmail.com)\<javascript:\>\>  
> wrote:
> 
> > I'm not sure how to send a GET request with a JSON payload in C#. The  
> > framework will throw an error when I try to get a RequestStream to write  
> > to  
> > it.
> > 
> > Can someone explain how I can emulate the CURL GET command (curl -GET  
> > "[http://localhost:9200/index/type/\_search](http://localhost:9200/index/type/_search)" -d "{ "query" : .... }") in  
> > C#?
> > 
> > I was looking at NEST and it seems like it uses Thrift. Is there a  
> > requirement that in C# I would need to use Thrift instead of an HTTP GET  
> > Request with a payload??
> > 
> > Also, I've heard that GET with a payload is invalid, but read somewhere  
> > that HTTP RFC says that it's ok.
> > 
> > Thanks,  
> > Nick
> > 
> > --

--

---

<div class="post-metadata">

**Author:** ![Raffaele\_Sena](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raffaele_sena/32/1759_2.png) [@Raffaele\_Sena](https://discuss.elastic.co/u/Raffaele_Sena)\
**Post date:** [September 24, 2012, 7:03pm UTC](https://discuss.elastic.co/t/es-get-query-in-c/9122/4 "2012-09-24T19:03:59Z")

</div>

yup! Not sure if the Content-Type matters, since what I am sending is  
NOT x-www-form-urlencoded 🙂

sh\> curl -v -i [http://localhost:9200/\_search](http://localhost:9200/_search) -XPOST -d  
'{"query":{"query\_string":{"query":"pdf"}}}'

> POST /\_search HTTP/1.1  
> User-Agent: curl/7.15.5 (x86\_64-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5  
> Host: localhost:9200  
> Accept: _/_  
> Content-Length: 42  
> Content-Type: application/x-www-form-urlencoded
> 
> {"query":{"query\_string":{"query":"pdf"}}}HTTP/1.1 200 OK  
> HTTP/1.1 200 OK  
> \< Content-Type: application/json; charset=UTF-8  
> Content-Type: application/json; charset=UTF-8  
> \< Content-Length: 1930  
> Content-Length: 1930

{"took":11,"timed\_out":false,"\_shards":{"total":15,"successful":15,"failed":0},"hits":{"total":4317,"max\_score":2.3064148,"hits":[{"\_index":"names","\_type":"document","\_id":"-3069932108639787315","\_score":2.3064148,  
"\_source" : {...}}]}

On Mon, Sep 24, 2012 at 11:14 AM, TheOutlander [theoutlander@gmail.com](mailto:theoutlander@gmail.com) wrote:

> I tried that in curl but I don't get any hits.... I'm not sure if it works.  
> Have you tried it?
> 
> Thanks for the quick response!
> 
> On Monday, September 24, 2012 10:45:50 AM UTC-7, Raffaele Sena wrote:
> 
> > POST should work too.
> > 
> > On Mon, Sep 24, 2012 at 10:37 AM, TheOutlander [theout...@gmail.com](mailto:theout...@gmail.com)  
> > wrote:
> > 
> > > I'm not sure how to send a GET request with a JSON payload in C#. The  
> > > framework will throw an error when I try to get a RequestStream to write  
> > > to  
> > > it.
> > > 
> > > Can someone explain how I can emulate the CURL GET command (curl -GET  
> > > "[http://localhost:9200/index/type/\_search](http://localhost:9200/index/type/_search)" -d "{ "query" : .... }") in  
> > > C#?
> > > 
> > > I was looking at NEST and it seems like it uses Thrift. Is there a  
> > > requirement that in C# I would need to use Thrift instead of an HTTP GET  
> > > Request with a payload??
> > > 
> > > Also, I've heard that GET with a payload is invalid, but read somewhere  
> > > that HTTP RFC says that it's ok.
> > > 
> > > Thanks,  
> > > Nick
> > > 
> > > --
> 
> --

--

---

<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, 3:11am UTC](https://discuss.elastic.co/t/es-get-query-in-c/9122/5 "2017-07-06T03:11:41Z")

</div>


