Reputation: 2561
I need to do a search through multiple fields including a datetime field.
The search query may or may not contain date values specified in different formats:
Query sting might contain some term that cannot be converted to date time.
Is there any way I can support that types of query using elastic search?
Upvotes: 0
Views: 4796
Reputation: 2561
Here what I dig up during my investigation:
I use multi_field feature of Elastic search. I added string searchable text field for date type feature.
Here is the mapping I using for date type field:
"TransactionDate":{
"type":"multi_field",
"fields":{
"TransactionDate":{
"type":"date",
"format":"YYYY-MM-dd HH:mm:ss||MM/dd/yyyy||yyyy/MM/dd",
"index":"not_analyzed"
},
"formatted":{
"type":"string",
"index":"analyzed"
}
}
}
Then I am able to include TransactionDate.formatted
field to search query that using textual fields.
Hope that helps somebody else.
Upvotes: 3