2017-03-24 45 views
0

我使用Apache Solr實現-6.0.0Solr的獲得最後索引時間編程

我有一個集合:我的搜索

每當我運行一個增量導入,在dataimport的last_index_time .properties文件正在更新。

有沒有辦法使用api調用獲取此值?如果是,那麼如何使用solrj庫讀取該值?

使用下面的API我能夠讀取該文件的內容:

http://localhost:8983/solr/my-search/admin/file?wt=json&file=dataimport.properties

樣的反應看起來:

#Thu Mar 23 10:00:01 UTC 2017 
name.last_index_time=2017-03-23 10\:00\:01 
last_index_time=2017-03-23 10\:00\:01 

使用solrj java庫,我我在做以下事情:

ModifiableSolrParams params = new ModifiableSolrParams(); 
params.set("qt", "/admin/file"); 
params.set("file", "dataimport.properties"); 
params.set("contentType", "text/plain;charset=utf-8"); 

try 
{ 
    return this.solr.query(collectionName, params); 
} 
catch (Exception e) 
{ 
    logger.info("Exception msg: " + e.getMessage()); 
} 

但是我得到錯誤說:

org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/cdi-search: Expected mime type application/octet-stream but got text/plain. #Thu Mar 23 10:00:01 UTC 2017 
name.last_index_time=2017-03-23 10\:00\:01 
last_index_time=2017-03-23 10\:00\:01 

我改變了的contentType爲application /八位字節流。但現在的錯誤是:

org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/cdi-search: Invalid version (expected 2, but 35) or the data in not in 'javabin' format 
+0

因此,您正在尋找一種方法來將'data'屬性讀入'dataimport.properties'文件中? – freedev

+0

我的意思是我想從這個文件dataimport.properties中讀取屬性「last_index_time」。 – iwekesi

+0

或換句話說,我該如何使用solrj來打這個api: http:// localhost:8983/solr/admin/zookeeper?detail = true&path =%2Fconfigs%2Fmy-search%2Fdataimport.properties – iwekesi

回答

0

SolrJ is an API,可以很容易的添加,更新和查詢Solr的集合。換句話說,索引文件並搜索它們。

不包括您正在討論的功能類型。

所有你需要的只是提交一個HTTP請求,下載你的資源,閱讀和解析它。我建議閱讀這個Java教程「Reading directly from a URL」。

URL oracle = new URL("http://localhost:8983/solr/admin/zookeeper?detail=true&path=%2Fconfigs%2Fmy-search%2Fdataimport.properties"); 
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream())); 

String inputLine; 
while ((inputLine = in.readLine()) != null) 
    System.out.println(inputLine); 
in.close();