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

https://blog.csdn.net/baristas/article/details/78974090

在ElasticSearch中默认fielddata默认是false的,因为开启Text的fielddata后对内存的占用很高
index:megacorp
type:employee

如果进行聚合查询时候:

GET /megacorp/employee/_search
{
"aggs": {
"all_interests": {
"terms": { "field": "interests" }
}
}
}

返回错误码:

{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "Fielddata is disabled on text fields by default. Set fielddata=true on [interests] 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" : "megacorp",
"node" : "hDWX06IlTiu7gK3ybmsb-g",
"reason" : {
"type" : "illegal_argument_exception",
"reason" : "Fielddata is disabled on text fields by default. Set fielddata=true on [interests] 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
}

提示:fielddata=true未开启
此时需要做的是:

curl -i -H "Content-Type:application/json" -XPUT 127.0.0.1:9200/your_index/_mapping/your_type/?pretty -d‘{"your_type":{"properties":{"your_field_name":{"type":"text","fielddata":true}}}}‘
1
curl -i -H "Content-Type:application/json" -XPUT 127.0.0.1:9200/megacorp/_mapping/employee/?pretty -d‘{"employee":{"properties":{"interests":{"type":"text","fielddata":true}}}}‘
1
interests指的是需要开启fielddata的field

此时再进行测试

"aggregations" : {
"all_interests" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "music",
"doc_count" : 2
},
{
"key" : "forestry",
"doc_count" : 1
},
{
"key" : "sports",
"doc_count" : 1
}
]

就可以看出根据interests来进行聚类的查询结果,在这里就可以根据结果进行兴趣分析等
————————————————
原文链接:https://blog.csdn.net/baristas/article/details/78974090

原文地址:https://www.cnblogs.com/kelelipeng/p/12334926.html

时间: 2024-08-30 15:41:09

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

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

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 }' 提示报

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

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

elasticsearch按照配置时遇到的一些坑 [Failed to load settings from [elasticsearch.yml]]

这里整理几个空格引起的问题. 版本是elasticsearch-2.3.0 或者elasticsearch-rtf-master Exception in thread "main" SettingsException[Failed to load settings from [elasticsearch.yml]]; nested: ElasticsearchParseException[malformed, expected settings to start with 'obje

elasticsearch搜索QueryStringQueryBuilder时的一些问题记录

首先看下原始数据 但是 如果使用英文查询的时候又和上面有点区别了,感觉还是分词器的问题 原文地址:https://www.cnblogs.com/quyf/p/10584690.html

ES 24 - 如何通过Elasticsearch进行聚合检索 (分组统计)

目录 1 普通聚合分析 1.1 直接聚合统计 1.2 先检索, 再聚合 1.3 扩展: fielddata和keyword的聚合比较 2 嵌套聚合 2.1 先分组, 再聚合统计 2.2 先分组, 再统计, 最后排序 2.3 先分组, 组内再分组, 然后统计.排序 1 普通聚合分析 1.1 直接聚合统计 (1) 计算每个tag下的文档数量, 请求语法: GET book_shop/it_book/_search { "size": 0, // 不显示命中(hits)的所有文档信息 &qu

Elasticsearch:fielddata 介绍

默认情况下,大多数字段都已编入索引,这使它们可搜索. 但是,脚本中的排序,聚合和访问字段值需要与搜索不同的访问模式. 搜索需要回答"哪个文档包含该术语?"这个问题,而排序和汇总则需要回答一个不同的问题:"此字段对该文档的值是什么?". 大多数字段可以将索引时生产的磁盘doc_values(https://www.elastic.co/guide/en/elasticsearch/reference/current/doc-values.html)用于此数据访问模式,