1谴古、錯(cuò)誤異常:document_missing_exception
org.springframework.data.elasticsearch.UncategorizedElasticsearchException: Elasticsearch exception [type=document_missing_exception, reason=[_doc][412457]: document missing];
服務(wù)環(huán)境:
- 三臺(tái)服務(wù)器 各部署一個(gè)服務(wù)
- Mysql8.0 + Canal + Kafka2.6.0 + Elasticsearch7.6.2
原因:配置了文檔不存在 更新時(shí)不創(chuàng)建文檔
DocAsUpsert=false
簇抵,在文檔新增前進(jìn)行修改會(huì)報(bào)此錯(cuò)誤蝙斜。
解決辦法:由于本項(xiàng)目環(huán)境在新增時(shí)會(huì)獲取最新數(shù)據(jù)经磅,所以即使報(bào)錯(cuò)泌绣,也可以保證文檔的最終數(shù)據(jù)一致性,所以只是把異常捕獲掉预厌;
問(wèn)題情況:
1阿迈、考慮消費(fèi)順序是否異常
2、根據(jù)實(shí)際情況可配置文檔不存在即創(chuàng)建
//DocAsUpsert 不存在是否插入 默認(rèn)false
//Document 更新數(shù)據(jù)
UpdateQuery updateQuery = builder.withDocAsUpsert(false).withDocument(document).build();
try {
UpdateResponse response = elasticsearchRestTemplate.update(updateQuery,IndexCoordinates.of("indexName"));
} catch (UncategorizedElasticsearchException e){
}
貼出完整錯(cuò)誤:
org.springframework.data.elasticsearch.UncategorizedElasticsearchException: Elasticsearch exception [type=document_missing_exception, reason=[_doc][412457]: document missing]; nested exception is [索引名稱/NSavibY2QLOJObm0xJgJ-g][[索引名稱][2]] ElasticsearchStatusException[Elasticsearch exception [type=document_missing_exception, reason=[_doc][412457]: document missing]]
at org.springframework.data.elasticsearch.core.ElasticsearchExceptionTranslator.translateExceptionIfPossible(ElasticsearchExceptionTranslator.java:67)
at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.translateException(ElasticsearchRestTemplate.java:378)
at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.execute(ElasticsearchRestTemplate.java:361)
at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.update(ElasticsearchRestTemplate.java:234)
報(bào)錯(cuò)異常類:UncategorizedElasticsearchException
ES異常類:ElasticsearchException
ES錯(cuò)誤枚舉:ElasticsearchExceptionHandle
2轧叽、錯(cuò)誤異常:Cannot index a document due to seq_no+primary_term conflict
org.springframework.dao.OptimisticLockingFailureException: Cannot index a document due to seq_no+primary_term conflict; nested exception is [case_info-prod/NSavibY2QLOJObm0xJgJ-g][[case_info-prod][0]] ElasticsearchStatusException[Elasticsearch exception [type=version_conflict_engine_exception, reason=[121857]: version conflict, required seqNo [1323993], primary term [1]. current document has seqNo [1747408] and primary term [1]]]
原因:Es更新操作
樂(lè)觀鎖
苗沧,主要是在集群環(huán)境的情況下同時(shí)操作導(dǎo)致,并發(fā)修改觸發(fā)樂(lè)觀鎖
需求環(huán)境:本項(xiàng)目根據(jù)Canal監(jiān)聽(tīng)binlog消息到kafka 消費(fèi)增量同步Es炭晒;
問(wèn)題出現(xiàn)情況:多臺(tái)服務(wù)同時(shí)處理同一條消息到Es
解決辦法:
1待逞、多臺(tái)服務(wù)器配置消費(fèi)不同Partition
2、可通過(guò)RetryOnConflict設(shè)置重試次數(shù)
//DocAsUpsert 不存在是否插入 默認(rèn)false
//RetryOnConflict 失敗重試次數(shù)
//Document 更新數(shù)據(jù)
UpdateQuery updateQuery = builder.withDocAsUpsert(false).withRetryOnConflict(3).withDocument(document).build();
UpdateResponse response = elasticsearchRestTemplate.update(updateQuery,IndexCoordinates.of("indexName"));
貼出完整錯(cuò)誤:
org.springframework.dao.OptimisticLockingFailureException: Cannot index a document due to seq_no+primary_term conflict; nested exception is [case_info-prod/NSavibY2QLOJObm0xJgJ-g][[case_info-prod][0]] ElasticsearchStatusException[Elasticsearch exception [type=version_conflict_engine_exception, reason=[121857]: version conflict, required seqNo [1323993], primary term [1]. current document has seqNo [1747408] and primary term [1]]]
at org.springframework.data.elasticsearch.core.ElasticsearchExceptionTranslator.translateExceptionIfPossible(ElasticsearchExceptionTranslator.java:55)
at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.translateException(ElasticsearchRestTemplate.java:378)
at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.execute(ElasticsearchRestTemplate.java:361)
at org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate.update(ElasticsearchRestTemplate.java:234)
嘀嘀嘀 彩蛋時(shí)間~
如何查看Es版本
訪問(wèn)ES地址 返回JSON數(shù)據(jù)
{
"name" : "node-1",
"cluster_name" : "es",
"cluster_uuid" : "Yz9huLzYRZ-K6fVYuE4zXA",
"version" : {
"number" : "7.6.2",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "ef48eb35cf30adf4db14086e8aabd07ef6fb113f",
"build_date" : "2020-03-26T06:34:37.794943Z",
"build_snapshot" : false,
"lucene_version" : "8.4.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}
kibana可通過(guò)'GET /'命令查看
linux查看kafka版本
find /opt -name \*kafka_\* | head -1 | grep -o '\kafka[^\n]*'