Reputation: 2374
I have documents with a field that contains multiple dates.
"release_date" : [
"2015-07-10",
"2015-07-13",
"2015-07-26",
"2015-07-27"
]
I would like to filter all documents with at least a date greater than a another given date.
I was able to use range filter when the document just had one date
{
"constant_score": {
"filter": {
"range" : {
"release_date" : {
"gte": "2012-01-01",
}
}
}
}
}
But now that I have more than one date, I don't find the way to achieve a similar result. Is it possible?
Thanks!
Upvotes: 0
Views: 268
Reputation: 12459
Make sure that you're "release_date" field is properly mapped to a date object. The following example works for what you're trying to do:
PUT test1
PUT /test1/_mapping/type1
{
"type1" : {
"properties" : {
"release_date" : {"type" : "date"}
}
}
}
POST test1/type1
{
"release_date" : [
"2014-03-28",
"2010-03-28",
"2011-03-28"
]
}
GET test1/type1/_search
{
"query": {
"filtered": {
"filter": {
"range": {
"release_date": {
"gte": "2013-01-01"
}
}
}
}
}
}
Upvotes: 1