2016-09-13 4 views
0

Elastic Search Clusterのデータにrailsアプリケーションからアクセスしたいと思います。サーバがhttp://localhost:9200で動作していて、エンドポイントhttp://localhost:9200/location/typeにアクセスしたいとします。Rubyで弾性検索宝石を使用する場合のクラスタの詳細を指定する場所

この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/

答えて

1

で実行されている、elasticsearch逸品elasticsearchのAPIにアクセスするためのクラスタとelasticsearch-apiに接続するためのelasticsearch-transportをラップします。 (9200:elasticsearch輸送の文書から、最も単純な形で

、任意の設定なしでhttp://localhost:9200上で実行されているElasticsearchに接続:

だから、基本的に、client = Elasticsearch::Client.new log: trueは、デフォルトでローカルホストで実行中のクラスタに接続しますあなたのRailsアプリケーションと同じマシン)。

接続を確立した後にclient.cluster.healthを実行しようとすると、成功したかどうかを知ることができます。クラスタが別のサーバー上で動作している場合

また、あなたはそれに接続するには、次を使用することができます。

es = Elasticsearch::Client.new host: http(s)://<path-to-cluster-server> 
関連する問題