java核心代码如下
SearchResponse searchResponse = client.prepareSearch(Constants.ES_INDEX_COMPANY)
.addAggregation(AggregationBuilders.terms("group_by_country").field("country")
.subAggregation(AggregationBuilders.dateHistogram("group_by_join_date").field("join_date")
.dateHistogramInterval(DateHistogramInterval.YEAR)
.subAggregation(AggregationBuilders.avg("avg_salary").field("salary"))))
.execute().actionGet();
执行结果报如下的错:
Exception in thread "main" Failed to execute phase [query], all shards failed; shardFailures {[SLYuyauWSNeIP7vedKA6JA][company][0]: RemoteTransportException[[SLYuyau][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[Fielddata is disabled on text fields by default. Set fielddata=true on [country] 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.]; }{[SLYuyauWSNeIP7vedKA6JA][company][1]: RemoteTransportException[[SLYuyau][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[Fielddata is disabled on text fields by default. Set fielddata=true on [country] 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.]; }{[SLYuyauWSNeIP7vedKA6JA][company][2]: RemoteTransportException[[SLYuyau][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: IllegalArgumentException[Fielddata is disabled on text fields by default. Set fielddata=true on [country] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively