Fielddata is disabled on text fields by default. Set fielddata=true on [gender] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memor

ES进行如下聚合操作时,会报如题所示错误:

 1 ?  Downloads curl -XPOST ‘localhost:9200/bank/_search?pretty‘ -d ‘
 2         {
 3           "size": 0,
 4           "aggs": {
 5             "group_by_state": {
 6               "terms": {
 7                 "field": "state"
 8               }
 9             }
10           }
11         }‘

提示报错如下:

 1 {
 2   "error" : {
 3     "root_cause" : [
 4       {
 5         "type" : "illegal_argument_exception",
 6         "reason" : "Fielddata is disabled on text fields by default. Set fielddata=true on [state] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
 7       }
 8     ],
 9     "type" : "search_phase_execution_exception",
10     "reason" : "all shards failed",
11     "phase" : "query",
12     "grouped" : true,
13     "failed_shards" : [
14       {
15         "shard" : 0,
16         "index" : "bank",
17         "node" : "nkL8C69pTMuXrZBXicjshw",
18         "reason" : {
19           "type" : "illegal_argument_exception",
20           "reason" : "Fielddata is disabled on text fields by default. Set fielddata=true on [state] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
21         }
22       }
23     ],
24     "caused_by" : {
25       "type" : "illegal_argument_exception",
26       "reason" : "Fielddata is disabled on text fields by default. Set fielddata=true on [state] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory."
27     }
28   },
29   "status" : 400
30 }

  根据官方文档显示,出现该错误是因为5.x之后,Elasticsearch对排序、聚合所依据的字段用单独的数据结构(fielddata)缓存到内存里了,但是在text字段上默认是禁用的,如果有需要单独开启,这样做的目的是为了节省内存空间。——官方文档地址:https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html

开启方法:

1 ?  Downloads curl -XPUT ‘http://localhost:9200/bank/_mapping/account‘ -d ‘
2 {
3   "properties": {
4         "state": {
5             "type": "text",
6             "fielddata": true
7         }
8     }
9 }# bank是index、account是类型、state是你需要设置的text字段

出现如下提示,说明设置成功:

1 {"acknowledged":true}

至此,聚合问题解决:

 1 ?  Downloads curl -XPOST ‘localhost:9200/bank/_search?pretty‘ -d ‘
 2         {
 3           "size": 0,
 4           "aggs": {
 5             "group_by_state": {
 6               "terms": {
 7                 "field": "state"
 8               }
 9             }
10           }
11         }‘
12 {
13   "took" : 60,
14   "timed_out" : false,
15   "_shards" : {
16     "total" : 5,
17     "successful" : 5,
18     "failed" : 0
19   },
20   "hits" : {
21     "total" : 1000,
22     "max_score" : 0.0,
23     "hits" : [ ]
24   },
25   "aggregations" : {
26     "group_by_state" : {
27       "doc_count_error_upper_bound" : 20,
28       "sum_other_doc_count" : 770,
29       "buckets" : [
30         {
31           "key" : "id",
32           "doc_count" : 27
33         },
34         {
35           "key" : "tx",
36           "doc_count" : 27
37         },
38         {
39           "key" : "al",
40           "doc_count" : 25
41         },
42         {
43           "key" : "md",
44           "doc_count" : 25
45         },
46         {
47           "key" : "tn",
48           "doc_count" : 23
49         },
50         {
51           "key" : "ma",
52           "doc_count" : 21
53         },
54         {
55           "key" : "nc",
56           "doc_count" : 21
57         },
58         {
59           "key" : "nd",
60           "doc_count" : 21
61         },
62         {
63           "key" : "me",
64           "doc_count" : 20
65         },
66         {
67           "key" : "mo",
68           "doc_count" : 20
69         }
70       ]
71     }
72   }
73 }
时间: 2024-10-08 14:59:08

Fielddata is disabled on text fields by default. Set fielddata=true on [gender] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memor的相关文章

es进行聚合操作时提示Fielddata is disabled on text fields by default

根据es官网的文档执行 GET /megacorp/employee/_search { "aggs": { "all_interests": { "terms": { "field": "interests", "size": 10 } } } } 这个例子时,报错: { "error": { "root_cause": [ { "ty

Elasticsearch 报错:Fielddata is disabled on text fields by default. Set `fielddata=true` on [`your_field_name`] in order to load fielddata in memory by uninverting the inverted index.

Elasticsearch 报错: Fielddata is disabled on text fields by default. Set `fielddata=true` on [`your_field_name`] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. 解决:https://www.e

Kibana error " Fielddata is disabled on text fields by default. Set fielddata=true on [publisher] ..."

Reason of this error:Fielddata can consume a lot of heap space, especially when loading high cardinality text fields. Once fielddata has been loaded into the heap, it remains there for the lifetime of the segment.Also, loading fielddata is an expensi

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

2个字段的: PUT metricbeat-7.3.0/_mapping { "properties": { "service": { "properties": { "address": { "type": "text", "fielddata": true, "fields": { "keyword": { "ty

python Fielddata is disabled on text fields

# 执行https://www.elastic.co/guide/cn/elasticsearch/guide/current/_aggregation_test_drive.html中的例子时报错Fielddata is disabled on text fields ,只需要在查询的fields后面加上.kewwords即可 # 参考https://blog.csdn.net/u011403655/article/details/71107415/ def curl_es(data): re

54.string field聚合以及fielddata原理初探

主要知识点: 直接对分词的term进行聚合后果 设置fielddata=true 直接用.keyword进行聚合 doc value 的性能问题 一.直接对分词的term进行聚合后果 对于分词的field执行aggregation,发现报错... 1.新建一条数据(隐式创建一个索引和type) POST /test_index/test_type/1 { "test_field":"test" } 2.进行聚合操作 GET /test_index/test_type

es fielddata理解

在es中,text类型的字段使用一种叫做fielddata的查询时内存数据结构.当字段被排序,聚合或者通过脚本访问时这种数据结构会被创建.它是通过从磁盘读取每个段的整个反向索引来构建的,然后存存储在java的堆内存中. fileddata默认是不开启的.Fielddata可能会消耗大量的堆空间,尤其是在加载高基数文本字段时.一旦fielddata已加载到堆中,它将在该段的生命周期内保留.此外,加载fielddata是一个昂贵的过程,可能会导致用户遇到延迟命中.这就是默认情况下禁用fielddat

关于ElasticSearch的聚类时出现fielddata=true问题

https://blog.csdn.net/baristas/article/details/78974090 在ElasticSearch中默认fielddata默认是false的,因为开启Text的fielddata后对内存的占用很高index:megacorptype:employee 如果进行聚合查询时候: GET /megacorp/employee/_search{ "aggs": { "all_interests": { "terms&quo

【ES】学习9-聚合2

按时间统计:date_histogram GET /cars/transactions/_search { "size" : 0, "aggs": { "sales": { "date_histogram": { "field": "sold", "interval": "month", "format": "yyyy