Skip to content

Commit

Permalink
Simplify index mapping of item authors
Browse files Browse the repository at this point in the history
Map all fields as keywords
  • Loading branch information
eronisko committed Mar 14, 2024
1 parent 5b76925 commit 1c378e5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions app/Http/Controllers/Api/V1/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ public function aggregations(Request $request)
'multi_terms' => [
'terms' => [
[
'field' => 'authors.name.keyword',
'field' => 'authors.name',
],
[
'field' => 'authors.authority.id.keyword',
'field' => 'authors.authority.id',
'missing' => '',
],
],
Expand Down Expand Up @@ -318,8 +318,8 @@ protected function createQueryBuilder($q, $filter)
$authorsBuilder ??= Query::bool();
$authorsBuilder->should(
is_array($value)
? ['terms' => ["$field.keyword" => $value]]
: ['term' => ["$field.keyword" => $value]]
? ['terms' => [$field => $value]]
: ['term' => [$field => $value]]
);
continue;
}
Expand Down
12 changes: 12 additions & 0 deletions config/elasticsearch/mapping/items.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@
],
'authors' => [
'type' => 'nested',
'properties' => [
'name' => [
'type' => 'keyword',
],
'authority' => [
'properties' => [
'id' => [
'type' => 'keyword',
],
],
],
],
],
'authority_id' => [
'type' => 'keyword',
Expand Down

0 comments on commit 1c378e5

Please sign in to comment.