我想从Elastic Search Cluster
应用程序访问rails
中的数据。可以说服务器正在http://localhost:9200
上运行,我想访问端点http://localhost:9200/location/type
。
以下是documentation,并遇到了此示例:
require 'elasticsearch'
client = Elasticsearch::Client.new log: true
client.cluster.health
client.index index: 'my-index', type: 'my-document', id: 1, body: { title: 'Test' }
client.indices.refresh index: 'my-index'
client.search index: 'my-index', body: { query: { match: { title: 'test' } } }
问题:
elasticsearch cluster
的详细信息吗?集群运行在http://localhost:9200/
最佳答案
作为文档的具体说明,elasticsearch gem包装了用于连接到集群的elasticsearch-transport和用于访问elasticsearch API的elasticsearch-api。从elasticsearch-transport的文档中,
以最简单的形式,无需任何配置即可连接到在http://localhost:9200上运行的Elasticsearch:
因此,基本上,client = Elasticsearch::Client.new log: true
将默认连接到在localhost:9200(与Rails应用程序位于同一台机器)上运行的集群。
继续,尝试在建立连接后执行client.cluster.health
,您将知道连接是否成功。
此外,如果您的群集在其他服务器上运行,则可以使用以下命令连接到该服务器:
es = Elasticsearch::Client.new host: http(s)://<path-to-cluster-server>
关于ruby-on-rails - 在Ruby中使用 Elasticsearch gem时在哪里指定集群详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39473243/