首页 > ELK > 解决 Elasticsearch 查询时 Fielddata is disabled on text fields by default 错误
2019
09-10

解决 Elasticsearch 查询时 Fielddata is disabled on text fields by default 错误

问题描述


以下过程基于elasticsearch 7.5.0


最近发现es测试服务器日志有大量报错,而且kibana打不开,于是打开es日志查看如下:

[2023-08-10T13:54:33,119][DEBUG][o.e.a.s.TransportSearchAction] [super-test.aigupiao.com] [.kibana][0], node[xXnF0Aw-SSWhLuXz5hUY4Q], [P], s[STARTED], 
a[id=FyuQPDNdQp64ZnOeA6AzmQ]: Failed to execute [SearchRequest{searchType=QUERY_THEN_FETCH, indices=[.kibana], indicesOptions=IndicesOptions[ignore_unavailable=true, 
allow_no_indices=true, expand_wildcards_open=true, expand_wildcards_closed=false, allow_aliases_to_multiple_indices=true, forbid_closed_indices=true, 
ignore_aliases=false, ignore_throttled=true], types=[], routing='null', preference='null', requestCache=null, scroll=null, maxConcurrentShardRequests=0, 
batchedReduceSize=512, preFilterShardSize=128, allowPartialSearchResults=true, localClusterAlias=null, getOrCreateAbsoluteStartMillis=-1, 
ccsMinimizeRoundtrips=true, source={"size":0,"query":{"terms":{"type":["dashboard","visualization","search","index-pattern","graph-workspace",
"timelion-sheet"],"boost":1.0}},"aggregations":{"types":{"terms":{"field":"type","size":6,"min_doc_count":1,"shard_min_doc_count":0,"show_term_doc_count_error":false,
"order":[{"_count":"desc"},{"_key":"asc"}]}}}}}]

org.elasticsearch.transport.RemoteTransportException: [super-test.aigupiao.com][10.10.0.3:9300][indices:data/read/search[phase/query]]

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.
        at org.elasticsearch.index.mapper.TextFieldMapper$TextFieldType.fielddataBuilder(TextFieldMapper.java:759) ~[eva.lang.IllegalArgumentException: 
        Fielddata is disabled on text fields by default.lasticsearch-7.5.0.jar:7.5.0]


找重点

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

通过分析以上日志发现出问题的是kibana启动的时候,索引 .kibana 有问题


Fielddata is disabled on text fields by default. Set fielddata=true on [type] ]

再通过上面日志分析是 type出了问题,日志其实已经说得很清楚了,默认情况下 text 类型的字段 fielddata 被禁用。官方文档在:https://www.elastic.co/guide/en/elasticsearch/reference/7.17/text.html#fielddata-mapping-param

节选一部分官方文档:

fielddata mapping parameteredit
text fields are searchable by default, but by default are not available for
aggregations, sorting, or scripting. If you try to sort, aggregate, or access
values from a script on a text field, you will see this exception:
Fielddata is disabled on text fields by default. Set fielddata=true onyour_field_name in order to load fielddata in memory by uninverting the
inverted index. Note that this can however use significant memory.
Field data is the only way to access the analyzed tokens from a full text field
in aggregations, sorting, or scripting. For example, a full text field like New Yorkwould get analyzed as new and york. To aggregate on these tokens requires field data.


解决方案

根据文档说明将 [type] 字段 fielddata 设置为 true:

PUT /.kibana/_mapping?pretty
{
  "properties": {
    "type": {
      "type":     "text",
      "fielddata": true
    }
  }
}


总结

首先找到是哪个索引下的哪个字段报错,此例中就是 .kibana 索引的 type 字段,然后将对应字段 fielddata 设置为 true 解决问题。


本文》有 0 条评论

留下一个回复