diff --git a/lib/controllers/v1/search_controller.js b/lib/controllers/v1/search_controller.js index a6b636e9..7cd22fcc 100644 --- a/lib/controllers/v1/search_controller.js +++ b/lib/controllers/v1/search_controller.js @@ -78,11 +78,11 @@ SearchController.search = async req => { }, // match the nested name_autocomplete field in the taxa index { - constant_score: { - filter: { - nested: { - path: "names", - ignore_unmapped: true, + nested: { + path: "names", + ignore_unmapped: true, + query: { + function_score: { query: { match: { "names.name_autocomplete": { @@ -92,10 +92,16 @@ SearchController.search = async req => { operator: "and" } } - } + }, + script_score: { + script: { + source: "doc['names.is_valid'].size() == 0 || doc['names.is_valid'].value == false ? 0.5 : 2.0" + } + }, + boost_mode: "replace", + score_mode: "max" } - }, - boost: 2 + } } }, // boost exact matches in the taxa index