ELK(分布式大数据搜索和日志挖掘及可视化)之实战(先不要审核只是保存一些记录)

logstash 配置

input{
 file{
     path =>"opt/logs/*.sql"
     type =>"logjson"
     start_position => "beginning"
     sincedb_path =>"/dev/null"
  }
}
filter{
  json{
  #将默认中的message内容转换成json内容,并删除message域
  source => "message"
  remove_field =>"message"
  }
}

output{
 elasticsearch{
  hosts =>["172.16.117.93:9200"]
index =>"query"
document_type=> "%{type}"
flush_size=>20000
idle_flush_time =>10
  }
}
es
public class ESsearch{
static Essearch ts=new ESearch();
static Client client =ts.TransportClientContect();
//返回client对象
public Client TransportClientContect(){
Settings settings =Setting.settingsBuilder().put("cluster.name","topic").build();
Client client=null;
try{
client =TransportClient.builder().setting(settings).build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("172.16.117.93"),9300));
}catch(){}
return client;
}
}
}

class ESmain{
static ESearch ts=new ESearch();
static Client client=ts.TransportClientContect();
public static void main(String[] args) throws IOException{
Excel excel =new Excel();
Instant startClock=Instant.now();
System.out.println("开始时间"+startClock );
String index="logstash-sql---3p";
String type="loghson";
String value;
List<String> stringList=new ArrayList<String>();
//scroll模式启动 每次50000
SearchResponse scrollResponse=client.prepareSearch(index)
.setSearchType(SearchType.SCAN).setSize(10000)
.setQuery(QueryBuilders.matchAllQuery())
.setQuery(QueryBuilders.boolQuery()
   .must(QueryBuilders.matchQuery("q1","q1v"))
   .operator(prg.elasticsearch.index.query.MatchQueryBuilder.Operator.AND)
   .must(QueryBuilders.matchQuery("q2","q2v") )
setScroll(TimeVakue.timeValueMinutes(1))
.execute().actionGet();
int count =(int)scrollResponse.getHits().getTotalHits();//第一次不返回数据
for(int i=0,sum=0;sum<count;i++){
scrollResponse=client.prepareSearchScroll(scrollResponse.getScrollId())
     .setScroll(Timevalue.timeValueMinutes(8))
.execute().actionGet();
sum+=scrollResponse.getHits().hits().length;
  for(SearchHit hit:srollResponse.getHits()){
value=hits.getSource.get("param").toString();
stringList.add(value);
      }
File destFile=new File("./output/"+i+".xls");
try{
excel.createStringExcelFile(stringList,destFile);
}catch(){}
StringList.clear();
System.out.println("总数:"+count+"已查到:"+sum);
    }
}


}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值