You should read this: http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/index_.html <http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/index_.html> You need to create a Client: http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/client.html <http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/client.html>You need to create a JSON from your properties. See: http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/index_.html#helpers <http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/index_.html#helpers> Then you should use a Bulk to index all those documents: See: http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/bulk.html <http://www.elasticsearch.org/guide/en/elasticsearch/client/java-api/current/bulk.html> Something like this: BulkRequestBuilder bulkRequest = client.prepareBulk(); while(result.next() && count<1000){ // YOUR ORACLE stuff here // either use client#prepare, or use Requests# to directly build index/delete requests bulkRequest.add(client.prepareIndex("indexname", "typename", id) .setSource(jsonBuilder() .startObject() .field("deliveryid", deliveryid) .field("msgid", msgid) // Add your other fields .endObject() ) ); } BulkResponse bulkResponse = bulkRequest.execute().actionGet(); Do that every 1000 or 10000 documents. Don’t send too many requests within the same bulk. It will use too much memory and probably will slow down your indexation rate.
HTH -- David Pilato | Technical Advocate | Elasticsearch.com @dadoonet <https://twitter.com/dadoonet> | @elasticsearchfr <https://twitter.com/elasticsearchfr> | @scrutmydocs <https://twitter.com/scrutmydocs> > Le 7 janv. 2015 à 16:41, Marian Valero <[email protected]> a écrit : > > I have this: > > public static void main(String args[]) throws SQLException { > > int count=0; > > String url = "jdbc:oracle:thin:eso:1521:eso"; > > Properties props = new Properties(); > props.setProperty("user", "eso"); > props.setProperty("password", "eso"); > > Connection conn = DriverManager.getConnection(url,props); > > String sql ="select * from responselog"; > > PreparedStatement preStatement = conn.prepareStatement(sql); > > ResultSet result = preStatement.executeQuery(); > > Timestamp timestamp = null; > > while(result.next() && count<1000){ > count++; > String id = result.getString("id"); > String deliveryid = result.getString("deliveryid"); > String msgid = result.getString("msgid"); > String rspdate = result.getString("rspdate"); > String parsedresponse = result.getString("parsedresponse"); > String shortcode = result.getString("shortcode"); > String insid = result.getString("insid"); > String mobilenumber = result.getString("mobilenumber"); > String rawresponse = result.getString("rawresponse"); > > System.out.println("Responselog from Oracle : "+ > result.getString("id")+" "+result.getString("deliveryid")+" > "+result.getString("msgid")+" "+result.getString("rspdate")+" > "+result.getString("parsedresponse")+" "+result.getString("shortcode")+" > "+result.getString("insid")+" "+result.getString("mobilenumber")+" > "+result.getString("rawresponse")); > } > System.out.println("done"); > } > > I'm reading 1000 registers of the table and I want to insert this in > Elasticsearch, but this is an example, I want to do that for all registers of > my database, this is millions of registers. I don't understand very well that > you send me. > > -- > 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 [email protected] > <mailto:[email protected]>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elasticsearch/8391d264-86c0-48e5-ac90-613cc9f59628%40googlegroups.com > > <https://groups.google.com/d/msgid/elasticsearch/8391d264-86c0-48e5-ac90-613cc9f59628%40googlegroups.com?utm_medium=email&utm_source=footer>. > For more options, visit 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/A69A19D5-CEC2-4A3E-9CBC-5024438288AE%40pilato.fr. For more options, visit https://groups.google.com/d/optout.
