想实现动态多条件下日志查询的功能  
我之前只写过固定匹配的字段,
比如之前查询某用户在某时间段的日志,这样data就只要传三个固定字段,user ,startDate,endDate
现在情况是查询条件变多,比如用户名,系统名,时间段,日志类型。 且不是每个条件都是必须填写,
所以我在server.route里写request.payload.start request.payload.app等等把位置提前占好也没用的。
																				我之前只写过固定匹配的字段,
比如之前查询某用户在某时间段的日志,这样data就只要传三个固定字段,user ,startDate,endDate
现在情况是查询条件变多,比如用户名,系统名,时间段,日志类型。 且不是每个条件都是必须填写,
所以我在server.route里写request.payload.start request.payload.app等等把位置提前占好也没用的。
server.route({
    path: "/log-monitor/backdate",
    method: "POST",
    config: {
      payload: {
        output: "data",
        parse: true,
        allow: "application/json"
      }
    },
    handler(request, reply) {
      console.log(request.payload);
      const { callWithRequest } = server.plugins.elasticsearch.getCluster(
        "data"
      );
      callWithRequest(request, "search", {
        index: " logstash-*",
        body: {
          query: {
            bool: {  
              must:[
                {match: { user: request.payload.user }},
                {match: { app: request.payload.app }}
              ],
              filter: {
                range: {
                  "@timestamp": {
                    gte: request.payload.start,
                    lte: request.payload.end
                  }
                }
              }
            }
          },
          from: request.payload.currentPage,
          size:25,
          sort: [{ "@timestamp": "desc" }]
        }
      }).then(response => {
        reply(response);
      });
    }
  });var data = {
        user: $scope.userName,
        start: startDate($scope.dateRangeStart),
        end: endDate($scope.dateRangeEnd),
        app:$scope.app,
        level:$scope.level,
      };
      console.log(data)
        $http.post(url, data).success(function(req) {
        console.log(req)
        })
 
	
1 个回复
rochy - rochy_he
赞同来自: