I have a script which indexes a document using the the following mapping:
{
"mappings": {
"rule-check-result": {
"properties": {
"date": {
"type": "date",
"format": "epoch_second"
},
"rule": {
"type": "string",
"index": "not_analyzed"
},
"alert": {
"type": "string",
"index": "not_analyzed"
},
"level": {
"type": "string",
"index": "not_analyzed"
},
"sms": {
"type": "string"
},
"subject": {
"type": "string"
},
"body": {
"type": "string"
}
}
}
}
}
As part of the indexing, the script runs this search:
{
"from": 0,
"size": 1,
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"and": [
{
"term": {
"rule": "Replication"
}
},
{
"term": {
"alert": "Replication Lag"
}
}
]
}
}
},
"sort": {
"date": {
"order": "desc"
}
}
}
When I run the script I get the following in /var/log/elasticsearch/elasticsearch.log:
SearchParseException[No mapping found for [date] in order to sort on];
Caused by: SearchParseException[failed to parse search source [{
"from": 0,
"size": 1,
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"and": [
{
"term": {
"rule": "Replication"
}
},
{
"term": {
"alert": "Replication Lag"
}
}
]
}
}
},
"sort": {
"date": {
"order": "desc"
}
}
}]];
Despite the exception the search actually does return a result.
I have two questions about this:
- Why is this exception generated even though the date field is clearly in the mapping?
- Why does the search return a result even though an exception is generated?