# Insert the json into elastic using java

**URL:** <https://discuss.elastic.co/t/insert-the-json-into-elastic-using-java/140674>\
**Category:** Elasticsearch\
**Created:** [July 19, 2018, 7:29am UTC](https://discuss.elastic.co/t/insert-the-json-into-elastic-using-java/140674 "2018-07-19T07:29:03Z")\
**Posts on this page:** 11\
**Page:** 2

<div class="post-metadata">

**Author:** ![srinivasthouti](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@srinivasthouti](https://discuss.elastic.co/u/srinivasthouti)\
**Post date:** [July 25, 2018, 9:41am UTC](https://discuss.elastic.co/t/insert-the-json-into-elastic-using-java/140674/21 "2018-07-25T09:41:48Z")

</div>

hi i am getting below issue while inserting the date  
`ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Invalid format: "2018-07-25 14:28:04" is malformed at " 14:28:04"]]`

will you help in this

---

<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:** [July 25, 2018, 10:38am UTC](https://discuss.elastic.co/t/insert-the-json-into-elastic-using-java/140674/22 "2018-07-25T10:38:40Z")

</div>

Have a look at mapping for date fields. [https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html)

---

<div class="post-metadata">

**Author:** ![srinivasthouti](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@srinivasthouti](https://discuss.elastic.co/u/srinivasthouti)\
**Post date:** [July 25, 2018, 11:18am UTC](https://discuss.elastic.co/t/insert-the-json-into-elastic-using-java/140674/23 "2018-07-25T11:18:36Z")

</div>

hi i am unable to update existing record in elastic search using java can any provide me existing code please.

---

<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:** [July 25, 2018, 12:27pm UTC](https://discuss.elastic.co/t/insert-the-json-into-elastic-using-java/140674/24 "2018-07-25T12:27:19Z")

</div>

Because it is raising the error you shared?

---

<div class="post-metadata">

**Author:** ![srinivasthouti](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@srinivasthouti](https://discuss.elastic.co/u/srinivasthouti)\
**Post date:** [July 26, 2018, 2:12pm UTC](https://discuss.elastic.co/t/insert-the-json-into-elastic-using-java/140674/25 "2018-07-26T14:12:05Z")

</div>

which maven dependency i need to use i am using below one  
  
org.elasticsearch.client  
transport  
6.3.2

`TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)`

still now i am unable to import the class of PreBuiltTransportClient

---

<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:** [July 26, 2018, 2:26pm UTC](https://discuss.elastic.co/t/insert-the-json-into-elastic-using-java/140674/26 "2018-07-26T14:26:12Z")

</div>

I don't know what you are doing. But this class exists: [https://artifacts.elastic.co/javadoc/org/elasticsearch/client/transport/6.3.2/org/elasticsearch/transport/client/PreBuiltTransportClient.html](https://artifacts.elastic.co/javadoc/org/elasticsearch/client/transport/6.3.2/org/elasticsearch/transport/client/PreBuiltTransportClient.html)

May be you have a wrong dependency. Check what gives

```auto
mvn dependency:tree

```

---

<div class="post-metadata">

**Author:** ![srinivasthouti](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@srinivasthouti](https://discuss.elastic.co/u/srinivasthouti)\
**Post date:** [July 26, 2018, 2:40pm UTC](https://discuss.elastic.co/t/insert-the-json-into-elastic-using-java/140674/27 "2018-07-26T14:40:39Z")

</div>

thanks for your replay .  
i have one more question here

```
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
				.addTransportAddress(new TransportAddress(InetAddress.getByName("host1"), 9209));

```

how can i pass host1 i have my own server for elastic .

---

<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:** [July 26, 2018, 2:53pm UTC](https://discuss.elastic.co/t/insert-the-json-into-elastic-using-java/140674/28 "2018-07-26T14:53:15Z")

</div>

`host1` is whatever value you want. Your hostname, `127.0.0.1`...  
Note that I doubt that the port `9209` will work. I'd expect something like `9300`.

---

<div class="post-metadata">

**Author:** ![srinivasthouti](https://avatars.discourse-cdn.com/v4/letter/s/c5a1d2/32.png) [@srinivasthouti](https://discuss.elastic.co/u/srinivasthouti)\
**Post date:** [July 27, 2018, 7:33am UTC](https://discuss.elastic.co/t/insert-the-json-into-elastic-using-java/140674/29 "2018-07-27T07:33:07Z")

</div>

hi i am using below code to insert the data into elastic

```
String toemail="srinu@gmail.com";
		TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
				.addTransportAddress(new TransportAddress(InetAddress.getByName("apsrp06825"),9300)); //9209
		String summary="http://apsrp06825:5609/app/kibana#/dashboard/981e4030-8992-11e8-9f53-e9f85e9a2101?embed=true&_g=(refreshInterval:(display:Off,pause:!f,value:0),time:(from:now-7y,mode:relative,to:now))&_a=(description:'',filters:!(),fullScreenMode:!f,options:(darkTheme:!f,hidePanelTitles:!f,useMargins:!t),panels:!((embeddableConfig:(vis:(colors:(Count:%2370DBED,'Cumulative+Sum+of+Count':%23BF1B00),legendOpen:!t)),gridData:(h:12,i:'1',w:48,x:0,y:0),id:d251e070-898f-11e8-9f53-e9f85e9a2101,panelIndex:'1',type:visualization,version:'6.3.0'),(embeddableConfig:(vis:(colors:(No:%2364B0C8,Yes:%23CCA300),legendOpen:!t)),gridData:(h:12,i:'2',w:16,x:0,y:12),id:'0a6c8460-8990-11e8-9f53-e9f85e9a2101',panelIndex:'2',type:visualization,version:'6.3.0'),(embeddableConfig:(vis:(colors:(Count:%23CCA300),legendOpen:!t)),gridData:(h:12,i:'5',w:24,x:24,y:24),id:'5d8a49c0-8990-11e8-9f53-e9f85e9a2101',panelIndex:'5',type:visualization,version:'6.3.0'),(embeddableConfig:(vis:(colors:(Count:%231F78C1),legendOpen:!t)),gridData:(h:12,i:'6',w:24,x:0,y:48),id:'84a8a1a0-8990-11e8-9f53-e9f85e9a2101',panelIndex:'6',type:visualization,version:'6.3.0'),(embeddableConfig:(vis:(colors:(Count:%2358140C),legendOpen:!t)),gridData:(h:12,i:'7',w:24,x:0,y:36),id:'9b2354c0-8990-11e8-9f53-e9f85e9a2101',panelIndex:'7',type:visualization,version:'6.3.0'),(embeddableConfig:(vis:(colors:(Negative:%23BF1B00,Positive:%23629E51),legendOpen:!t)),gridData:(h:12,i:'8',w:16,x:16,y:12),id:'21dc45e0-8990-11e8-9f53-e9f85e9a2101',panelIndex:'8',type:visualization,version:'6.3.0'),(embeddableConfig:(vis:(colors:(www.glassdoor.com:%23806EB7,www.indeed.co.in:%23BA43A9),legendOpen:!t)),gridData:(h:12,i:'9',w:16,x:32,y:12),id:'33e32420-8990-11e8-9f53-e9f85e9a2101',panelIndex:'9',type:visualization,version:'6.3.0'),(embeddableConfig:(vis:(colors:(Count:%23052B51),legendOpen:!t)),gridData:(h:12,i:'10',w:24,x:24,y:48),id:e5a03d60-8990-11e8-9f53-e9f85e9a2101,panelIndex:'10',type:visualization,version:'6.3.0'),(embeddableConfig:(vis:(colors:(Count:%23CCA300),legendOpen:!f)),gridData:(h:12,i:'11',w:16,x:0,y:60),id:'010ef1e0-8991-11e8-9f53-e9f85e9a2101',panelIndex:'11',type:visualization,version:'6.3.0'),(embeddableConfig:(vis:(colors:(Count:%23629E51),legendOpen:!f)),gridData:(h:12,i:'12',w:16,x:16,y:60),id:'128fd740-8991-11e8-9f53-e9f85e9a2101',panelIndex:'12',type:visualization,version:'6.3.0'),(embeddableConfig:(vis:(colors:(Count:%23BF1B00),legendOpen:!f)),gridData:(h:12,i:'13',w:16,x:32,y:60),id:'24ba6a20-8991-11e8-9f53-e9f85e9a2101',panelIndex:'13',type:visualization,version:'6.3.0'),(embeddableConfig:(),gridData:(h:13,i:'14',w:16,x:0,y:72),id:'59538870-8991-11e8-9f53-e9f85e9a2101',panelIndex:'14',type:visualization,version:'6.3.0'),(embeddableConfig:(),gridData:(h:13,i:'15',w:16,x:16,y:72),id:'862ed700-8991-11e8-9f53-e9f85e9a2101',panelIndex:'15',type:visualization,version:'6.3.0'),(embeddableConfig:(spy:!n),gridData:(h:13,i:'16',w:16,x:32,y:72),id:'99a76db0-8991-11e8-9f53-e9f85e9a2101',panelIndex:'16',type:visualization,version:'6.3.0'),(embeddableConfig:(),gridData:(h:11,i:'17',w:48,x:0,y:85),id:eeb6c9e0-8991-11e8-9f53-e9f85e9a2101,panelIndex:'17',type:search,version:'6.3.0'),(embeddableConfig:(vis:(colors:(Negative:%23BF1B00,Positive:%23629E51),legendOpen:!t)),gridData:(h:12,i:'18',w:24,x:0,y:24),id:e2aadb10-89a4-11e8-9f53-e9f85e9a2101,panelIndex:'18',type:visualization,version:'6.3.0'),(embeddableConfig:(vis:(colors:(Negative:%23BF1B00,Positive:%23629E51))),gridData:(h:12,i:'19',w:24,x:24,y:36),id:f5ff2710-8bf8-11e8-9f53-e9f85e9a2101,panelIndex:'19',type:visualization,version:'6.3.0')),query:(language:lucene,query:''),timeRestore:!f,title:'Employee+Feedback',viewMode:view)";
		String data1="\"data\": { \"counter\":\"0\",\"create_ts\":\""+java.time.LocalDate.now()+" "+java.time.LocalTime.now()+"\",\"email\" :\""+toemail+"\",\"last_updated_ts\":\""+java.time.LocalDate.now()+" "+java.time.LocalTime.now()+"\",\"source_site\":\"Customer Centricity\",\"url\":\""+summary+"\"}";
		IndexResponse response = client.prepareIndex("email_subscription", "data")
		        .setSource(data1, XContentType.JSON)
		        .get();
		String _id = response.getId();

```

but i am getting below error  
`Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{MAKrcLTwQd6HKrWJF_PbsQ}{apsrp06825}{10.87.57.211:9300}]]`  
will you help in this

---

<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:** [July 27, 2018, 7:52am UTC](https://discuss.elastic.co/t/insert-the-json-into-elastic-using-java/140674/30 "2018-07-27T07:52:52Z")

</div>

You need to solve 2 problems.

The first is that you can't connect to your node using the TransportClient (note that I recommend using the rest client instead as the TransportClient will be removed in the future).

For that:

- check you can go from the machine where you code is running on [http://10.87.57.211:9200](http://10.87.57.211:9200)
- check your firewall
- check the clistername
- check your elasticsearch logs (and share them with us if you still don't succeed).

The 2nd problem is that your data1 field does not contain a valid JSON. Remove `"\"data\":`

---

<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:** [August 24, 2018, 7:52am UTC](https://discuss.elastic.co/t/insert-the-json-into-elastic-using-java/140674/31 "2018-08-24T07:52:55Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.

[Previous page](https://discuss.elastic.co/t/insert-the-json-into-elastic-using-java/140674.md?page=1)
