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 就解决了

你可能感兴趣的:(Elasticsearch)