即使是不成熟的尝试,也胜于胎死腹中的策略。

Java调用 Fielddata is disabled on text fields by default Set fielddata=true on [geoip.city_name]

Elasticsearch | 作者 clean | 发布于2017年08月02日 | 阅读数:9658

 public  void searcher(QueryBuilder queryBuilder, String indexname, String type) throws Exception{
        TermsAggregationBuilder teamAgg= AggregationBuilders.terms("city_count ").field("geoip.city_name").valueType(ValueType.STRING);
        SearchResponse searchResponse = elasticsearchConfig.getObject().prepareSearch(indexname).setSize(10000).setTypes(type).setQuery(queryBuilder).addAggregation(teamAgg).execute().actionGet();
        SearchHits hits = searchResponse.getHits();
        SearchHit[] searchHists = hits.getHits();
        System.out.println("length = " + searchHists.length);
        if(searchHists!=null && searchHists.length>0){
            for(SearchHit hit : searchHists){
                Object id = hit.getSource().get("geoip");
                System.out.println("id = " + id);
            }
        }
    }
 
 
错误: 
 
 
java.lang.IllegalArgumentException: Fielddata is disabled on text fields by default. Set fielddata=true on [geoip.city_name] 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.
    at org.elasticsearch.index.mapper.TextFieldMapper$TextFieldType.fielddataBuilder(TextFieldMapper.java:336)
 
这个  fielddata=true  用java api 如何设置?
已邀请:

要回复问题请先登录注册