elasticsearch 時間范圍搜索


如下,首先,你建立的索引mapping 可以是下面這種格式,不要使用代碼自動創建的,手動創建,指定字段類型為 "format": "yyyy-MM-dd HH:mm:ss", "type": "date"

{ 
  "mappings": {
    "company": {
      "properties": {
        "gmtModified": {
          "format": "yyyy-MM-dd HH:mm:ss",
          "type": "date"
        },
        "modifiedBy": {
          "type": "long"
        }
      }
    }
  }
}

然后在代碼中使用:
queryBuilder.must(QueryBuilders.rangeQuery("gmtModified")
.from(gmtModified, true)
.to(gmtModified, true));


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM