【问题标题】:Solr get the last-indexed-time programmaticallySolr 以编程方式获取最后索引时间
【发布时间】:2017-03-24 08:39:03
【问题描述】:

我正在使用 apache solr-6.0.0

我有一个收藏:我的搜索

每当我运行增量导入时,dataimport.properties 文件中的 last_index_time 都会更新。

有没有办法使用 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/octet-stream。但是现在的错误是:

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

【问题讨论】:

  • 所以您正在寻找一种将名为data 的属性读入dataimport.properties 文件的方法?
  • 我的意思是我想从这个文件 dataimport.properties 中读取属性“last_index_time”。
  • 或者换句话说,我如何使用 solrj 来访问这个 api:localhost:8983/solr/admin/…

标签: java solr solrj


【解决方案1】:

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();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-23
    • 2011-12-26
    相关资源
    最近更新 更多