在 application.properties 文件中使用 tcp 端口"9300",但仍"None of the configured nodes are available"



错误:

failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [{#transport#-1}{uyXiOMnyRpyTSXqUoNxTyg}{localhost}{127.0.0.1:9300}]

版本:

Spring-Boot 版本:2.1.6 和 Elasticsearch 版本:7.3.0

这是我的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 consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
cluster.name: elastic
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
path.data: D:JEE_ProjectsspringSpring_WorkSpacespring-boot-with-mongodb
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size 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, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# Pass an initial list of hosts to perform discovery when this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
#
#discovery.seed_hosts: ["host1", "host2"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
#
# For more information, consult the discovery and cluster formation module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true

这是我的应用程序属性文件:

#Local MongoDB config
spring.data.mongodb.uri=mongodb://localhost:27017/newtest

# App config
server.port=8080
spring.application.name=BootMongo
server.address=localhost
# elastic search
spring.data.elasticsearch.cluster-name=elastic
#spring.main.allow-bean-definition-overriding=true
#spring.data.elasticsearch.repositories.enabled = true
spring.data.elasticsearch.cluster-nodes =localhost:9300

我重新启动了应用程序,重新启动了弹性搜索.bat甚至重新启动了整个计算机,但没有任何工作。

此外,我认为其他一些应用程序会占用该端口,但它被 elasticsearch 本身占用了。(我在浏览器中输入"localhost:9300",它响应为"这不是HTTP端口")。

这个问题是我问的,我找到了解决方案。

有 2 个主要的内部问题:

  1. 在 Elasticsearch 的最新版本(我猜是从 7.x 开始)中,每个索引只能有一个"类型"(尽管不赞成在索引中有多个"类型",但我们仍然可以强制使用它)。我通过注释为每个实体提供不同的"类型"@Document但在同一索引下。
  2. 我下载了最新版本的Elasticsearch,即7.3.0。由于这是一项新兴技术,因此更新非常频繁。但是在春季,默认情况下,Elasticsearch jar 的版本是 6.4.3(您可以通过单击Maven 依赖项来查看这一点)

解决 方案:

对于第一个问题,您可以为每个实体创建单独的索引。要解决第二个问题,您可以将 Elasticsearch 的版本降级到 6.4.3,或者您可以将 Maven 依赖项中的 jar 版本升级到 7.3.0(但在 7.3.0 jar 中,一些内置方法有点不同,您可能不知道)。

我想"cluster-name=elastic"可能是错误的。您确定弹性运行具有这样的集群名称吗?

相关内容

最新更新