Bug 26922: Regression tests
[koha.git] / misc / search_tools / export_elasticsearch_mappings.pl
blob5d3f49c8282b93691adea8f8a340c14a95061855
1 #!/usr/bin/perl
3 # This inserts records from a Koha database into elastic search
5 # Copyright 2020 Koha Development Team
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 =head1 NAME
24 export_elasticsearch_mappings.pl - export search_marc_map, search_marc_to_field and search_field tables to YAML
26 =head1 SYNOPSIS
28 B<export_elasticsearch_mappings.pl>
29 [B<-t|--type>]
30 [B<--man>]
32 =head1 DESCRIPTION
34 Export search_marc_map, search_marc_to_field and search_field tables to YAML.
36 =head1 OPTIONS
38 =over
40 =item B<-t|--type>=C<marc21|unimarc|normarc>
42 Only export a specific marc type. All if empty.
44 =item B<--man>
46 Full documentation.
48 =back
50 =head1 IMPLEMENTATION
52 =cut
54 use Modern::Perl;
56 use Koha::Script;
57 use Koha::Database;
58 use Koha::SearchFields;
59 use Koha::SearchMarcMaps;
60 use Koha::SearchEngine::Elasticsearch;
62 use YAML;
63 use Getopt::Long;
64 use Pod::Usage;
66 my $type = '';
67 my $man;
69 GetOptions(
70 't|type=s' => \$type,
71 'man' => \$man,
74 pod2usage( -exitstatus => 0, -verbose => 2 ) if $man;
76 if ( $type && $type !~ /^(marc21|unimarc|normarc)$/ ) {
77 print "Bad marc type provided.\n";
78 pod2usage(1);
81 my $mappings = Koha::SearchEngine::Elasticsearch::raw_elasticsearch_mappings( $type );
83 binmode STDOUT, ":encoding(UTF-8)";
84 print Dump($mappings);