Elasticsearch索引无法工作并出现错误信息:节点null不是集群[elasticsearch]的一部分,将其忽略。

17

我刚刚下载了 Elastic Search 分布式并运行它。

curl 'localhost:9200'

{
   "status" : 200,
   "name" : "cbs",
   "cluster_name" : "elasticsearch",
   "version" : {
   "number" : "1.4.1",
   "build_hash" : "89d3241d670db65f994242c8e8383b169779e2d4",
   "build_timestamp" : "2014-11-26T15:49:29Z",
   "build_snapshot" : false,
   "lucene_version" : "4.10.2"
    },
  "tagline" : "You Know, for Search"
}

我正在尝试使用spring-data访问它。 根据spring data文档,在应用程序上下文中添加以下行,带有xml命名空间:

<elasticsearch:repositories base-package="com.cbs" />
<elasticsearch:transport-client id="client" cluster-nodes="127.0.0.1:9300" cluster-name="elasticsearch" />
<bean name="elasticsearchTemplate" class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
    <constructor-arg name="client" ref="client" />
</bean>

以下是实体和仓库的代码:

@org.springframework.data.elasticsearch.annotations.Document(indexName = "product", type = "product", shards = 1, replicas = 0, indexStoreType = "memory", refreshInterval = "-1")
public class Product {
    @Id
    private String id;    
    private String name;
}


@Repository
public class ProductSearchDaoImpl implements IProductSearchDao {
@Autowired
private ElasticsearchOperations elasticsearchOperations;

@Override
public void index(Product product) {
    elasticsearchOperations.createIndex(Product.class);
    elasticsearchOperations.putMapping(Product.class);
    IndexQuery indexQuery = new IndexQueryBuilder().withId(product.getId()).withObject(product).build();
    elasticsearchOperations.index(indexQuery);
    elasticsearchOperations.refresh(Product.class, true);
}
}

现在当我运行测试用例来索引产品时,我每隔约2秒钟就会收到一个一致的警告消息,如下所示:
[Neuronne] node null not part of the cluster Cluster [elasticsearch], ignoring...
[Neuronne] node null not part of the cluster Cluster [elasticsearch], ignoring...

该产品未被索引(甚至没有创建索引)

curl 'localhost:9200/_cat/indices?v'
health status index    pri rep docs.count docs.deleted store.size pri.store.size 

有人能帮我解决这个问题吗?

2个回答

40

对于那些遇到相同错误并从搜索引擎跳转至此的人,请确保 TransportClient 使用与集群本身相同的集群名称。

  1. 验证集群名称。

访问 http://localhost:9200 来检查集群名称。默认名称为 elasticsearch。如果您使用 elasticsearch.yml 文件自定义了集群名称,请确保配置文件已被采用。

  1. 创建 TransportClient 时设置 culster.name

    Settings settings = ImmutableSettings.settingsBuilder()
            .put("cluster.name", clusterName)
            .put("client.transport.ignore_cluster_name", false)
            .put("node.client", true)
            .put("client.transport.sniff", true)
            .build();
    client = new TransportClient(settings).addTransportAddress(new  InetSocketTransportAddress(host, port)); 
    
  2. 忽略集群名称检查

您可以通过将client.transport.ignore_cluster_name设置为true来忽略集群名称的检查。

  1. 如果错误仍然存在,请调试

如果错误仍然存在,请在调试模式下启动您的应用程序,并调试TransportClientNodesService


2
大多数情况下,这个错误只会在传输客户端有错误的集群名称时发生! - Selvakumar Esra
1
我刚刚暂时禁用了集群名称检查。谢谢! - Dmitry Minkovsky

4

为了进行实验,我在我的开发 Elasticsearch 服务器上更改了名称,但之后忘记了。

客户端的错误信息并不是很有用。TransportClientNodeService 会将远程名称与本地名称进行比较,但并不会在日志中写入远程名称(“cluster-name”)。

可以通过以下 Spring 配置绕过名称检查:

对于我来说,解决方法要么是:

  • 更改 Elasticsearch 服务器中 cluster.name 的名称。
  • 忽略客户端的集群名称。

我两个都尝试了一下,这是我的 Spring 配置,希望能有所帮助:

spring:
    ...
    data:
    elasticsearch:
        # Defaults to cluster-name 'elasticsearch'
        cluster-name:
        cluster-nodes: 127.0.0.1:9300
        properties:
            # https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html
            client.transport.ignore_cluster_name: true

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接