Solrj full-import not working

2019-09-14 10:14发布

I configured solr server on my Glassfish and everything works well. The problem is when I try to make reindex call using Solrj in my Java application.

I'm using delta import via full import but it works well outside Solrj so I suppose there isn't problem

http://wiki.apache.org/solr/DataImportHandlerDeltaQueryViaFullImport

When I call

http://localhost:8787/solr-4.2.1/db/dataimport?command=full-import&clean=true

then reindex is correct and I see my new results. The problems starts when I do it using Solrj

    SolrServer solr = new HttpSolrServer("http://localhost:8787/solr-4.2.1/db");

    ModifiableSolrParams params = new ModifiableSolrParams();

    params.set("qt", "/dataimport");
    params.set("command", "full-import&clean=true");

    QueryResponse response = null;

    try {
        response = solr.query(params);
    } catch (SolrServerException e1) {
        e1.printStackTrace();
    } 
    System.out.println(response);

The resposne seems ok

{responseHeader={status=0,QTime=0},initArgs={defaults={config=db-data-config.xml}},command=full-import&clean=true,status=idle,importResponse=,statusMessages={Total Requests made to DataSource=4, Total Rows Fetched=5, Total Documents Skipped=0, Full Dump Started=2013-07-09 09:42:34, =Indexing completed. Added/Updated: 5 documents. Deleted 0 documents., Committed=2013-07-09 09:42:35, Total Documents Processed=5, Time taken=0:0:0.390},WARNING=This response format is experimental.  It is likely to change in the future.}

All the info there are correct - it should made 4 requests to database and proceed all 5 rows to index. But when I look at my indexed data (using URL or Solrj)

http://localhost:8787/solr-4.2.1/db/search/?q=*:*

I see there is still old index. For example I changed one row in database, called reindex using Solrj and I see no changes in index. When I call URL command

http://localhost:8787/solr-4.2.1/db/dataimport?command=full-import&clean=true

the reindex runs correctly and I see changed values in Solr (using URL or Solrj). I tried to add solr.commit() to my code but it didn't help. What am I doing wrong? Why I see no changes using Solrj but everything is fine using URL?

标签: solr solrj
1条回答
贪生不怕死
2楼-- · 2019-09-14 11:05

Few things you can check for -

  • command only full-import params.set("command", "full-import");
  • you can add clean=true as seperate param
  • Also, check if you need to pass commit=true as a param to have the documents committed.
  • Also, DIH calls are async to you would get a response back fast, however the process might still be running in the backend.
查看更多
登录 后发表回答