Skip to content

Commit

Permalink
[7.x] Fix SO query for searching across spaces (#83025) (#83046)
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego authored Nov 10, 2020
1 parent 59bdf4a commit 6a2d6b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,11 @@ describe('#getQueryParams', () => {
if (registry.isMultiNamespace(type)) {
const array = [...(namespaces ?? [DEFAULT_NAMESPACE_STRING]), ALL_NAMESPACES_STRING];

const namespacesClause = { terms: { namespaces: array } };
return {
bool: {
must: namespaces?.includes(ALL_NAMESPACES_STRING)
? expect.not.arrayContaining([namespacesClause])
: expect.arrayContaining([namespacesClause]),
? [{ term: { type } }]
: [{ term: { type } }, { terms: { namespaces: array } }],
must_not: [{ exists: { field: 'namespace' } }],
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,19 @@ function getClauseForType(
const searchAcrossAllNamespaces = namespaces.includes(ALL_NAMESPACES_STRING);

if (registry.isMultiNamespace(type)) {
const namespacesFilterClause = searchAcrossAllNamespaces
? {}
: { terms: { namespaces: [...namespaces, ALL_NAMESPACES_STRING] } };
const typeFilterClause = { term: { type } };

const namespacesFilterClause = {
terms: { namespaces: [...namespaces, ALL_NAMESPACES_STRING] },
};

const must = searchAcrossAllNamespaces
? [typeFilterClause]
: [typeFilterClause, namespacesFilterClause];

return {
bool: {
must: [{ term: { type } }, namespacesFilterClause],
must,
must_not: [{ exists: { field: 'namespace' } }],
},
};
Expand Down

0 comments on commit 6a2d6b1

Please sign in to comment.