通过Java API删除和重新创建elasticsearch索引时的明显竞争条件
我得到一个错误-在创建我刚刚删除的索引时,索引已经存在。下面是我创建的一个简单测试,用于复制该行为:通过Java API删除和重新创建elasticsearch索引时的明显竞争条件,java,indexing,
elasticsearch,Java,Indexing,
elasticsearch,我得到一个错误-在创建我刚刚删除的索引时,索引已经存在。下面是我创建的一个简单测试,用于复制该行为: Client elasticSearchClient = elasticSearchLocalService.getClient(); if (elasticSearchClient.admin().indices().exists(new IndicesExistsRequest(indexName)).get().isExists())
Client elasticSearchClient = elasticSearchLocalService.getClient();
if (elasticSearchClient.admin().indices().exists(new IndicesExistsRequest(indexName)).get().isExists())
elasticSearchClient.admin().indices().delete(new DeleteIndexRequest(indexName)).get();
elasticSearchClient.admin().indices().exists(new IndicesExistsRequest(indexName)).get().isExists();//returns false
elasticSearchClient.admin().indices().create(new CreateIndexRequest(indexName)).get();
即使检查索引是否存在的第二个调用返回false,我仍然得到错误,我尝试刷新索引,但我认为这只会影响数据。
我希望。在所有操作完成之前阻止删除
谢谢 第四行应该在if中吗?这实际上只是为了调试目的,因为根据api,delete应该阻止