1
我有以下字段我elasticsearch获取所需的字段从Elasticsearch
"_source": {
"@timestamp":
"cpu_stat_s": {
"temp_in_celsius":
"model_name":,
"cpu_MHz_String": ,
"cache_size_string":
},
"memory_stat_s": {
"total_memory": ,
"swap_total": ,
"swap_free": ,
"used": ,
"free": ,
"swap_used":
},
"process_stat_s": [
{
"process_name": ,
"mem_in_use":,
"process_pid":
}
]
我只是想使用的Java API从elasticsearch得到假设cpu_stat_s和memory_stat_s场,我寻遍查询过滤器,也没有
String source="{\"query\":\"ether_stat_s\"}";
SearchResponse response = client.prepareSearch("cn_*")
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setFrom(0).setSize(10).setExplain(true)
.setPostFilter(FilterBuilders.rangeFilter("@timestamp").from(TIMESTAMP_FROM).to(TIMESTAMP_TO)).**setSource(source).**execute().actionGet();
但我收到所有字段而不是必填字段。
我可以通过获取所有字段,然后使用for循环,并从响应获取源,但它会增加CPU时间incase数十亿记录。我是新的弹性搜索,因此它会是很大的帮助,如果有人可以帮助我