Commit b821c2f1 authored by 张辰's avatar 张辰

修改es.index

parent 27fdb913
......@@ -106,7 +106,6 @@ public class RecommendService {
}
}
//HTTP查询python推荐主题
public List<String> refreshPythonRecommendList(String userId) {
if (!"true".equals(enablePython)) {
......
......@@ -25,7 +25,5 @@ public class ReportLogService {
.reportTime(LocalDateTime.now())
.build();
reportLogMapper.insert(entity);
}
}
......@@ -22,6 +22,7 @@ import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.elasticsearch.client.*;
......@@ -35,14 +36,16 @@ import java.util.Map;
@Service
public class ESHelper {
@Value("${es.index}")
private String esIndex;
@Autowired
private RestHighLevelClient client;
public void insert(String index, String type, String id, String json) {
public void insert(String type, String id, String json) {
try {
IndexRequest req = new IndexRequest(index);
IndexRequest req = new IndexRequest(esIndex);
if (StringUtils.isNotBlank(id)) {
req.id(type + "_" + id);
}
......@@ -55,9 +58,9 @@ public class ESHelper {
}
}
public void insert(String index, String type, String id, Map<String, Object> data) {
public void insert(String type, String id, Map<String, Object> data) {
try {
IndexRequest req = new IndexRequest(index);
IndexRequest req = new IndexRequest(esIndex);
if (StringUtils.isNotBlank(id)) {
req.id(type + "_" + id);
}
......@@ -70,9 +73,9 @@ public class ESHelper {
}
}
public SearchHit[] selectLike(String index, SearchSourceBuilder builder) {
public SearchHit[] selectLike(SearchSourceBuilder builder) {
try {
SearchRequest req = new SearchRequest(index);
SearchRequest req = new SearchRequest(esIndex);
req.source(builder);
SearchResponse resp = client.search(req, RequestOptions.DEFAULT);
validStatus(resp.status(), RestStatus.OK);
......@@ -149,7 +152,7 @@ public class ESHelper {
search.query(boolQb).from(0).size(50);
SearchHit[] hits = helper.selectLike("theme", search);
SearchHit[] hits = helper.selectLike(search);
System.out.println(hits.length);
for (SearchHit hit : hits) {
System.out.println(hit.toString());
......
......@@ -16,6 +16,7 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.Arrays;
......@@ -29,8 +30,6 @@ public class ESService {
@Autowired
private ESHelper helper;
private static final String INDEX_THEME = "theme";
public void insertOrUpdateThemes(List<ESThemeQo> qos) {
for (ESThemeQo qo : qos) {
insertOrUpdateTheme(qo);
......@@ -38,7 +37,7 @@ public class ESService {
}
// 只要设置了_id,则直接覆盖
public void insertOrUpdateTheme(ESThemeQo qo) {
helper.insert(INDEX_THEME, String.valueOf(qo.themeType), qo.themeId, JSON.toJSONString(qo));
helper.insert(String.valueOf(qo.themeType), qo.themeId, JSON.toJSONString(qo));
}
public List<ESThemeQo> queryThemeIdByContentAndTitle(String keyword, int from, int size) {
......@@ -55,7 +54,7 @@ public class ESService {
search.query(boolQb).fetchSource(includes, excludes).sort("createTime", SortOrder.DESC).from(from).size(size);
search.query(boolQb).sort("createTime", SortOrder.DESC).from(from).size(size);
SearchHit[] hits = helper.selectLike(INDEX_THEME, search);
SearchHit[] hits = helper.selectLike(search);
return Arrays.stream(hits).map(h -> {
return JsonUtil.toBean(h.getSourceAsString(), ESThemeQo.class);
}).collect(Collectors.toList());
......
......@@ -97,6 +97,7 @@ es:
port: 9200
userName: 1
userPasswd: 2
index: dev
tencent:
cloud:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment