{
"_source": "dob",
"query": {
"bool": {
"must": [
{
"term": {
"dob": "01/01/1965"
}
}
]
}
}
}
I'm getting documents having 11/01/1965, 12/01/1965, 01/01/1965 etc So I need to get only documents that are matched with this date 01/01/1965
I tried with this and it work (elastic version 6.8), if you provide more information or a simple use case it may help to figure out the problem.
If you use a different version >7 you need to make some small changes, check the documentation.
# delete any previous index to start from clean version
DELETE my_index
# set a mapping as guessed from your question
PUT my_index
{
"mappings": {
"_doc": {
"properties": {
"dob": {
"type": "date",
"format": "MM/dd/yyyy"
}
}
}
}
}
# put several document as in your first question.
POST _bulk
{ "index" : { "_index" : "my_index", "_type" : "_doc", "_id" : "1" } }
{ "dob" : "01/01/1965" }
{ "index" : { "_index" : "my_index", "_type" : "_doc", "_id" : "2" } }
{ "dob" : "01/11/1965" }
{ "index" : { "_index" : "my_index", "_type" : "_doc", "_id" : "3" } }
{ "dob" : "12/01/1965" }
# make a term search
GET my_index/_doc/_search
{
"query": {
"bool": {
"must": [
{
"term": {
"dob": "01/01/1965"
}
}
]
}
}
}
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.