[英]Elasticsearch - Range query doesn't work
為了嘗試此錯誤,我嘗試了使用Elasticsearch 2.x和5.x,但在任何這些方法中均不起作用。
我的Elasticsearch實例中保存了很多日志。 它們具有一個稱為時間戳記的字段,其格式為“ 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"
}
您需要在建立索引之前將日期映射應用於該字段,或者將其重新索引為在提取之前應用了該映射的新索引。
符合您的時間戳格式的映射請求如下所示:
PUT loganalyzer
{
"mappings": {
"logs": {
"properties": {
"timestamp": {
"type": "date",
"format": "YYYY-MM-dd HH-mm-ss.SSS"
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.