elasticsearch 聚合操作

项目场景: 使用 elasticsearch 对 网站拉新统计(es版本6.3.2)  需要类似 

select  count(distinct columns) from tables 

使用  es   AggregationBuilder  实现 count (distinct)  

AggregationBuilder agg = AggregationBuilders.cardinality("uvip").field("http_x_forwarded_for");
PUT index/_mapping/type
{
  "properties": {
       "field":{
             "type": "text"
              , "fielddata":true 
       }
  }
}

 

程序运行时 报错: (数据清洗load 到es 中的字段 为 text 类型)

Fielddata is disabled on text fields by default. Set fielddata=true on [content_id] in order to load fielddata in memory by uninverting the inverted index

Set fielddata=true on [id]

ElasticsearchStatusException[Elasticsearch exception [type=search_phase_execution_exception, reason=all shards failed]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Fielddata is disabled on text fields by default. Set fielddata=true on [http_x_forwarded_for] 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.]]; nested: ElasticsearchException[Elasticsearch exception [type=illegal_argument_exception, reason=Fielddata is disabled on text fields by default. Set fielddata=true on [http_x_forwarded_for] 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.]];

通过 上面的 PUT 操作   仍报错 ,

different [norms] values, cannot change from disable to enabled

解决方案: 咨询了阿里的工程师 

 

PUT myindex/_mapping/mytype
{
  "properties": {
       "http_x_forwarded_for":{
             "type": "text"
              , "fielddata":true
              ,  "norms": false
       }
  }
}

在kibana 控制台上加入  norms: false 就解决了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值