1、Code -> GitHub https://github.com/liufengji/elasticsearch_api.git 2、源代码 @Test public void termQuery() { // 1 第一field查询 SearchResponse searchResponse = client.prepareSearch("blog").setTypes("article") .setQuery(QueryBuilders.termQuery("content", "全")).get(); // 2 打印查询结果 SearchHits hits = searchResponse.getHits(); // 获取命中次数,查询结果有多少对象 System.out.println("查询结果有:" + hits.getTotalHits() + "条"); Iterator iterator = hits.iterator(); while (iterator.hasNext()) { SearchHit searchHit = iterator.next(); // 每个查询对象 System.out.println(searchHit.getSourceAsString()); // 获取字符串格式打印 } // 3 关闭连接 client.close(); } 3、结果查看