There is currently a block in Koha::SearchEngine::Elasticsearch::marc_records_to_documents that in my opinion should be brokwn out to its own method for increased maintainability and readability. It's easily done that these two blocks will drift apart with time (when they should be the same), fixing a bug in one place, forgetting in another etc. Here is a patch to fix this.
Created attachment 178302 [details] [review] Bug 39158: Reduce code duplication in marc_records_to_documents Refactor marc_record_to_documents to avoid code duplicaiton. To test: 1) Verify tests in t/db_dependant/Koha/SearchEngine/Elasticsearch.t all pass 2) Apply patch 3) Veriy tests in t/db_dependant/Koha/SearchEngine/Elasticsearch.t still pass