Title: How to send POST request from Android to Elasticsearch
Tags: android;json;elasticsearch;android-volley
Question: I have an app, where the 'Feedback' entered by the user is stored as JSONObject. How do I send this JSONObject to elasticsearch?

Below is the code I have tried:

```     void sendFeedback() {
            String url = "http://localhost:9200/trial_feedback_index2/trial_feedback_type2 ";

/* "trial_feedback_index2" is my index and "trial_feedback_type2" is my type, where I want to store the data,  in elasticsearch.*/

            JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, url, null, new Response.Listener<JSONObject&gt;()
            {
                @Override
                public void onResponse(JSONObject response) {

                    Toast.makeText(getApplicationContext(), response.toString(), Toast.LENGTH_SHORT).show();

                    Log.d("Response", response.toString());
                    Toast.makeText(getApplicationContext(),response.toString(), Toast.LENGTH_SHORT).show();
                }
            },
                    new Response.ErrorListener()
                    {
                        @Override
                        public void onErrorResponse(VolleyError error) {
                            // error
                            // Log.d("Error.Response", response);
                        }
                    }
            ) {
                @Override
                protected Map<String, String&gt; getParams()
                {
                    Map<String, String&gt; params = new HashMap<String, String&gt;();
                    params.put("Feedback", feedbackQAJsonObjOuter.toString());


                    return params;
                }
            };
            queue.add(postRequest);
    // add it to the RequestQueue


        }
```

How do I make it work?

Thanks!

Comment: `http://localhost:9200/` will not work. That needs to be the external IP of your server, but you've given localhost of your Android device, not running Elasticsearch

Comment: What is the problem? What errors did you get? It's difficult trying to help someone when you don't know what's their exact problem


Here is another answer: You can use ```HashMap``` to store your data and then convert it to ```JSONObject```. After that pass that ```JSONObject``` to request:

```HashMap<String,String&gt; hashMap = new HashMap<&gt;();
hashMap.put("feedbackKey","value");
JSONObject jsonObject = new JSONObject(hashMap);

JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, url, jsonObject, new Response.Listener<JSONObject&gt;()
            {..... 
..... Your other code
```


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:11/05/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<android><json><elasticsearch><android-volley>', 'Title': 'How to send POST request from Android to Elasticsearch', 'ViewCount': 965, 'id': 53148870, 'user_AboutMe': None, 'user_AccountId': 13879959.0, 'user_DisplayName': 'Lemmy', 'user_Reputation': 223.0, 'user_Views': 29.0, 'user_id': 10020557.0}}