Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 连接到本地主机上运行的solr服务器_Python_Solr_Connection_Server_Localhost - Fatal编程技术网

Python 连接到本地主机上运行的solr服务器

Python 连接到本地主机上运行的solr服务器,python,solr,connection,server,localhost,Python,Solr,Connection,Server,Localhost,我正在尝试使用教程连接到服务器。此时,我确信我的solr设置正确。我能跑 > solr start -p 8983 它似乎启动了一些事情 果然 > solr status Solr process 31421 running on port 8983 所以现在在我的python代码中,我尝试了我认为应该是基本连接脚本的东西 import solr host = "http://localhost:8983/solr" # also tried # host = "http://

我正在尝试使用教程连接到服务器。此时,我确信我的solr设置正确。我能跑

> solr start -p 8983
它似乎启动了一些事情

果然

> solr status
Solr process 31421 running on port 8983
所以现在在我的python代码中,我尝试了我认为应该是基本连接脚本的东西

import solr
host = "http://localhost:8983/solr"

# also tried
# host = "http://localhost:8983"

# also tried
# host = "http://127.0.0.1:8983/solr"

# also tried
# host = "http://127.0.0.1:8983"

connection = solr.SolrConnection(host)

try:
    connection.add(
        id= 1,
        title= "Lucene in Action",
        author= ['Zack', 'Hank Hill']
    )
except Exception as e:
    import pdb
    pdb.set_trace()

connection.commit()
我的代码从未到达connection.commit(),而是到达异常中的调试点。查看异常e

HTTP code=404, Reason=Not Found, body=<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>Error 404 Not Found</title>
</head>
<body><h2>HTTP ERROR 404</h2>
    <p>Problem accessing /solr/update. Reason:
    <pre>    Not Found</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>
</body>
</html>
每个异常都是相同的,404错误

编辑2:我能够

import solr

# create a connection to a solr server
s = solr.SolrConnection('http://localhost:8983/solr/test')

# add 2 documents to the index
s.add(id=1, title='Lucene in Action', author=['bob', 'asdf'])
s.add(id=2, title='test2', author=['Joe', 'test'])
s.commit()

# do a search
response = s.query('joe')
for hit in response.results:
    print hit['title']

而且它已连接,因此我非常确定solr服务器正在该端口上运行?

要使用solr进行索引,您还需要创建一个核心,并确保在url中使用该核心。例如,启动solr后,运行此命令以创建名为test的核心:

solr-create-c测试

创建之后,您应该会在solr admin页面中看到它的列表。要使用它,您只需将该核心名称添加到您的连接url。python代码的简单示例:


此处的更多信息

如果打开浏览器并转到同一url“”,您会看到什么?如果是远程服务器,您可以使用wget或curl测试对url“”的访问权限。在浏览器中尝试命令:wget“好的,是的,我打开了”:8983/solr,可以看到solr web应用程序
> telnet localhost 8983
import solr

# create a connection to a solr server
s = solr.SolrConnection('http://localhost:8983/solr/test')

# add 2 documents to the index
s.add(id=1, title='Lucene in Action', author=['bob', 'asdf'])
s.add(id=2, title='test2', author=['Joe', 'test'])
s.commit()

# do a search
response = s.query('joe')
for hit in response.results:
    print hit['title']