Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Kwan的解忧杂货铺@新空间代码工作室
elasticsearch-demo
提交
72313b0e
E
elasticsearch-demo
项目概览
Kwan的解忧杂货铺@新空间代码工作室
/
elasticsearch-demo
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
elasticsearch-demo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
72313b0e
编写于
5月 14, 2023
作者:
Kwan的解忧杂货铺@新空间代码工作室
🐭
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:爬取数据
上级
72d39140
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
20 addition
and
12 deletion
+20
-12
pom.xml
pom.xml
+2
-2
src/main/java/com/kwan/shuyu/controller/ContentController.java
...ain/java/com/kwan/shuyu/controller/ContentController.java
+3
-2
src/main/java/com/kwan/shuyu/service/impl/ContentServiceImpl.java
.../java/com/kwan/shuyu/service/impl/ContentServiceImpl.java
+11
-5
src/main/resources/application.yml
src/main/resources/application.yml
+1
-1
src/test/java/es_02_index/TestIndex_08_close.java
src/test/java/es_02_index/TestIndex_08_close.java
+1
-1
src/test/java/es_04_agg/TestAggs_05.java
src/test/java/es_04_agg/TestAggs_05.java
+2
-1
未找到文件。
pom.xml
浏览文件 @
72313b0e
...
...
@@ -15,7 +15,7 @@
<dependency>
<groupId>
org.elasticsearch.client
</groupId>
<artifactId>
elasticsearch-rest-high-level-client
</artifactId>
<version>
7.
12
.0
</version>
<version>
7.
3
.0
</version>
<exclusions>
<exclusion>
<groupId>
org.elasticsearch
</groupId>
...
...
@@ -26,7 +26,7 @@
<dependency>
<groupId>
org.elasticsearch
</groupId>
<artifactId>
elasticsearch
</artifactId>
<version>
7.
12
.0
</version>
<version>
7.
3
.0
</version>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
...
...
src/main/java/com/kwan/shuyu/controller/ContentController.java
浏览文件 @
72313b0e
...
...
@@ -5,6 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
java.io.IOException
;
...
...
@@ -24,9 +25,9 @@ public class ContentController {
* @return
* @throws Exception
*/
@GetMapping
(
"/parse
/{keyword}
"
)
@GetMapping
(
"/parse"
)
@ResponseBody
public
Boolean
parse
(
@
PathVariable
String
keyword
)
throws
Exception
{
public
Boolean
parse
(
@
RequestParam
(
value
=
"keyword"
)
String
keyword
)
throws
Exception
{
return
contentService
.
parseContent
(
keyword
);
}
...
...
src/main/java/com/kwan/shuyu/service/impl/ContentServiceImpl.java
浏览文件 @
72313b0e
...
...
@@ -29,22 +29,28 @@ import java.util.concurrent.TimeUnit;
@Service
public
class
ContentServiceImpl
implements
ContentService
{
@Autowired
private
RestHighLevelClient
restHighLevelClient
;
@Autowired
private
HtmlParseUtil
htmlParseUtil
;
@Autowired
private
RestHighLevelClient
restHighLevelClient
;
//1.解析数据放入es索引中
/**
* 解析数据放入es索引中
*
* @param keywords
* @return
* @throws Exception
*/
@Override
public
Boolean
parseContent
(
String
keywords
)
throws
Exception
{
List
<
Content
>
contents
=
htmlParseUtil
.
parseJD
(
keywords
);
//把查询出来的数据放入es里面
BulkRequest
bulkRequest
=
new
BulkRequest
();
bulkRequest
.
timeout
(
"2m"
);
bulkRequest
.
timeout
(
TimeValue
.
timeValueMinutes
(
120
)
);
for
(
int
i
=
0
;
i
<
contents
.
size
();
i
++)
{
System
.
out
.
println
(
contents
.
get
(
i
));
bulkRequest
.
add
(
new
IndexRequest
(
"jd_goods
_2"
,
keywords
+
""
)
new
IndexRequest
(
"jd_goods
"
+
keywords
,
keywords
+
""
)
.
source
(
JSON
.
toJSONString
(
contents
.
get
(
i
)),
XContentType
.
JSON
));
}
BulkResponse
bulk
=
restHighLevelClient
.
bulk
(
bulkRequest
,
RequestOptions
.
DEFAULT
);
...
...
src/main/resources/application.yml
浏览文件 @
72313b0e
server
:
port
:
40100
port
:
8888
spring
:
application
:
...
...
src/test/java/es_02_index/TestIndex_08_close.java
浏览文件 @
72313b0e
package
es_02_index
;
import
org.elasticsearch.action.admin.indices.close.CloseIndexRequest
;
import
org.elasticsearch.action.support.master.AcknowledgedResponse
;
import
org.elasticsearch.client.RequestOptions
;
import
org.elasticsearch.client.RestHighLevelClient
;
import
org.elasticsearch.client.indices.CloseIndexRequest
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
src/test/java/es_04_agg/TestAggs_05.java
浏览文件 @
72313b0e
...
...
@@ -68,7 +68,8 @@ public class TestAggs_05 {
searchSourceBuilder
.
size
(
0
);
searchSourceBuilder
.
query
(
QueryBuilders
.
matchAllQuery
());
DateHistogramAggregationBuilder
dateHistogramAggregationBuilder
=
AggregationBuilders
.
dateHistogram
(
"date_histogram"
).
field
(
"sold_date"
).
calendarInterval
(
DateHistogramInterval
.
QUARTER
)
.
format
(
"yyyy-MM-dd"
).
minDocCount
(
0
).
extendedBounds
(
new
ExtendedBounds
(
"2019-01-01"
,
"2020-12-31"
));
.
format
(
"yyyy-MM-dd"
).
minDocCount
(
0
)
.
extendedBounds
(
new
ExtendedBounds
(
"2019-01-01"
,
"2020-12-31"
));
SumAggregationBuilder
sumAggregationBuilder
=
AggregationBuilders
.
sum
(
"income"
).
field
(
"price"
);
dateHistogramAggregationBuilder
.
subAggregation
(
sumAggregationBuilder
);
searchSourceBuilder
.
aggregation
(
dateHistogramAggregationBuilder
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录