Insert the json into elastic using java

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

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

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

Because it is raising the error you shared?

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

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

May be you have a wrong dependency. Check what gives

mvn dependency:tree

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 .

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.

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

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
  • 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\":

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