Bug 19481

Summary: Elasticsearch - Set default fields for sorting in mappings.yaml
Product: Koha Reporter: Nick Clemens <nick>
Component: Searching - ElasticsearchAssignee: Nick Clemens <nick>
Status: CLOSED FIXED QA Contact: Julian Maurice <julian.maurice>
Severity: major    
Priority: P5 - low CC: david.bourgault, fridolin.somers, jonathan.druart, julian.maurice, severine.queune, tomascohen
Version: Main   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Bug Depends on:    
Bug Blocks: 19482    
Attachments: Bug 19481 - Set default sort options as sortable in ES default mappings
Bug 19481 - Set default sort options as sortable in ES default mappings
Bug 19481 - Set default sort options as sortable in ES default mappings

Description Nick Clemens 2017-10-18 10:31:23 UTC
Currently sorting options are hardcoded, some of the options are not defined as sortable in the default ES mappings leading to search errors
Comment 1 Nick Clemens 2017-10-18 10:33:56 UTC
Created attachment 68241 [details] [review]
Bug  19481 - Set default sort options as sortable in ES default mappings

To test:
1 - Setup Koha with ES
2 - perform a search
3 - try sorting by pubdate, acqdate, popularity, or title
4 - Search fails!
5 - Apply patch
6 - visit:
/cgi-bin/koha/admin/searchengine/elasticsearch/mappings.pl?op=reset&i_know_what_i_am_doing=1
7 - Re-index ES
8 - Perform search
9 - All sorting options should work
Comment 2 Fridolin Somers 2017-10-18 13:43:03 UTC
For UNIMARC, mapping for sorting by popularity is not really defined.
We could use 942$0 like in MARC21.
Comment 3 David Bourgault 2017-10-27 19:43:00 UTC
Created attachment 68788 [details] [review]
Bug 19481 - Set default sort options as sortable in ES default mappings

To test:
1 - Setup Koha with ES
2 - perform a search
3 - try sorting by pubdate, acqdate, popularity, or title
4 - Search fails!
5 - Apply patch
6 - visit:
/cgi-bin/koha/admin/searchengine/elasticsearch/mappings.pl?op=reset&i_know_what_i_am_doing=1
7 - Re-index ES
8 - Perform search
9 - All sorting options should work

Signed-off-by: David Bourgault <david.bourgault@inlibro.com>
Comment 4 David Bourgault 2017-10-27 19:44:25 UTC
Test worked as planned, however sorting by title and author seemed strange. I assume the issue wasn't introduced by this bug, but looking at the results list, it did not seem alphabetical to me.
Comment 5 Nick Clemens 2017-11-05 02:04:36 UTC
(In reply to David Bourgault from comment #4)
> Test worked as planned, however sorting by title and author seemed strange.
> I assume the issue wasn't introduced by this bug, but looking at the results
> list, it did not seem alphabetical to me.

See bug 19581 and bug 18827 for ordering issues
Comment 6 Julian Maurice 2017-11-10 10:34:11 UTC
Patch works as described (except for popularity when in UNIMARC, since the field is not defined).
But I wonder about 6th step in test plan. Shouldn't it be done in an updatedatabase script ?
Comment 7 Nick Clemens 2017-11-17 17:27:46 UTC
(In reply to Julian Maurice from comment #6)
> Patch works as described (except for popularity when in UNIMARC, since the
> field is not defined).
> But I wonder about 6th step in test plan. Shouldn't it be done in an
> updatedatabase script ?

I am not sure - if someone has custom mappings setup for some reasonn I don't think we want to alter them.

I think i would prefer to follow up on 19542 and add a warning if standard sort fields are not defined. Does that sound reasonable?
Comment 8 Julian Maurice 2017-11-20 08:07:48 UTC
(In reply to Nick Clemens from comment #7)
> I am not sure - if someone has custom mappings setup for some reasonn I
> don't think we want to alter them.
> 
> I think i would prefer to follow up on 19542 and add a warning if standard
> sort fields are not defined. Does that sound reasonable?
Ok
Comment 9 Julian Maurice 2017-11-20 08:08:01 UTC
Created attachment 69224 [details] [review]
Bug 19481 - Set default sort options as sortable in ES default mappings

To test:
1 - Setup Koha with ES
2 - perform a search
3 - try sorting by pubdate, acqdate, popularity, or title
4 - Search fails!
5 - Apply patch
6 - visit:
/cgi-bin/koha/admin/searchengine/elasticsearch/mappings.pl?op=reset&i_know_what_i_am_doing=1
7 - Re-index ES
8 - Perform search
9 - All sorting options should work

Signed-off-by: David Bourgault <david.bourgault@inlibro.com>
Signed-off-by: Julian Maurice <julian.maurice@biblibre.com>
Comment 10 Jonathan Druart 2017-11-26 16:26:22 UTC
Pushed to master for 17.11, thanks to everybody involved!