📣 极限科技诚招搜索运维工程师(Elasticsearch/Easysearch)- 全职/北京 👉 : 立即申请加入

版本: 6.8-7.15

简而言之,当 Elasticsearch 在分片分配过程中遇到期望的分配 ID 与实际分配 ID 不匹配时,就会出现此错误。这可能是由于节点离开并重新加入集群,导致分片分配出现差异。要解决此问题,您可以尝试使用集群重新路由 API 手动重新路由分片,或执行完整的集群重启。如果问题仍然存在,请考虑删除并重新索引数据。在执行这些操作之前,务必确保已做好备份。

日志上下文 #

日志 “expected allocation id [{}] but found [{}]” 的类名是 TransportReplicationAction.java。我们从 Elasticsearch 源代码中提取了以下内容,供那些寻求深入了解上下文的人参考:

if (shardRouting.primary() == false) {
    throw new ReplicationOperation.RetryOnPrimaryException(shardId, "actual shard is not a primary " + shardRouting);
}
final String actualAllocationId = shardRouting.allocationId().getId();
if (actualAllocationId.equals(primaryRequest.getTargetAllocationID()) == false) {
    throw new ShardNotFoundException(shardId, "expected allocation id [{}] but found [{}]",
    primaryRequest.getTargetAllocationID(), actualAllocationId);
}
final long actualTerm = indexShard.getPendingPrimaryTerm();
if (actualTerm != primaryRequest.getPrimaryTerm()) {
    throw new ShardNotFoundException(shardId, "expected allocation id [{}] with term [{}] but found [{}]",