解決 Elasticsearch 查詢時 Fielddata is disabled on text fields by default 錯誤


問題描述

以下過程基於 Elasticsearch 7.3

Elasticsearch 啟動后無法查詢,檢查日志發現這樣一行日志:

Caused by: java.lang.IllegalArgumentException: Fielddata is disabled on text fields by default. Set fielddata=true on [type] 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.

日志其實已經說得很清楚了,默認情況下 text 類型的字段 fielddata 被禁用。官方文檔在這里

繼續排查日志發現:

Failed to execute [SearchRequest{searchType=QUERY_THEN_FETCH, indices=[.kibana], indicesOptions=IndicesOptions......

是啟動 kibana 時報的錯。

解決方案

根據文檔說明將 [type] 字段 fielddata 設置為 true:

curl -X PUT "localhost:9200/.kibana/_mapping?pretty" -H 'Content-Type: application/json' -d'
{
  "properties": {
    "type": {
      "type":     "text",
      "fielddata": true
    }
  }
}
'

總結

首先找到是哪個索引下的哪個字段報錯,此例中就是 .kibana 索引的 type 字段,然后將對應字段 fielddata 設置為 true 解決問題。

修改配置 :

curl -X PUT "localhost:9200/[modify_this_index]/_mapping?pretty" -H 'Content-Type: application/json' -d'
{
  "properties": {
    "[modify_this_field]": {
      "type":     "text",
      "fielddata": true
    }
  }
}
'

驗證結果:

curl -X GET "localhost:9200/[modify_this_index]/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "aggs": {
    "all_[modify_this_field]": {
      "terms": { "field": "[modify_this_field]" }
    }
  }
}
'

將 [modify_this_index] 和 [modify_this_field] 修改為對應的索引和字段即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM