Elasticsearch索引不起作用和错误消息:node null不是集群Cluster [elasticsearch]的一部分,忽略

Sun*_*wal 16 elasticsearch spring-data-elasticsearch

我刚刚下载了弹性搜索分发并运行它.

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"
}
Run Code Online (Sandbox Code Playgroud)

我试图使用spring-data访问它.在应用程序上下文中(根据spring数据文档)在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>
Run Code Online (Sandbox Code Playgroud)

这是实体和存储库代码:

@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);
}
}
Run Code Online (Sandbox Code Playgroud)

现在,当我运行测试用例来索引产品时,我得到一个一致的警告消息(每2秒左右)

[Neuronne] node null not part of the cluster Cluster [elasticsearch], ignoring...
[Neuronne] node null not part of the cluster Cluster [elasticsearch], ignoring...
Run Code Online (Sandbox Code Playgroud)

并且产品没有被索引(即使没有创建索引)

curl 'localhost:9200/_cat/indices?v'
health status index    pri rep docs.count docs.deleted store.size pri.store.size 
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我解决这个问题吗?

Ale*_*eng 37

对于那些遇到相同错误并从搜索引擎来到这里的人,请确保TransportClient使用与群集本身相同的群集名称.

  1. 验证群集名称.

访问http:// localhost:9200以检查群集名称.默认名称是elasticsearch.如果使用elasticsearch.ymlfile 自定义群集名称,请确保已选择配置文件.

  1. culster.name创建时设置TransportClient.

    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)); 
    
    Run Code Online (Sandbox Code Playgroud)
  2. 忽略群集名称检查

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

  1. 如果错误仍然存​​在则进行调试

如果错误仍然存​​在,请以调试模式启动应用程序并进行调试TransportClientNodesService.

  • 大多数情况下,只有当传输客户端具有错误的群集名称时才会发生此错误! (2认同)