亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Elasticsearch在應(yīng)用中常見(jiàn)錯(cuò)誤示例解析

 更新時(shí)間:2022年04月20日 08:30:53   作者:Jeff的技術(shù)棧  
這篇文章主要為大家介紹了Elasticsearch在應(yīng)用中常見(jiàn)錯(cuò)誤示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

一 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)文章

最新評(píng)論