|
@@ -3,9 +3,17 @@ package com.example.nngkxxdp.elk;
|
|
|
import java.io.IOException;
|
|
|
import java.util.*;
|
|
|
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import com.example.nngkxxdp.dao.ElkDao;
|
|
|
+import org.apache.http.HttpHost;
|
|
|
+import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
|
|
|
+import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
|
|
|
+import org.elasticsearch.action.get.GetRequest;
|
|
|
+import org.elasticsearch.action.get.GetResponse;
|
|
|
import org.elasticsearch.action.search.SearchRequest;
|
|
|
import org.elasticsearch.action.search.SearchRequestBuilder;
|
|
|
+import org.elasticsearch.client.RestClient;
|
|
|
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
|
|
import org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket;
|
|
|
import org.elasticsearch.action.search.SearchResponse;
|
|
@@ -245,7 +253,6 @@ public class ElkController {
|
|
|
|
|
|
/**
|
|
|
* 搜索热门文章
|
|
|
- *
|
|
|
* @param page
|
|
|
* @param limit
|
|
|
* @return
|
|
@@ -289,6 +296,23 @@ public class ElkController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 根据id获取文章
|
|
|
+ * @return
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @GetMapping("getarticle")
|
|
|
+ public Map<String, Object> getarticle(Integer id) throws IOException{
|
|
|
+ RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http")));
|
|
|
+ //1.创建请求对象
|
|
|
+ GetRequest request = new GetRequest().index("elk_article").id(String.valueOf(id));
|
|
|
+ //2.客户端发送请求,获取响应对象
|
|
|
+ GetResponse response = client.get(request, RequestOptions.DEFAULT);
|
|
|
+ //3.打印结果信息
|
|
|
+ System.out.println("_id:" + response.getId());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取所有部门
|
|
|
*
|
|
|
* @return
|