You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by taniamm2002 <ta...@yahoo.com> on 2013/03/29 16:02:42 UTC

trying to index postgresql database using solrj

 I'm new to solr and my question may be easy but i can't understand why

I've got table which I have already indexed in solr (so I've already have
the fields of this table in the schema.xml). SO i added 2 new rows in my
database and now I try to index again this table but this time from my java
apllication usong solrj

But it gives me all the time exeption

*1030 [pool-1-thread-1] ERROR
org.apache.solr.client.solrj.impl.StreamingUpdateSolrServer - error
java.lang.Exception: Bad Request

Bad Request

request: http://localhost:8983/solr/db/update
	at
org.apache.solr.client.solrj.impl.StreamingUpdateSolrServer$Runner.run(StreamingUpdateSolrServer.java:161)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
1030 [pool-1-thread-1] INFO
org.apache.solr.client.solrj.impl.StreamingUpdateSolrServer - finished:
org.apache.solr.client.solrj.impl.StreamingUpdateSolrServer$Runner@3f5b4f9c
Total Time Taken: 1296 milliseconds to index 100 SQL rows*

You see that at the end it shows me the right number of the rows whih means
that it reads from my database. May the problem be that the this table is
already index or I don't know.



public class ReadFromSolr {
    private  Connection conn = null;
    private static StreamingUpdateSolrServer  server;
      private Collection docs = new ArrayList();
      private int _totalSql = 0;
      private long _start = System.currentTimeMillis();

public static void main(String[] args) throws SolrServerException,
SQLException, IOException 
{ String url = "http://localhost:8983/solr/db/";

     ReadFromSolr idxer = new ReadFromSolr(url);
      try
      {
     idxer.doSqlDocuments();

     idxer.endIndexing();
      }
      catch (Exception ex)
      {
          ex.printStackTrace();
      }




   }
private void doSqlDocuments() throws SQLException {

    try {
        Class.forName("org.postgresql.Driver");

        conn = DriverManager.getConnection(
                "jdbc:postgresql://localhost:5432/plovdivbizloca",
                "postgres", "tan");
        java.sql.Statement st = null;
       st = conn.createStatement();
       ResultSet rs =   st.executeQuery("select * from pl_biz");

      while (rs.next()) {

        SolrInputDocument doc = new SolrInputDocument(); 

        Integer  id = rs.getInt("id");
        String name = rs.getString("name");
        String midname = rs.getString("midname");
        String lastname = rs.getString("lastname");
        String frlsname = rs.getString("frlsname");
        String biz_subject = rs.getString("biz_subject");
        String company_type = rs.getString("company_type");
        String obshtina = rs.getString("obshtina");
        String main_office_town = rs.getString("main_office_town");
        String address = rs.getString("address");
        String role = rs.getString("role");
        String country = rs.getString("country");
        String nace_code = rs.getString("nace_code");
        String nace_text = rs.getString("nace_text");
        String zip_code = rs.getString("zip_code");
        String phone = rs.getString("phone");
        String fax = rs.getString("fax");
        String email = rs.getString("email");
        String web = rs.getString("web");
        String location = rs.getString("location");
        String geohash = rs.getString("geohash");
        Integer popularity = rs.getInt("popularity");

        doc.addField("id", id);
        doc.addField("name", name); 
        doc.addField("midname", midname);
        doc.addField("lastnme", lastname);
        doc.addField("frlsname", frlsname);
        doc.addField("biz_subject", biz_subject);
        doc.addField("company_type", company_type);
        doc.addField("obshtina", obshtina);
        doc.addField("main_office_town", main_office_town);
        doc.addField("address", address);
        doc.addField("role", role);
        doc.addField("country", country);
        doc.addField("nace_code", nace_code);
        doc.addField("nace_text", nace_text);
        doc.addField("zip_code", zip_code);
        doc.addField("phone", phone);
        doc.addField("fax", fax);
        doc.addField("email", email);
        doc.addField("web", web);
        doc.addField("location", location);
        doc.addField("geohash", geohash);
        doc.addField("popularity", popularity);


        docs.add(doc);
         ++_totalSql;

                if (docs.size() > 100) {
             // Commit within 5 minutes.
          UpdateResponse resp = server.add(docs, 300000);
                  docs.clear();
        }
      }
    }
    catch (Exception ex) 
    {
      ex.printStackTrace();
    } 
    finally {
      if (conn != null) {
        conn.close();
      }
    }


}

 private void endIndexing() throws IOException, SolrServerException {
        if (docs.size() > 0) { // Are there any documents left over?
          server.add(docs, 300000); 
        }
        server.commit(); 


        long endTime = System.currentTimeMillis();
        log("Total Time Taken: " + (endTime - _start) +
             " milliseconds to index " + _totalSql +
            " SQL rows" );
      }


      private static void log(String msg) {
        System.out.println(msg);
      }


      private ReadFromSolr(String url) throws IOException,
SolrServerException {
          // Create a multi-threaded communications channel to the Solr
server.
      try {    
        server = new StreamingUpdateSolrServer(url,10,4 );

        server.setSoTimeout(1000);  // socket read timeout
        server.setConnectionTimeout(1000);
        server.setMaxRetries(1); 


      }
           catch (Exception ex)
           {

               ex.printStackTrace();
           }
       }





--
View this message in context: http://lucene.472066.n3.nabble.com/trying-to-index-postgresql-database-using-solrj-tp4052401.html
Sent from the Solr - User mailing list archive at Nabble.com.