我刚刚下载了弹性搜索发行版并运行了它。
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 访问它。在带有 xml 命名空间的应用程序上下文中添加了以下行(根据 spring 数据文档):
<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
谁能帮我解决这个问题?