mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-07 01:46:47 +08:00
ES处理
This commit is contained in:
@@ -40,6 +40,9 @@ public interface ICourseFullTextSearch {
|
||||
*/
|
||||
boolean checkHas(String indexName,String id);
|
||||
|
||||
|
||||
boolean reCreateIndex(String indexName) throws Exception;
|
||||
|
||||
/**
|
||||
* 更新一个字段
|
||||
* @param indexName
|
||||
|
||||
@@ -74,6 +74,18 @@ public class CourseElasticsearchImpl implements ICourseFullTextSearch{
|
||||
* @param indexName
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean reCreateIndex(String indexName) throws Exception{
|
||||
boolean isExists = esUtil.isIndexExists(indexName);
|
||||
if(!isExists) {
|
||||
boolean ok =createIndex(indexName);
|
||||
if(!ok) {
|
||||
log.error("创建索引【"+indexName+"】失败");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建索引
|
||||
@@ -99,7 +111,7 @@ public class CourseElasticsearchImpl implements ICourseFullTextSearch{
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
builder.startObject();
|
||||
builder.field("properties").startObject();
|
||||
builder.field("id").startObject().field("index", "true").field("type", "text").endObject();
|
||||
builder.field("id").startObject().field("index", "true").field("type", "keyword").endObject();
|
||||
//builder.field("name").startObject().field("type", "text").field("analyzer", "ik_max_word").field("search_analyzer","ik_smart").endObject();
|
||||
builder.field("name").startObject().field("type", "keyword").endObject();
|
||||
builder.field("keywords").startObject().field("type", "text").field("analyzer", "ik_max_word").field("search_analyzer","ik_smart").endObject();
|
||||
@@ -208,6 +220,15 @@ public class CourseElasticsearchImpl implements ICourseFullTextSearch{
|
||||
@Override
|
||||
public String republish(String indexName, CourseFullText item, String fullTextId) throws Exception{
|
||||
|
||||
boolean isExists = esUtil.isIndexExists(indexName);
|
||||
if(!isExists) {
|
||||
boolean ok =createIndex(indexName);
|
||||
if(!ok) {
|
||||
log.error("创建索引【"+indexName+"】失败");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
String fullId=fullTextId;
|
||||
|
||||
boolean exists=false;
|
||||
|
||||
@@ -55,6 +55,9 @@ public class CourseFullTextApi extends ApiBaseController{
|
||||
if(fullTextSearch==null) {
|
||||
return error("初始化失败:未实现全文检索功能");
|
||||
}
|
||||
//重新创建索引,如果已经存在,不会重新建
|
||||
fullTextSearch.reCreateIndex(ICourseFullTextSearch.DEFAULT_INDEX_NAME);
|
||||
|
||||
//提取课程信息,因为现在课程没有太多,所以一次性全部查出来,
|
||||
CourseQueryDto dto =new CourseQueryDto();
|
||||
dto.setPublish(true);//必须是已发布的
|
||||
|
||||
Reference in New Issue
Block a user