在ElasticSearch中搜索大文本的整个短语需要很长时间

时间:2017-05-25 11:16:41

标签: elasticsearch

我将Tomcat的日志存储在ElasticSearch服务中。日志colud有超过5k个字符。当我仅通过时间戳搜索时,搜索以毫秒结束。当指数计数很短时,搜索速度很快,但现在指数的数量大约是37万,而整个短语的搜索需要花费很多时间。我尝试在结果中使用filter或post_filter并搜索短语,但它需要相同的时间段。 我使用了关键字标记符,因为我想在logLines中搜索带有“/”等特殊字符的整个短语。如何改进查询或映射以加快搜索速度?

编辑:

我认为它可以先按文本搜索而不是按日期过滤,因为如果日志计数很短,并且时间戳之间的日志数相同,则搜索速度非常快。现在它获得相同数量的日志,并且非常慢。即使我使用了post_filter。

这是我的映射:

{
  "settings": {
    "analysis": {
      "analyzer": {
        "logs_string_analyzer": {
          "type": "custom",
          "filter": [
            "lowercase"
          ],
          "tokenizer": "keyword"
        }
      }
    }
  },
  "mappings": {
    "log": {
      "properties": {
        "level": {
           "type": "long"
         },
         "logLines": {
           "type": "text",
           "analyzer": "logs_string_analyzer"
         },
         "timestamp": {
           "type": "long"
         }
       }
     }
   } 
 }

这是我的疑问:

{
  "size" : 30,
  "query" : {
    "bool" : {
      "must" : [
        {
          "wildcard" : {
            "logLines" : {
              "wildcard" : "*XYZ*",
              "boost" : 1.0
            }
          }
        },
        {
          "range" : {
            "timestamp" : {
              "from" : null,
              "to" : 1495705598305,
              "include_lower" : true,
              "include_upper" : true,
              "boost" : 2.0
            }
          }
        },
        {
          "range" : {
            "timestamp" : {
              "from" : 1495705501496,
              "to" : null,
              "include_lower" : false,
              "include_upper" : true,
              "boost" : 2.0
            }
          }
        }
      ]
    }
  },
  "sort" : [
    {
      "timestamp" : {
        "order" : "desc"
      }
    }
  ]
}

使用post_filtter和query_string而不是通配符进行查询:

{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "timestamp": {
              "from": null,
              "to": 1495705598305,
              "include_lower": true,
              "include_upper": true,
              "boost": 2
            }
          }
        },
        {
          "range": {
            "timestamp": {
              "from": 1495705501496,
              "to": null,
              "include_lower": false,
              "include_upper": true,
              "boost": 2
            }
          }
        }
      ]
    }
  },
  "post_filter": {
    "query_string": {
      "default_field": "logLines",
      "query": "*XYZ*"
    }
  }
}

0 个答案:

没有答案
相关问题