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));

猜你喜欢

转载自www.cnblogs.com/mojiruo/p/12416204.html