elasticsearch数据列过滤restful api以及java代码实现
restful api实现:
POST http://192.168.1.111:9200/film/dongzuo/_search/
{
"from": 0,
"size": 2,
"_source":{
"include":["title","price"]
}
}
Java代码实现:
/** * 数据列过滤 * @throws Exception */ @Test public void searchInclude()throws Exception{ SearchRequestBuilder srb=client.prepareSearch("film").setTypes("dongzuo"); SearchResponse sr=srb.setQuery(QueryBuilders.matchAllQuery()) .setFetchSource(new String[]{"title","price"}, null) .execute() .actionGet(); // 分页排序所有 SearchHits hits=sr.getHits(); for(SearchHit hit:hits){ System.out.println(hit.getSourceAsString()); } }
运行结果: