opencrvs / opencrvs-core

A global solution to civil registration
https://www.opencrvs.org
Other
79 stars 58 forks source link

fix: bad requests in elastic search when there is no mapping #7288

Closed naftis closed 2 days ago

naftis commented 2 days ago

When we have no records in ElasticSearch, first load of the application always give an error to console:

[10:38:11.030] ERROR: ElasticSearch: bad request. Error: search_phase_execution_exception: [query_shard_exception] Reason: No mapping found for [dateOfDeclaration] in order to sort on

As it's an non-issue and gets fixed when first declaration is made, it should be ignored from console. ElasticSearch offers a "unmapped_type", which maps the field to any type we want if it doesn't exist. I set it to "keyword" as it's the default we use in the search fields. I amended the search request to include that, unless the advanced sortBy is used.