Elasticsearch在應(yīng)用中常見(jiàn)錯(cuò)誤示例解析
一 read_only_allow_delete" : "true"
當(dāng)我們?cè)谙蚰硞€(gè)索引添加一條數(shù)據(jù)的時(shí)候,可能(極少情況)會(huì)碰到下面的報(bào)錯(cuò):
{ "error": { "root_cause": [ { "type": "cluster_block_exception", "reason": "blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];" } ], "type": "cluster_block_exception", "reason": "blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];" }, "status": 403 }
上述報(bào)錯(cuò)是說(shuō)索引現(xiàn)在的狀態(tài)是只讀模式(read-only),如果查看該索引此時(shí)的狀態(tài):
GET z1/_settings # 結(jié)果如下 { "z1" : { "settings" : { "index" : { "number_of_shards" : "5", "blocks" : { "read_only_allow_delete" : "true" }, "provided_name" : "z1", "creation_date" : "1556204559161", "number_of_replicas" : "1", "uuid" : "3PEevS9xSm-r3tw54p0o9w", "version" : { "created" : "6050499" } } } } }
可以看到"read_only_allow_delete" : "true",說(shuō)明此時(shí)無(wú)法插入數(shù)據(jù),當(dāng)然,我們也可以模擬出來(lái)這個(gè)錯(cuò)誤:
PUT z1 { "mappings": { "doc": { "properties": { "title": { "type":"text" } } } }, "settings": { "index.blocks.read_only_allow_delete": true } } PUT z1/doc/1 { "title": "es真難學(xué)" }
現(xiàn)在我們?nèi)绻麍?zhí)行插入數(shù)據(jù),就會(huì)報(bào)開(kāi)始的錯(cuò)誤。那么怎么解決呢?
- 清理磁盤,使占用率低于85%。
- 手動(dòng)調(diào)整該項(xiàng),具體參考官網(wǎng)
這里介紹一種,我們將該字段重新設(shè)置為:
PUT z1/_settings { "index.blocks.read_only_allow_delete": null }
現(xiàn)在再查看該索引就正常了,也可以正常的插入數(shù)據(jù)和查詢了。
二 illegal_argument_exception
有時(shí)候,在聚合中,我們會(huì)發(fā)現(xiàn)如下報(bào)錯(cuò):
{ "error": { "root_cause": [ { "type": "illegal_argument_exception", "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [age] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead." } ], "type": "search_phase_execution_exception", "reason": "all shards failed", "phase": "query", "grouped": true, "failed_shards": [ { "shard": 0, "index": "z2", "node": "NRwiP9PLRFCTJA7w3H9eqA", "reason": { "type": "illegal_argument_exception", "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [age] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead." } } ], "caused_by": { "type": "illegal_argument_exception", "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [age] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.", "caused_by": { "type": "illegal_argument_exception", "reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [age] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead." } } }, "status": 400 }
這是怎么回事呢?是因?yàn)椋酆喜樵儠r(shí),指定字段不能是text類型。比如下列示例:
PUT z2/doc/1 { "age":"18" } PUT z2/doc/2 { "age":20 } GET z2/doc/_search { "query": { "match_all": {} }, "aggs": { "my_sum": { "sum": { "field": "age" } } } }
當(dāng)我們向elasticsearch中,添加一條數(shù)據(jù)時(shí)(此時(shí),如果索引存在則直接新增或者更新文檔,不存在則先創(chuàng)建索引),首先檢查該age字段的映射類型。
如上示例中,我們添加第一篇文檔時(shí)(z1索引不存在),elasticsearch會(huì)自動(dòng)的創(chuàng)建索引,然后為age字段創(chuàng)建映射關(guān)系(es就猜此時(shí)age字段的值是什么類型,如果發(fā)現(xiàn)是text類型,那么存儲(chǔ)該字段的映射類型就是text),此時(shí)age字段的值是text類型,所以,第二條插入數(shù)據(jù),age的值也是text類型,而不是我們看到的long類型。我們可以查看一下該索引的mappings信息:
GET z2/_mapping # mapping信息如下 { "z2" : { "mappings" : { "doc" : { "properties" : { "age" : { "type" : "text", "fields" : { "keyword" : { "type" : "keyword", "ignore_above" : 256 } } } } } } } }
上述返回結(jié)果發(fā)現(xiàn),age類型是text。而該類型又不支持聚合,所以,就會(huì)報(bào)錯(cuò)了。解決辦法就是:
- 如果選擇動(dòng)態(tài)創(chuàng)建一篇文檔,映射關(guān)系取決于你添加的第一條文檔的各字段都對(duì)應(yīng)什么類型。而不是我們看到的那樣,第一次是text,第二次不加引號(hào),就是long類型了不是這樣的。
- 如果嫌棄上面的解決辦法麻煩,那就選擇手動(dòng)創(chuàng)建映射關(guān)系。首先指定好各字段對(duì)應(yīng)什么類型。后續(xù)才不至于出錯(cuò)。
三 Result window is too large
很多時(shí)候,我們?cè)诓樵兾臋n時(shí),一次查詢結(jié)果很可能會(huì)有很多,而elasticsearch一次返回多少條結(jié)果,由size參數(shù)決定:
GET e2/doc/_search { "size": 100000, "query": { "match_all": {} } }
而默認(rèn)是最多范圍一萬(wàn)條,那么當(dāng)我們的請(qǐng)求超過(guò)一萬(wàn)條時(shí)(比如有十萬(wàn)條),就會(huì)報(bào):
Result window is too large, from + size must be less than or equal to: [10000] but was [100000]. See the scroll api for a more efficient way to request large data sets. This limit can be set by changing the [index.max_result_window] index level setting.
意思是一次請(qǐng)求返回的結(jié)果太大,可以另行參考 scroll API或者設(shè)置index.max_result_window參數(shù)手動(dòng)調(diào)整size的最大默認(rèn)值:
# kibana中設(shè)置 PUT e2/_settings { "index": { "max_result_window": "100000" } } # Python中設(shè)置 from elasticsearch import Elasticsearch es = Elasticsearch() es.indices.put_settings(index='e2', body={"index": {"max_result_window": 100000}})
如上例,我們手動(dòng)調(diào)整索引e2的size參數(shù)最大默認(rèn)值到十萬(wàn),這時(shí),一次查詢結(jié)果只要不超過(guò)10萬(wàn)就都會(huì)一次返回。
注意,這個(gè)設(shè)置對(duì)于索引es的size參數(shù)是永久生效的。
以上就是Elasticsearch在應(yīng)用中常見(jiàn)錯(cuò)誤示例解析的詳細(xì)內(nèi)容,更多關(guān)于Elasticsearch錯(cuò)誤示例解析的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Github創(chuàng)建個(gè)人訪問(wèn)Tokens令牌
這篇文章介紹了Github創(chuàng)建個(gè)人訪問(wèn)Tokens令牌的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04Bottle部署web服務(wù)及postman接口的方法
這篇文章主要介紹了Bottle部署web服務(wù)及postman接口的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-01-01GCC?指令詳解及動(dòng)態(tài)庫(kù)、靜態(tài)庫(kù)的使用方法
GCC?是?Linux?下的編譯工具集,是「GNU?Compiler?Collection」的縮寫(xiě),包含?gcc、g++?等編譯器,這篇文章主要介紹了GCC?指令詳解及動(dòng)態(tài)庫(kù)、靜態(tài)庫(kù)的使用,需要的朋友可以參考下2022-10-10全網(wǎng)最強(qiáng)下載神器IDM使用教程之利用IDM加速下載百度網(wǎng)盤大文件的方法
自從不限速度盤下載工具Pandownload被封殺后,有些網(wǎng)友紛紛表示:幸好我們還有IDM,但是很多朋友對(duì)IDM不是多了解,下面小編給大家介紹下下載神器IDM使用教程之利用IDM加速下載百度網(wǎng)盤大文件的方法,感興趣的朋友跟隨小編一起看看吧2023-01-01Ceph分布式存儲(chǔ)集群Pool資源池簡(jiǎn)介及使用小結(jié)
這篇文章主要介紹了Ceph分布式存儲(chǔ)集群Pool資源池的概念以及使用,Pool資源池是Ceph存儲(chǔ)數(shù)據(jù)的邏輯分區(qū),起到Namespace命名空間的作用,本文給大家介紹的非常詳細(xì),需要的朋友參考下吧2022-06-06git工作區(qū)暫存區(qū)與版本庫(kù)基本理解及提交流程全解
這篇文章主要為大家介紹了git工作區(qū)暫存區(qū)與版本庫(kù)基本理解及提交流程,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2022-04-04詳解Git.gitignore開(kāi)發(fā)必備建議收藏
這篇文章主要介紹了Git.gitignore的全面詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-08-08網(wǎng)址(URL)支持的最大長(zhǎng)度是多少?最大支持多少個(gè)字符?
這篇文章主要介紹了網(wǎng)址(URL)支持的最大長(zhǎng)度是多少?最大支持多少個(gè)字符?本文總結(jié)了IIS、apache服務(wù)器及瀏覽器軟件Internet Explorer、Firefox、Opera、chrome等主流的瀏覽器軟件支持情況,需要的朋友可以參考下2015-07-07flask+layui+echarts實(shí)現(xiàn)前端動(dòng)態(tài)圖展示數(shù)據(jù)效果
這篇文章主要介紹了flask+layui+echarts實(shí)現(xiàn)前端動(dòng)態(tài)圖展示數(shù)據(jù)效果,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09