【问题标题】:How to search on a URL exactly in ElasticSearch / Kibana如何在 ElasticSearch / Kibana 中准确搜索 URL
【发布时间】:2014-10-14 20:52:05
【问题描述】:

我已导入 IIS 日志文件,数据已通过 Logstash (1.4.2) 移动到 ElasticSearch (1.3.1) 中,然后显示在 Kibana 中。

我的过滤部分如下:

filter {
  grok {
     match => 
        ["message" , "%{TIMESTAMP_ISO8601:iisTimestamp} %{IP:serverIP} %{WORD:method} %{URIPATH:uri} - %{NUMBER:port} - %{IP:clientIP} - %{NUMBER:status} %{NUMBER:subStatus} %{NUMBER:win32Status} %{NUMBER:timeTaken}"]
  }
}

在 Kibana 中使用术语面板并使用“uri”(我从 Logstash 中捕获的字段之一)时,它会匹配 URI 中的令牌。因此它匹配如下项目:

  • '脚本'
  • '/'
  • 'ZH

问:如何以完整形式显示“热门 URL”?

问:我如何通知 ElasticSearch 该字段是“未分析的”。我不介意有 2 个字段,例如:

  • uri - 标记化的 URI
  • uri.raw - 完整的 URL。

这可以在 Logstash 端完成,还是需要在 ElasticSearch 中设置映射?


映射如下:

//http://localhost:9200/iislog-2014.10.09/_mapping?pretty

{
  "iislog-2014.10.09" : {
    "mappings" : {
      "iislogs" : {
        "properties" : {
          "@timestamp" : {
            "type" : "date",
            "format" : "dateOptionalTime"
          },
          "@version" : {
            "type" : "string"
          },
          "clientIP" : {
            "type" : "string"
          },
          "device" : {
            "type" : "string"
          },
          "host" : {
            "type" : "string"
          },
          "id" : {
            "type" : "string"
          },
          "iisTimestamp" : {
            "type" : "string"
          },
          "logFilePath" : {
            "type" : "string"
          },
          "message" : {
            "type" : "string"
          },
          "method" : {
            "type" : "string"
          },
          "name" : {
            "type" : "string"
          },
          "os" : {
            "type" : "string"
          },
          "os_name" : {
            "type" : "string"
          },
          "port" : {
            "type" : "string"
          },
          "serverIP" : {
            "type" : "string"
          },
          "status" : {
            "type" : "string"
          },
          "subStatus" : {
            "type" : "string"
          },
          "tags" : {
            "type" : "string"
          },
          "timeTaken" : {
            "type" : "string"
          },
          "type" : {
            "type" : "string"
          },
          "uri" : {
            "type" : "string"
          },
          "win32Status" : {
            "type" : "string"
          }
        }
      }
    }
  }
}

【问题讨论】:

  • 向我们展示您的 ES 映射
  • 它是开箱即用的默认设置。没有创建其他映射

标签: elasticsearch logstash kibana logstash-grok


【解决方案1】:

在您的 Elasticsearch 映射中:

url: {
  type: "string",
  index: "not_analyzed"
}

【讨论】:

【解决方案2】:

问题是iislog- 不符合logstash- 格式,因此没有选择模板:

我的索引格式是iislog-YYYY.MM.dd,这没有使用 Logstash 开箱即用的映射。当使用logstash- 索引格式时,Logstash 将为字符串创建 2 对字段。例如uri 是:

  • uri(出现在 Kibana 中)
  • uri.raw(不会出现在 Kibana 中)

请注意,uri.raw 不会出现在 Kibana 中 - 但它是可查询的。

所以使用替代索引的解决方案是:

  1. 别打扰!使用默认的索引格式logstash-%{+YYYY.MM.dd}
  2. file 输入中添加“类型”,以帮助您在 Kibana 中过滤正确的日志(同时使用 logstash- 索引格式)

    input { 
      file {
          type => "iislog"
          ....
      }
    }
    
  3. 在 Kibana 中根据类型应用过滤

如果你真的真的想要不同的索引格式:

  1. default configuration file 复制到一个新文件,比如iislog-template.json
  2. 像这样引用output ==> elasticsearch中的配置文件:

    output {    
       elasticsearch_http {
          host => localhost
          template_name => "iislog-template.json"
          template => "<path to template>"
          index => "iislog-%{+YYYY.MM.dd}"   
       }
    }
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-20
    • 1970-01-01
    • 2017-11-10
    • 1970-01-01
    相关资源
    最近更新 更多