您可以使用range filter https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-range-filter.html为此,通过使用相同的日期gte
/ lte
and a format
仅指定日期部分的参数(即省略时间部分)
{
"constant_score": {
"filter": {
"range" : {
"IH_PT_DSC" : {
"gte": "2015-04-02",
"lte": "2015-04-02",
"format": "yyyy-MM-dd"
}
}
}
}
}
如果您需要指定多个日期,也可以轻松完成。
{
"constant_score": {
"filter": {
"range" : {
"IH_PT_DSC" : {
"gte": "2015-04-01",
"lte": "2015-04-03",
"format": "yyyy-MM-dd"
}
}
}
}
}
最后,如果您需要查询不相交的日期间隔,只需使用bool/should
filter:
{
"constant_score": {
"filter": {
"bool": {
"should": [
{
"range": { <--- interval 1
"IH_PT_DSC": {
"gte": "2015-04-01",
"lte": "2015-04-03",
"format": "yyyy-MM-dd"
}
}
},
{
"range": { <--- interval 2
"IH_PT_DSC": {
"gte": "2015-04-05",
"lte": "2015-04-08",
"format": "yyyy-MM-dd"
}
}
},
{
"range": { <--- interval 3
"IH_PT_DSC": {
"gte": "2015-04-10",
"lte": "2015-04-12",
"format": "yyyy-MM-dd"
}
}
}
]
}
}
}
}