Commit 745e3fa7 by [zhangzhiwei]

修改es读取读取当前月份

parent 442d726b
......@@ -179,6 +179,11 @@
<version>7.0.47</version>
</dependency>
<dependency>
<groupId>com.zhiwei.tools</groupId>
<artifactId>zhiwei-tools</artifactId>
<version>0.1.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
......@@ -22,6 +22,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import com.zhiwei.tools.timeparse.TimeParse;
import com.zhiwei.util.Config;
import com.zhiwei.util.MongoConnection;
import com.zhiwei.util.ReadExcel;
......@@ -131,8 +132,9 @@ public class ESUtil {
}
keys = new ReadExcel().getExcel(path);
try {
String indexName = getIndex(start, type);
for (String key : keys) {
SearchRequestBuilder srb = esClient.prepareSearch(Config.getVal("indexName." + type));
SearchRequestBuilder srb = esClient.prepareSearch(indexName);
BoolQueryBuilder bb = new BoolQueryBuilder();
QueryBuilder matchQuery = QueryBuilders.termQuery("content", key);
bb.should(matchQuery);
......@@ -190,4 +192,40 @@ public class ESUtil {
}
return result;
}
/**
* 根据时间处理微博+网媒 index
* @param start
* @param type
* @return
*/
private static String getIndex(Date startDate,String type){
String index = "network";
if(!type.contains("weibo")){
index = "mediaspider";
}
Date endData = TimeParse.stringFormartDate("2017-08-03 00:00:00");
String year = TimeParse.dateFormartString(startDate, "yyyyMM");
if(endData.before(startDate)){
index = index+"_"+year;
}
return index;
}
/**
* 根据查询时间处理微信大库index
* @param start
* @return
*/
private static String getWechatIndex(Date startDate){
String index = "wx_tanglihua";
Date endData = TimeParse.stringFormartDate("2017-05-01 00:00:00");
String year = TimeParse.dateFormartString(startDate, "yyyyMM");
if(endData.before(startDate)){
index = index+"_"+year;
}
return index;
}
}
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