date - Elasticsearch-范围查询不起作用

标签 date elasticsearch search range

为了尝试这个错误,我尝试使用Elasticsearch 2.x和5.x,但不适用于其中任何一个。

我在Elasticsearch实例中保存了很多日志。它们具有一个名为 timestamp 的字段,其格式为“YYYY-MM-dd HH-mm-ss.SSS”(例如,“2017-11-02 00:00:00.000”)。当我尝试通过POSTMAN发送查询时,这是这样的:

{
  "query": {
    "range": {
        "timestamp": {
          "gte": "2017-10-21 00:00:00.000",
          "lte": "2017-10-27 00:00:00.000"
        }
      }
  }
}

我什么也没收到,在该范围内有500多个日志。我究竟做错了什么?

编辑:
我的索引(loganalyzer):
{
  "loganalyzer" : {
    "aliases" : { },
    "mappings" : {
      "logs" : {
        "properties" : {
          "entireLog" : {
            "type" : "string"
          },
          "formattedMessage" : {
            "type" : "string"
          },
          "id" : {
            "type" : "string"
          },
          "level" : {
            "type" : "string"
          },
          "loggerName" : {
            "type" : "string"
          },
          "testNo" : {
            "type" : "string"
          },
          "threadName" : {
            "type" : "string"
          },
          "timestamp" : {
            "type" : "string"
          }
        }
      }
    },
    "settings" : {
      "index" : {
        "refresh_interval" : "1s",
        "number_of_shards" : "5",
        "creation_date" : "1507415366223",
        "store" : {
          "type" : "fs"
        },
        "number_of_replicas" : "1",
        "uuid" : "9w3QQQc0S0K0NcKtOERtTw",
        "version" : {
          "created" : "2040699"
        }
      }
    },
    "warmers" : { }
  }
}

我收到的发送请求的内容:
{
    "took": 429,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 0,
        "max_score": null,
        "hits": []
    }
}

并显示状态200(确定)。

最佳答案

您使用映射进行的编辑表明存在问题。之所以没有得到任何结果,是因为它试图根据索引中字段的值(也被视为字符串)为您提供的字符串找到一个“范围”。

      "timestamp" : {
        "type" : "string"
      }

Here's the elastic documentation on that mapping type

您需要在建立索引之前将日期映射应用于该字段,或者将其重新索引为在导入之前应用了该映射的新索引。

符合您的时间戳格式的映射请求如下所示:
PUT loganalyzer
{
  "mappings": {
    "logs": {
      "properties": {
        "timestamp": {
          "type":   "date",
          "format": "YYYY-MM-dd HH-mm-ss.SSS"
        }
      }
    }
  }
}

关于date - Elasticsearch-范围查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47076879/

相关文章:

search - 如何在 Vim 中进行不区分大小写的搜索

Linux 日期格式 hh-mm-ss

jquery - 文本输入字段作为 jQuery 日期选择器默认日期

javascript - 在 Node 中获取文件创建日期

javascript - Google chrome 扩展程序不执行 javascript 代码?

.net - SearchBuilder 在 NEST ElasticSearch 客户端中的使用

elasticsearch - 添加elasticsearch节点多台机器

bash - 将多个函数传递给远程 shell/mkdir 找不到目录

python - 如何在python中搜索并获取DLL文件的目录

java - 在 SD 卡上组织数据以便快速搜索的最佳方式