我在 elasticsearch 中有以下索引項。
{
"_index": "test_index",
"type": "_doc",
"_source": {
"someTitle": "Thank you for your help",
"lastUpdated": 1640085989000}
},
{
"_index": "test_index",
"type": "_doc",
"_source": {
"someTitle": "Thank you for your help",
"lastUpdated": 1640092916012
}
},
{
"_index": "test_index",
"type": "_doc",
"_source": {
"someTitle": "Thank you for your help",
"lastUpdated": 1640092916012
}
}
如何根據該lastUpdated值獲取一個多小時前更新的專案?我一直在嘗試在互聯網上找到的一些解決方案,但其中大部分是用于查詢字串而不是數字欄位。
uj5u.com熱心網友回復:
感覺就像一個range查詢可以完成作業[doc]
您正在尋找的部分是日期范圍
您的查詢應該或多或少像這樣:
GET /<your index>/_search
{
"query": {
"range": {
"lastUpdated": {
"gte": "now-1h"
}
}
}
}
確保您的映射正確,并且lastUpdated具有正確的格式[doc]。
uj5u.com熱心網友回復:
ES 為您提供類似now和h用于簡單日期數學查詢的關鍵字。隨著范圍查詢,您應該能夠做到:
{
"query": {
"range": {
"lastUpdated": {
"lt": "now-1h"
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/388705.html
上一篇:將模板模板引數限制為兩種型別之一
