Reputation: 327
Given I have a index mapping as following
PUT my_index
{
"mappings": {
"_doc": {
"properties": {
"date": {
"type": "date",
"format": "yyyy-MM-dd||yyyy||yyyy-MM"
}
}
}
}
}
this means I can put documents in all of the allowed date types if I make sure that all documents support the date format yyyy-MM-dd I would like to use the match query to allow me to search across different types such as providing documents that have the field date as follows doc1 - date: 2016-1-1 doc2 - date: 2017-1-4 doc3 - date: 2016-2-1
I want to be able to use the match to provide a query with only 2016 and get back doc2 and doc3 back and I would also like to be able to search using 2016-1 currently elasticsearch does not care and throws no exception as it should use all date types
Upvotes: 0
Views: 1966
Reputation: 608
I think the range query is what you're looking for. I haven't used it myself, so I can't say for sure on the syntax, but something like the following should work:
{
"query": {
"range" : {
"born" : {
"gte": "2016",
"lte": "2016",
"format": "yyyy-MM-dd||yyyy||yyyy-MM"
}
}
}
}
Earlier versions used a range filter instead of a query, but if you're on 5.x or newer, you should be fine with the range query.
Upvotes: 1