Skip to content
Snippets Groups Projects
Commit a311b346 authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- fixed parts of query builder in prepare_query()

parent 3b42eed6
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,7 @@ sub query_elasticsearch($protocol, $host, $port, $index_name, $query_hash, $opti
$local_query_hash->{_source}="false"; # avoids transfering complete source tree in results
}
my $e = _instantiate($protocol, $host, $port);
my $res = $e->search(
index => $index_name,
body => $local_query_hash, #hashref
......@@ -61,123 +62,27 @@ sub query_elasticsearch_count($protocol, $host, $port, $index_name, $query_hash)
sub prepare_query ($opt) {
my @must;
my @should;
# example query:
# query => {
# bool => {
# must =>
# [
# {
# match => {
# "transferMetadata.SLUBArchiv-externalWorkflow", "testcases",
# },
# },
# ],
# should => [
# {
# match => {
# "transferMetadata.SLUBArchiv-externalId", "test-sip_2020-07-17_13-40-17_96152",
# },
# }
# ]
# },
# }
# Is a SLUB-specific ID in the archive?
# curl -XGET -H 'Content-Type: application/json'
# 'localhost:9200/aips/_search?pretty=true' -d '
# {
# "query": {
# "term": {
# "transferMetadata.SLUBArchiv-lzaId.keyword":
# "SLUB:LZA:testworkflow:testcases:test-sip_2020-07-17_13-40-17_96152"
# }
# }
# }'
#
# What is the "SLUBArchiv-exportToArchiveDate" value of all matches
# curl -XGET -H 'Content-Type: application/json'
# 'localhost:9200/aips/_search?pretty=true' -d '
# {
# "query": {
# "match_all": {}
# },
# "_source": [
# "transferMetadata.SLUBArchiv-lzaId",
# "transferMetadata.SLUBArchiv-exportToArchiveDate"
# ]
# }'
#
# Find all AIPs with a SLUB-specific rights status
# curl -XGET -H 'Content-Type: application/json'
# 'localhost:9200/aips/_search?pretty=true' -d '
# {
# "query": {
# "term": {
# "transferMetadata.slubarchiv:rightsRecord_dict.slubarchiv:copyrightStatus.keyw
# ord": "copyrighted"
# }
# },
# "_source": ["uuid"]
# }'
#
# Reporting for a given date range: AIP count,
# number of archived files, size of archived data, etc.
# curl -XGET -H 'Content-Type: application/json'
# 'localhost:9200/aips/_search?pretty=true' -d '
# {
# "query": {
# "range": {
# "created": {
# "gte": 1638313200,
# "lt": 1640991600
# }
# }
# },
# "aggs": {
# "total_size": {"sum": {"field": "size"}},
# "total_file_count": {"sum": {"field": "file_count"}}
# },
# "size": 0
# }'
# Free Search - Find AIPs based on catalog data
# included by producers
# curl -XGET -H 'Content-Type: application/json'
# 'localhost:9200/aips/_search?pretty=true' -d '
# {
#"query": {
# "query_string": {
# "fields": [
# "transferMetadata.record_dict.datafield_dict.subfield",
# "transferMetadata.mods:mods_dict.mods:titleInfo_dict.mods:title"
# ],
# "query": "Riesaer Tageblatt und Anzeiger"
# }
#},
#"_source": ["uuid"]
#}'
if (exists $opt->{source}) {
#push @queries, "IE.sourceMD.content=\"$opt->{source}\"";
}
if (exists $opt->{lzaid}) {
push @must, {
"term" => {
"transferMetadata.SLUBArchiv-lzaId.keyword" =>
"match" => {
"transferMetadata.SLUBArchiv-lzaId" =>
"$opt->{lzaid}"
}
};
}
if (exists $opt->{descriptive}) {
push @should => {
push @should, {
match => {
"transferMetadata.dc" => "$opt->{descriptive}",
}
}
}
if (exists $opt->{creationdate}) {
push @should => {
push @should, {
"created" => $opt->{creationdate}
};
}
......@@ -213,14 +118,14 @@ sub prepare_query ($opt) {
# $must_s= {
# must => [ @must ]
# };
$query->{query}->{bool}->{must} = [ @must ];
$query->{query}->{bool}->{must} = \@must ;
}
my $should_s;
if (scalar @should > 0) {
# $should_s={
# should => [ @should ]
# };
$query->{query}->{bool}->{should} = [ @should ];
$query->{query}->{bool}->{should} = \@should ;
}
if (exists $opt->{debug}) {
......@@ -228,7 +133,9 @@ sub prepare_query ($opt) {
say "opt=", np( $opt);
say "\@must=",np(@must);
say "\@should=",np(@should);
say "QUERY=",np( $query);
say "------------------------";
say "query=",np( $query);
say "------------------------";
}
return $query;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment