简体   繁体   中英

Get request url from solrj

I am using to solrj to query an index and at times kick off a reindex.

We are having some server issues, so I want to verify the url solrj is constructing. This is what I have tried:

public void indexSolr() throws SolrServerException, IOException {
    HttpSolrServer solr = new HttpSolrServer(solrIndexPath);
    logger.info("Indexing cp solr at " + solrIndexPath);

    // reindex to pickup new articles
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set("qt", "/" + solrDataImportPath);
    params.set("command", "full-import");
    params.set("clean", "true");
    params.set("commit", "true");
    QueryResponse response = solr.query(params);
    logger.info("index url: " + response.getRequestUrl());
}

The problem is in that last line. getRequestUrl() is always null. I know solrj is indeed calling solr, because it does in fact kick off an index request (most of the time).

How can I intercept or retrieve the url solrj is constructing for my request?

As described in How can I transform SolrQuery(SOLRJ) to URL? you can use ClientUtils.toQueryString for this matter.

In the javadoc you can see that this helper methods accepts SolrParams as input, which is what you have. To get the full URL you will need to concatenate this with the solrIndexPath you have in your code sample.

System.out.println(solrIndexPath + ClientUtils.toQueryString(params, false));

should do the trick.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM