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