java es报错:Fielddata is disabled on text fields by default. Set fielddata=true on [serviceId] in orde

Elasticsearch聚合操作异常:

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

fielddate官方解释https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html#fielddata

解决办法

  1. 修改字段类型为keyword (建议)
  2. 修改字段属性,使用该my_field.keyword字段进行聚合,排序或脚本
PUT my_index 
{ 
  “mappings”:{ 
    “my_type”:{ 
      “properties”:{ 
        “my_field”:{
          “type”:“text”,
          “fields”:{ 
            “keyword”:{
              “type”:“keyword” 
            } 
          } 
        } 
      } 
    } 
  } 
}

java api

String index = "people";
String type = "man";
SearchRequestBuilder searchRequestBuilder = client.prepareSearch(index).setTypes(type);
TermsAggregationBuilder field = AggregationBuilders.terms("my_type123").field("my_type.keyword");
searchRequestBuilder.addAggregation(field);
searchRequestBuilder.setSize(0);
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
System.out.println(searchResponse.toString());

参考

https://blog.youkuaiyun.com/wwd0501/article/details/78490201
http://www.belonk.com/c/elasticsearch_error_fielddata_is_disabled.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/fielddata.html#fielddata

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值