Skip to content

Commit

Permalink
Fix SO query for searching across spaces (elastic#83025)
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego committed Nov 10, 2020
1 parent 8c2c9cc commit 796ab89
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 796ab89

Please sign in to comment.