[英]Elastic Search java (spring) issue at indexing
I have integrated elastic-search 1.7.1 with spring application.I have a cron job which update the index of elasticsearch on every run. 我已经将spring-spring应用程序集成了Elastic-search 1.7.1。我有一个cron作业,该作业在每次运行时都会更新elasticsearch的索引。 I have followed various example codes available on github to make it work.First I have Autowired ElasticSearchOperations for indexing purpose:
我遵循了github上可用的各种示例代码来使其工作。首先,我为索引目的自动装配了ElasticSearchOperations:
@Autowired
private ElasticsearchOperations elasticsearchOperations;
Then inside loop indexing is perform in following manner 然后以以下方式执行内部循环索引
for(int i=0;i<list.size();i++)
{
CategoryProductSearch search = new CategoryProductSearch();
// set data to fields
System.out.println("BEFORE SAVING DATA");
IndexQuery indexQuery =new
IndexQueryBuilder().withId(search.getId()).withObject(search).build();
//indexQuery.setId(search.getId());
//indexQuery.setObject(search);
//elasticsearchOperations.createIndex(CategoryProductSearch.class);
elasticsearchOperations.putMapping(CategoryProductSearch.class);
elasticsearchOperations.index(indexQuery);
elasticsearchOperations.refresh(CategoryProductSearch.class,true);
System.out.println("SAVING DATA");
}
When i run it for first time it works as expected. 当我第一次运行它时,它按预期工作。 I have renamed cluster to "mycluster" in elasticsearch.yml inside config folder.
我在配置文件夹中的elasticsearch.yml中将集群重命名为“ mycluster”。 After first run i can see the folder created.
第一次运行后,我可以看到创建的文件夹。 Indexing and searching(Implemented in another file) works perfectly.
索引和搜索(在另一个文件中实现)工作完美。 But sometimes the code get stuck at below mentioned line and shows continuous warning [Chase Stein] node null not part of the cluster Cluster [elasticsearch], ignoring...
但是有时代码卡在下面提到的行中,并显示连续警告[Chase Stein]节点null而不是集群Cluster [elasticsearch]的一部分,从而忽略了...
elasticsearchOperations.putMapping(CategoryProductSearch.class);
Then after some time it throws NoNodeAvailableException. 然后一段时间后,它将引发NoNodeAvailableException。 I have read about this issue and it says there might not be enough disk space for elastic-search to index data.
我已经读过这个问题,它说可能没有足够的磁盘空间用于弹性搜索来索引数据。 I am new to spring and have tried elastic-search for the first time.
我刚接触春天,并第一次尝试了弹性搜索。 Is this a disk space issue or something wrong in a way i am indexing data?
这是磁盘空间问题还是我索引数据的方式出现问题? Also if i manually delete "mycluster" folder from /data directory and restart application it works fine again.!
另外,如果我从/ data目录中手动删除“ mycluster”文件夹并重新启动应用程序,它将再次正常工作。
I have everything set up on my local PC. 我已经在本地PC上进行了所有设置。 Whenever i restart elasticsearch service this issue comes in.
每当我重新启动elasticsearch服务时,都会出现此问题。
Stack trace for the exception is: 异常的堆栈跟踪为:
org.elasticsearch.action.UnavailableShardsException: [mycluster][0]
Primary shard is not active or isn't assigned to a known node. Timeout:
[1m], request: index {[mycluster][categoryproductsearch][1],
source[{// Source string }]
at
org.elasticsearch.action.support.replication
.TransportShardReplicationOperationAction$PrimaryPhase
.retryBecauseUnavailable
(TransportShardReplicationOperationAction.java:655)
at
org.elasticsearch.action.support.replication
.TransportShardReplicationOperationAction$PrimaryPhase.doRun
(TransportShardReplicationOperationAction.java:362)
at
org.elasticsearch.common.util.concurrent.AbstractRunnable.run
(AbstractRunnable.java:36)
at
org.elasticsearch.action.support.replication.
TransportShardReplicationOperationAction$PrimaryPhase$3.onTimeout
(TransportShardReplicationOperationAction.java:515)
at
org.elasticsearch.cluster.ClusterStateObserver$ObserverClusterStateListener
.onTimeout
(ClusterStateObserver.java:231)
at
org.elasticsearch.cluster.service.
InternalClusterService$NotifyTimeout.run
(InternalClusterService.java:560)
at
java.util.concurrent.ThreadPoolExecutor.runWorker
(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:615)
at
java.lang.Thread.run(Thread.java:745)
Hi i took this code from generator-jhipster-elasticsearch-reindexer 嗨,我从generator-jhipster-elasticsearch-reindexer那里获得了这段代码
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
private <T> void reindexForClass(Class<T> entityClass, JpaRepository<T, Long> jpaRepository,
ElasticsearchRepository<T, Long> elasticsearchRepository) {
elasticsearchTemplate.deleteIndex(entityClass);
try {
elasticsearchTemplate.createIndex(entityClass);
} catch (IndexAlreadyExistsException e) {
// Do nothing. Index was already concurrently recreated by some other service.
}
elasticsearchTemplate.putMapping(entityClass);
if (jpaRepository.count() > 0) {
try {
Method m = jpaRepository.getClass().getMethod("findAllWithEagerRelationships");
elasticsearchRepository.save((List<T>) m.invoke(jpaRepository));
} catch (Exception e) {
elasticsearchRepository.save(jpaRepository.findAll());
}
}
log.info("Elasticsearch: Indexed all rows for " + entityClass.getSimpleName());
}
As you can see index is first deleted then created again an mapping is put, i think that your order is wrong and that it results in some broken shards. 如您所见,首先删除索引,然后再创建一个映射,我认为您的订单是错误的,并且导致碎片破裂。 You can access Elastic Rest API on localhost:9200 and try a get request /_cat/indices to see your indexes.
您可以在localhost:9200上访问Elastic Rest API,并尝试获取请求/ _cat / indices来查看索引。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.