EmbeddedDocuments Search multiple compound fields
Today, it doesn't seem that a $search index on a list of object documents allows for an embeddedDocument search to match on multiple properties within the document.
So, if I have:
[{
name: 'Doc 1',
attached: [ { name: 'a', type: 'string' }, { name: 'b', type: 'number' }]
},
{
name: 'Doc 1',
attached: [ { name: 'a', type: 'string' }, { name: 'b', type: 'string' }]
}]
I would like to be able to write a compound query like this:
[
{
$search: {
index: "default",
compound: {
must: [
{
embeddedDocument: {
path: "attached",
operator: {
compound: {
must: [
{
text: {
path: "attached.name",
query:
"b",
},
},
{
autocomplete: {
path: "attached.type",
query: "string",
},
},
],
},
},
},
},
],
},
},
}]
And for it to only find and return this:
{
name: 'Doc 1',
attached: [ { name: 'a', type: 'string' }, { name: 'b', type: 'string' }]
}