我正在學習本教程,對任何資料庫(包括 Elasticsearch)都是全新的。
我的代碼
client = Elasticsearch()
indexName = "art"
client.indices.create(index=indexName)
顯示以下錯誤(根據本書,它不應該)
ValueError Traceback(最近一次通話最后)/var/folders/s5/dhdrwvbj5bs4m9nld9bp43400000gn/T/ipykernel_49947/868473428.py in ----> 1 client = Elasticsearch() 2 indexName = "art" 3 client.indices.create(index =索引名稱)
~/opt/anaconda3/lib/python3.9/site-packages/elasticsearch/_sync/client/ init .py init(自我、主機、cloud_id、api_key、basic_auth、bearer_auth、opaque_id、標頭、connections_per_node、http_compress、verify_certs、ca_certs、client_cert、client_key、ssl_assert_hostname、ssl_assert_fingerprint、ssl_version、ssl_context、ssl_show_warn、transport_class、request_timeout_、node_class、node_pool_class、隨機, dead_node_backoff_factor, max_dead_node_backoff, serializer, serializers, default_mimetype, max_retries, retry_on_status, retry_on_timeout, sniff_on_start, sniff_before_requests, sniff_on_node_failure, sniff_timeout, min_delay_between_sniffing, sniffed_node_callback, meta_header, timeout, randomize_hosts, host_info_callback, sniffer_timeout, sniff_on_connection_fail, http_auth, maxsize, _transport) 189 ) - > 無:如果 hosts 為 None 且 cloud_id 為 None 且 _transport 為 None,則為 190:--> 191 raise ValueError("必須指定 'hosts' 或 'cloud_id'") 192 193 如果超時不是默認值:
ValueError:必須指定“hosts”或“cloud_id”
當我通過終端啟動 Elasticsearch 時,我可以打開 localhost:9200。我還更改了 elasticsearch.yml中的#network.host: 0.0.0.0。
請你幫助我好嗎?你能解釋一下,這段代碼到底是做什么的?
謝謝!
uj5u.com熱心網友回復:
看看檔案,如果你想在本地連接到 Elasticsearch,基本上你需要使用下面的;
client = Elasticsearch("http://localhost:9200")
indexName = "art"
client.indices.create(index=indexName)
client告訴這個實體需要連接到哪里才能與 Elasticsearch 對話indexName是您要使用的索引的名稱- 最后一行是動作,你想要做什么,即創建你定義的索引
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/526563.html
標籤:Python弹性搜索
上一篇:org.springframework.beans.factory.BeanCreationException:創建類路徑資源中定義的名稱為“OpensearchClient”的bean時出錯
