2013-03-28 31 views
1

我曾經使用Whoosh作爲搜索後端,但現在我切換到elasticsearch並試圖使事情正常工作。使用Haystack設置elasticsearch

當試圖重建索引我得到的錯誤:

requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8000): Max retries exceeded with url: /_bulk?op_type=create (Caused by <class 'socket.error'>: [Errno 61] Connection refused) 

以下是在我的settings.py:

HAYSTACK_CONNECTIONS = { 
    'default': { 
     'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', 
     'URL': 'http://localhost:8000/', 
     'INDEX_NAME': 'haystack', 
    }, 
} 

我的問題是,是用來做什麼的網址和做什麼我放在這裏?我在本地開發事務,並部署在Heroku上。

+0

爲ES的默認端口是9200。所以,除非你重新配置它到8000,只需切換你的端口號。 –

回答

4

的端口應9200

HAYSTACK_CONNECTIONS = { 
'default': { 
     'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine', 
     'URL': 'http://127.0.0.1:9200/', 
     'INDEX_NAME': 'haystack', 
    }, 
} 

而且,你必須確保你正在使用的草垛的開發版本(2.0)。


編輯:

你可能想首先要確保ElasticSearch通過執行以下命令運行:

curl -XGET 'http://127.0.0.1:9200/my_index/_mapping?pretty=1' 
+0

我跟着你的答案,但我仍然得到上述錯誤。 – picomon

+0

如果你得到完全相同的錯誤'requests.exceptions.ConnectionError:HTTPConnectionPool(host ='localhost',port = 8000)',那麼你把代碼放在錯誤的地方(它應該在'settings'中項目和取決於你使用的服務器,你應該重新啓動它)。如果錯誤顯示requests.exceptions.ConnectionError:HTTPConnectionPool(host ='localhost',port:9200)',那麼ElasticSearch沒有在您的機器上運行,或者可能性較小,它正在另一個端口上工作。 –

+0

您可以通過在終端執行以下命令來測試ElasticSearch是否正在運行:'curl -XGET'http://127.0.0.1:9200/my_index/_mapping?pretty = 1'' –