2017-10-04 4 views
0

こんにちは私は弾性検索にいくつかのデータを挿入しようとしています。そして、私はこのように試しましたJavaアプリケーションから弾性検索にデータを挿入

public static void main(String args[]) 
{ 
     Client client = null; 
     Settings settings = ImmutableSettings 
       .settingsBuilder() 
       .put("cluster.name","elasticsearch") 
       .build(); 
     try{ 
      client = new TransportClient(settings) 
        .addTransportAddress(new 
          InetSocketTransportAddress("localhost",9300)); 
     } 
     catch(Exception e) 
     { 
      e.printStackTrace(); 
     } 

     try{ 
      IndexResponse response = client.prepareIndex("twitter", 
        "tweet", "1") 
        .setSource(jsonBuilder() 
          .startObject() 
          .field("user", "kimchy") 
          .field("postDate", new Date()) 
          .field("message", "trying out Elastic Search") 
              .endObject() 
          ) 
          .execute() 
          .actionGet(); 
     } 
     catch(Exception e) 
     { 
      e.printStackTrace(); 
     } 

} 

私はputメソッドで "localtestsearch"について考えていません。しかし、私はそれがこのエラーを引き起こすとは思わない。私はこのコードを実行しようとした は、私はそれが私が間違ってそれをやっているout.Whereだけの時間を言うようにエラーが何であるかを把握することができませんでし

Exception in thread "main" org.elasticsearch.discovery.MasterNotDiscoveredException: waited for [1m] 
    at org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(TransportMasterNodeOperationAction.java:180) 
    at org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(InternalClusterService.java:451) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 

、それは私に、このエラーを示しスニペット?助けて。

編集

elasticsearch.yml

# ======================== Elasticsearch Configuration ========================= 
# 
# NOTE: Elasticsearch comes with reasonable defaults for most settings. 
#  Before you set out to tweak and tune the configuration, make sure you 
#  understand what are you trying to accomplish and the consequences. 
# 
# The primary way of configuring a node is via this file. This template lists 
# the most important settings you may want to configure for a production cluster. 
# 
# Please see the documentation for further information on configuration options: 
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/setup-configuration.html> 
# 
# ---------------------------------- Cluster ----------------------------------- 
# 
# Use a descriptive name for your cluster: 
# 
# cluster.name: my-application 
# 
# ------------------------------------ Node ------------------------------------ 
# 
# Use a descriptive name for the node: 
# 
# node.name: node-1 
# 
# Add custom attributes to the node: 
# 
# node.rack: r1 
# 
# ----------------------------------- Paths ------------------------------------ 
# 
# Path to directory where to store the data (separate multiple locations by comma): 
# 
# path.data: /path/to/data 
# 
# Path to log files: 
# 
# path.logs: /path/to/logs 
# 
# ----------------------------------- Memory ----------------------------------- 
# 
# Lock the memory on startup: 
# 
# bootstrap.memory_lock: true 
# 
# Make sure that the `ES_HEAP_SIZE` environment variable is set to about half the memory 
# available on the system and that the owner of the process is allowed to use this limit. 
# 
# Elasticsearch performs poorly when the system is swapping the memory. 
# 
# ---------------------------------- Network ----------------------------------- 
# 
# Set the bind address to a specific IP (IPv4 or IPv6): 
# 
# network.host: 192.168.0.1 
# 
# Set a custom port for HTTP: 
# 
# http.port: 9200 
# 
# For more information, see the documentation at: 
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html> 
# 
# --------------------------------- Discovery ---------------------------------- 
# 
# Pass an initial list of hosts to perform discovery when new node is started: 
# The default list of hosts is ["127.0.0.1", "[::1]"] 
# 
# discovery.zen.ping.unicast.hosts: ["host1", "host2"] 
# 
# Prevent the "split brain" by configuring the majority of nodes (total number of nodes/2 + 1): 
# 
# discovery.zen.minimum_master_nodes: 3 
# 
# For more information, see the documentation at: 
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-discovery.html> 
# 
# ---------------------------------- Gateway ----------------------------------- 
# 
# Block initial recovery after a full cluster restart until N nodes are started: 
# 
# gateway.recover_after_nodes: 3 
# 
# For more information, see the documentation at: 
# <http://www.elastic.co/guide/en/elasticsearch/reference/current/modules-gateway.html> 
# 
# ---------------------------------- Various ----------------------------------- 
# 
# Disable starting multiple nodes on a single system: 
# 
# node.max_local_storage_nodes: 1 
# 
# Require explicit names when deleting indices: 
# 
# action.destructive_requires_name: true 

EDIT2

これは、私は、configファイルで物事をコメントアウトするとき私が得たエラーです。

INFO: [Buzz] loaded [], sites [] 
Exception in thread "main" org.elasticsearch.client.transport.NoNodeAvailableException: No node available 
    at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:182) 
    at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:94) 
    at org.elasticsearch.client.support.AbstractClient.index(AbstractClient.java:79) 
    at org.elasticsearch.client.transport.TransportClient.index(TransportClient.java:310) 
    at com.kodcu.main.JavaAPIMain.main(JavaAPIMain.java:123) 
+0

クライアントがマスターノードを見つけることができないようです。これはコードの問題ではなく設定の問題のようです。 – JRR

+0

その解決策は何でしょうか? –

+0

あなたの質問をサーバー設定で更新してください。 – JRR

答えて

1

あなたはelasticsearch.ymlに次のキーワードをコメントアウトする必要があります

cluster.name: your_cluster_name 
node.name: your_node_name 
node.master: true 
node.data: true 
index.number_of_shards: number_of_shards 
index.number_of_replicas: number_of_replicas 
network.host: 0.0.0.0 
path.conf: path_to_conf 
path.data: path_to_data 

またhttp://localhost:9200からあなたelasticsearchサーバーに到達しようとすることができます。私はあなたのelasticsearchサーバーについてのより良い情報を得るために、プラグインヘッドまたはプラグインHQをインストールすることをお勧めします。

希望これは、私はタイプミスが転送ポートであると思い編集

に役立ちます。 9200ではなく9300です。

+0

ええ、ヘッドプラグインを使用していますが、あなたが言ったすべてのことをコメントしましたが、今は別のエラーが表示されます。私はそのエラーを表示するために私の質問を編集します。 –

+0

私はちょうど私の答えを編集しました。私は問題が接続ポートにあると思う、それは9200の代わりに9300であるべきである – Jorge

+0

私は多くの方法を試みた、私は方法を見つけることができなかった。今私は弾性バージョン5.6を使用しています。編集するymlファイルはありません。 –