您好我正在尝试将一些数据插入到弹性搜索中。我试着这样做,
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”一无所知。但我不认为这会导致这个错误。 当我尝试运行此代码段时,它会向我显示此错误,
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
这是我在配置文件中注释掉内容时得到的错误。
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 :(得分: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访问弹性搜索服务器。我建议安装插件头或插件HQ,以获得有关弹性搜索服务器的更好信息。
希望这有帮助
修改
我认为拼写错误在运输港口。是9300而不是9200。