【问题标题】:How do I check if solr is running or no using python?如何使用 python 检查 solr 是否正在运行?
【发布时间】:2020-08-03 15:59:38
【问题描述】:

我正在使用 pysolr 库,我想检查 solr 是否正在运行 并在 solr 和其他搜索引擎之间切换。 我发现了类似的问题,我尝试了很多建议但没有奏效。 How to know whether solr server is running or not How do i check cassandra and solr is up? Python code to check if service is running or not.?

【问题讨论】:

标签: python search solr search-engine pysolr


【解决方案1】:

一个干净的方法是使用pysolr

import pysolr

# Create a client instance. The timeout and authentication options are not required.
solr = pysolr.Solr('http://localhost:8983/solr/')

# Do a health check.
ping = solr.ping()
resp = json.loads(ping)

if resp.get('status') == 'OK':
   print('success')
  

【讨论】:

    【解决方案2】:

    如果下面的代码错误(连接被拒绝),solr 不工作。 gettingstarted 是链接中的示例集合名称。

    from urllib.request import *
    connection = urlopen('http://localhost:8983/solr/gettingstarted/select?q=mebus&wt=python')
    response = eval(connection.read())
    

    【讨论】:

      猜你喜欢
      • 2020-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-10
      • 2010-10-21
      相关资源
      最近更新 更多