# Creating index using uri

**URL:** <https://discuss.elastic.co/t/creating-index-using-uri/22327>\
**Category:** Elasticsearch\
**Created:** [February 23, 2015, 11:56am UTC](https://discuss.elastic.co/t/creating-index-using-uri/22327 "2015-02-23T11:56:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vahith](https://avatars.discourse-cdn.com/v4/letter/v/977dab/32.png) [@vahith](https://discuss.elastic.co/u/vahith)\
**Post date:** [February 23, 2015, 11:56am UTC](https://discuss.elastic.co/t/creating-index-using-uri/22327/1 "2015-02-23T11:56:56Z")

</div>

hi,  
i am trying to create an index through url without using crul command and  
API,but it giving bad request,  
this is code snippet which i am using

```
public void sendPost() throws Exception {
     
    String url = "http://localhost:9200/product/apparel/300";
    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();

    //add reuqest header 
    con.setRequestMethod("POST");
    //con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");

    //String urlParameters = "type=slide";

    // Send post request
    con.setDoOutput(true);
    
    int responseCode = con.getResponseCode();
    System.out.println("\nSending 'POST' request to URL : " + url);
    //System.out.println("Post parameters : " + urlParameters);
    System.out.println("Response Code : " + responseCode);

    BufferedReader in = new BufferedReader(
            new InputStreamReader(con.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);
    }
    in.close();

    //print result
    System.out.println(response.toString());

}

```

could you suggest me what i am doing wrong in this code..

--  
vahith

--  
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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5ea36f46-606d-402d-b14e-d74a6285b4e9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ea36f46-606d-402d-b14e-d74a6285b4e9%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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:** [February 23, 2015, 4:01pm UTC](https://discuss.elastic.co/t/creating-index-using-uri/22327/2 "2015-02-23T16:01:36Z")

</div>

Wondering what you are trying to do here. Why not using elasticsearch Java API?

Still, some comments:

You are using POST instead of PUT  
We don’t know what you are sending to elasticsearch.  
We don’t know what response give elasticsearch.

--  
David Pilato | Technical Advocate | [Elasticsearch.com](http://Elasticsearch.com)  
@dadoonet [https://twitter.com/dadoonet](https://twitter.com/dadoonet) | @elasticsearchfr [https://twitter.com/elasticsearchfr](https://twitter.com/elasticsearchfr) | @scrutmydocs [https://twitter.com/scrutmydocs](https://twitter.com/scrutmydocs)

> Le 23 févr. 2015 à 12:56, Vahith [vahith@gmail.com](mailto:vahith@gmail.com) a écrit :
> 
> hi,  
> i am trying to create an index through url without using crul command and API,but it giving bad request,  
> this is code snippet which i am using
> 
> ```
> public void sendPost() throws Exception {
>      
> String url = "http://localhost:9200/product/apparel/300";
> URL obj = new URL(url);
> HttpURLConnection con = (HttpURLConnection) obj.openConnection();
> 
> //add reuqest header 
> con.setRequestMethod("POST");
> //con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
> 
> //String urlParameters = "type=slide";
> 
> // Send post request
> con.setDoOutput(true);
>     
> int responseCode = con.getResponseCode();
> System.out.println("\nSending 'POST' request to URL : " + url);
> //System.out.println("Post parameters : " + urlParameters);
> System.out.println("Response Code : " + responseCode);
> 
> BufferedReader in = new BufferedReader(
> new InputStreamReader(con.getInputStream()));
> String inputLine;
> StringBuffer response = new StringBuffer();
> 
> while ((inputLine = in.readLine()) != null) {
> response.append(inputLine);
> }
> in.close();
> 
> //print result
> System.out.println(response.toString());
> 
> }
> 
> ```
> 
> could you suggest me what i am doing wrong in this code..
> 
> --  
> vahith
> 
> --  
> 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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com) [mailto:elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/5ea36f46-606d-402d-b14e-d74a6285b4e9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/5ea36f46-606d-402d-b14e-d74a6285b4e9%40googlegroups.com) [https://groups.google.com/d/msgid/elasticsearch/5ea36f46-606d-402d-b14e-d74a6285b4e9%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/5ea36f46-606d-402d-b14e-d74a6285b4e9%40googlegroups.com?utm_medium=email&utm_source=footer).  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout) [https://groups.google.com/d/optout](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+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/91235915-5B46-428E-9DB1-4E067918FDA3%40pilato.fr](https://groups.google.com/d/msgid/elasticsearch/91235915-5B46-428E-9DB1-4E067918FDA3%40pilato.fr).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:30am UTC](https://discuss.elastic.co/t/creating-index-using-uri/22327/3 "2017-07-06T00:30:46Z")

</div>


