【问题描述】:
需求:对员工信息进行聚合分析
1.先对员工按照国家country分组,然后再按入职年限join_date进行分组,分组后在计算组内平均薪资
员工数据如下:
{
"took": 4,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 5,
"max_score": 1,
"hits": [
{
"_index": "company",
"_type": "employee",
"_id": "5",
"_score": 1,
"_source": {
"name": "mike",
"age": 37,
"position": "finance manager",
"country": "usa",
"join_date": "2015-01-01",
"salary": 15000
}
},
{
"_index": "company",
"_type": "employee",
"_id": "2",
"_score": 1,
"_source": {
"name": "marry",
"age": 35,
"position": "technique manager",
"country": "china",
"join_date": "2017-01-01",
"salary": 12000
}
},
{
"_index": "company",
"_type": "employee",
"_id": "4",
"_score": 1,
"_source": {
"name": "jen",
"age": 25,
"position": "junior finance",
"country": "usa",
"join_date": "2016-01-01",
"salary": 7000
}
},
{
"_index": "company",
"_type": "employee",
"_id": "1",
"_score": 1,
"_source": {
"name": "jack",
"age": 27,
"position": "technique",
"country": "china",
"join_date": "2017-01-01",
"salary": 10000
}
},
{
"_index": "company",
"_type": "employee",
"_id": "3",
"_score": 1,
"_source": {
"name": "tom",
"age": 32,
"position": "senior technique software",
"country": "china",
"join_date": "2016-01-01",
"salary": 11000
}
}
]
}
}
java 学习视频中使用的是5.2版本,代码如下
《图1》
no modules loaded
loaded plugin [org.elasticsearch.index.reindex.ReindexPlugin]
loaded plugin [org.elasticsearch.join.ParentJoinPlugin]
loaded plugin [org.elasticsearch.percolator.PercolatorPlugin]
loaded plugin [org.elasticsearch.script.mustache.MustachePlugin]
loaded plugin [org.elasticsearch.transport.Netty4Plugin]
Exception in thread "main" Failed to execute phase [query], all shards failed; shardFailures {[yWbGC_XwQsyJXKZD3kIDgQ][company][0]: RemoteTransportException[[yWbGC_X][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.]; }{[yWbGC_XwQsyJXKZD3kIDgQ