我刚刚下载了弹性搜索分发并运行它。
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数据文档)和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
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:34)
对于遇到相同错误并从搜索引擎来到这里的人,请确保TransportClient
使用与群集本身相同的群集名称。
访问http://localhost:9200以检查群集名称。默认名称为elasticsearch
。如果使用elasticsearch.yml
文件自定义群集名称,请确保已选择配置文件。
创建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));
忽略群集名称检查
您可以将client.transport.ignore_cluster_name
设置为true
来忽略对群集名称的检查。
如果错误仍然存在,请以调试模式启动应用程序,然后调试TransportClientNodesService
。
答案 1 :(得分:3)
为了进行实验而忘记了,我在dev elasticsearch服务器上更改了名称。
客户端上的错误消息没有用,TransportClientNodeService与远程名称进行比较,但实际上并没有在日志中写入远程名称(&#34; cluster-name&#34;)。
可以使用以下Spring配置绕过名称检查:
我的决议是:
我去了两个,这是我的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