[Bug 43885] New: Elasticsearch: sorting on a field without a sort mapping makes the whole search fail
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43885 Bug ID: 43885 Summary: Elasticsearch: sorting on a field without a sort mapping makes the whole search fail Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Searching - Elasticsearch Assignee: koha-bugs@lists.koha-community.org Reporter: adolfo.rodriguez@xercode.es QA Contact: testopia@bugs.koha-community.org Target Milestone: --- QueryBuilder::_sort_field appends "__sort" to the sort field without checking that such a field exists in the index. When a field used for sorting (call number, author, title, date of acquisition, popularity...) is configured as not sortable, or is not mapped at all, Elasticsearch rejects the whole query: No mapping found for [cn-sort__sort] in order to sort on and Koha shows "You did not specify any search criteria" / "Unable to perform your search". If defaultSortField or OPACdefaultSortField points to that field, every search fails. The code was meant to handle fields without a sort mapping (sorting on their .raw version for text fields), but that branch is never reached: get_elasticsearch_mappings only records sortable fields in sort_fields, so a field that is not sortable is indistinguishable from an unknown field, and both get "__sort" appended. The existing tests did not catch it because they mock sort_fields with explicit 0 values. To reproduce: 1. Administration > Search engine configuration (Elasticsearch): set "Sortable" to No for cn-sort and save. 2. Rebuild the index so that the mapping is recreated: misc/search_tools/rebuild_elasticsearch.pl -d -b 3. Search the staff interface and sort by call number: the search fails. 4. Set OPACdefaultSortField to "call number": every OPAC search fails. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43885 Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43885 --- Comment #1 from Adolfo Rodríguez Taboada <adolfo.rodriguez@xercode.es> --- Created attachment 208669 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=208669&action=edit Bug 43885: Do not sort on a non-existent field in Elasticsearch QueryBuilder::_sort_field appended "__sort" to any field that was not recorded as not sortable. As get_elasticsearch_mappings only recorded the sortable fields in sort_fields, a field configured as not sortable was treated like an unknown one and also got "__sort" appended. That field does not exist in the index, so Elasticsearch rejected the whole query ("No mapping found for [cn-sort__sort] in order to sort on") and the search failed. With defaultSortField or OPACdefaultSortField set to such a field, every search failed. This patch: - records the fields without a sort mapping in sort_fields too (as 0, unless another mapping of the same field is sortable), so that _sort_field sorts them on their search field, using the .raw version of text fields, as the code already intended - makes _sort_field return undef, with a warning, for fields that are not mapped at all, and build_query skips that sort, so the results are sorted by relevance instead of failing Steps to follow: 1. Administration > Search engine configuration (Elasticsearch): set "Sortable" to No for cn-sort and save. 2. Rebuild the index so that the mapping is recreated: misc/search_tools/rebuild_elasticsearch.pl -d -b 3. Search the staff interface and sort by call number: the search fails ("Unable to perform your search"), and the logs show "No mapping found for [cn-sort__sort] in order to sort on". 4. Set OPACdefaultSortField to "call number" and search the OPAC: the search fails. 5. Apply the patch and restart Plack if running under it. 6. Repeat steps 3 and 4: the searches work and the results are sorted by call number (ascending and descending). 7. Restore "Sortable" to Yes for cn-sort, rebuild the index as in step 2 and restore OPACdefaultSortField. 8. prove t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t \ t/db_dependent/Koha/SearchEngine/Elasticsearch.t Signed-off-by: Adolfo Rodríguez <adolfo.rodriguez@xercode.es> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43885 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43885 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #208669|0 |1 is obsolete| | -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43885 --- Comment #2 from David Nind <david@davidnind.com> --- Created attachment 208765 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=208765&action=edit Bug 43885: Do not sort on a non-existent field in Elasticsearch QueryBuilder::_sort_field appended "__sort" to any field that was not recorded as not sortable. As get_elasticsearch_mappings only recorded the sortable fields in sort_fields, a field configured as not sortable was treated like an unknown one and also got "__sort" appended. That field does not exist in the index, so Elasticsearch rejected the whole query ("No mapping found for [cn-sort__sort] in order to sort on") and the search failed. With defaultSortField or OPACdefaultSortField set to such a field, every search failed. This patch: - records the fields without a sort mapping in sort_fields too (as 0, unless another mapping of the same field is sortable), so that _sort_field sorts them on their search field, using the .raw version of text fields, as the code already intended - makes _sort_field return undef, with a warning, for fields that are not mapped at all, and build_query skips that sort, so the results are sorted by relevance instead of failing Steps to follow: 1. Administration > Search engine configuration (Elasticsearch): set "Sortable" to No for cn-sort and save. 2. Rebuild the index so that the mapping is recreated: misc/search_tools/rebuild_elasticsearch.pl -d -b 3. Search the staff interface and sort by call number: the search fails ("Unable to perform your search"), and the logs show "No mapping found for [cn-sort__sort] in order to sort on". 4. Set OPACdefaultSortField to "call number" and search the OPAC: the search fails. 5. Apply the patch and restart Plack if running under it. 6. Repeat steps 3 and 4: the searches work and the results are sorted by call number (ascending and descending). 7. Restore "Sortable" to Yes for cn-sort, rebuild the index as in step 2 and restore OPACdefaultSortField. 8. prove t/db_dependent/Koha/SearchEngine/Elasticsearch/QueryBuilder.t \ t/db_dependent/Koha/SearchEngine/Elasticsearch.t Signed-off-by: Adolfo Rodríguez <adolfo.rodriguez@xercode.es> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43885 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |release-notes-needed Assignee|koha-bugs@lists.koha-commun |adolfo.rodriguez@xercode.es |ity.org | CC| |david@davidnind.com --- Comment #3 from David Nind <david@davidnind.com> --- Added assignee 8-). Testing notes (using KTD): 1. Step 1: Administration > Search engine configuration (Elasticsearch) > Bibliographic records. 2. Rebuild Elasticsearch: koha-elasticsearch --rebuild -d -b -a kohadev 3. Log file with the warning: /var/log/koha/kohadev/plack-intranet-error.log -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org