Improve bad request response messages
Related to #57 (closed)
In case the query does not match with the actual structure of the index mapping, ElasticSearch can provide a detailed message that can help a user to understand that query or mapping should be refactored. For example, nested
query running for properties that are not nested in elasticsearch:
{
"kind": "{{data-partition-id}}:wks:master-data--Well:*.*.*",
"query": "nested(data.NameAliases, (AliasName:\"L10-14\" AND AliasNameTypeID:\"osdu:reference-data--AliasNameType:WELL_NAME:\"))"
}
Elasticsearch will respond with such message:
{
"error": {
"root_cause": [{
"type": "query_shard_exception",
"reason": "failed to create query: [nested] failed to find nested object under path [data.NameAliases]",
"index_uuid": "XVFuNDNAQvqrdeAlhykBYw",
"index": "odesprod-wks-master-data--well-1.0.0"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [{
"shard": 0,
"index": "odesprod-wks-master-data--well-1.0.0",
"node": "vozOfr32RhSgpm7dCXzp0g",
"reason": {
"type": "query_shard_exception",
"reason": "failed to create query: [nested] failed to find nested object under path [data.NameAliases]",
"index_uuid": "XVFuNDNAQvqrdeAlhykBYw",
"index": "odesprod-wks-master-data--well-1.0.0",
"caused_by": {
"type": "illegal_state_exception",
"reason": "[nested] failed to find nested object under path [data.NameAliases]"
}
}
}
]
},
"status": 400
}
But for Search service users this message will be suppressed, and they will receive such not descriptive response:
{
"code": 400,
"reason": "Bad Request",
"message": "Invalid parameters were given on search request"
}
We need to improve bad request
response messages, and transfer elasticsearch
reason to users, this will simplify understanding the current data structure (that can be complicated).
Example response:
{
"code": 400,
"reason": "Bad Request",
"message": "failed to create query: [nested] failed to find nested object under path [data.NameAliases]"
}