2 / 5
Oct 2024

I have the below document

{ "_id": "101", "PublisherName": "Big book publishers", "PublisherAddress": "123 Mian Street", "Books": [ { "_id": "6791913210", "Title": "Piano made simple", "Author": "John Bent" }, { "_id": "6638200210", "Title": "Guitar made simple", "Author": "Kim Larry" } ] }

I would like to perform a Compound “MUST” search across the root fields (PublisherName,PublisherAddress) and embeded document fields (Title, Author) at the same time.

Using the below Compound “Must” aggregation on the root document fields work OK. This e aggregation will return the sample document above

{ "$search": { "index": "my-book-Index", "compound": { "must": [ { "text": { "query": "Big", "path": [ "PublisherName", "PublisherAddress" ] } }, { "text": { "query": "Street", "path": [ "PublisherName", "PublisherAddress" ] } } ] } } }

But the Compound “Must” aggregation is faling to find a document when I add the EmbeddedDocument to the aggregation.

{ "$search": { "index": "my-book-Index", "compound": { "must": [ { "text": { "query": "Big", "path": [ "PublisherName", "PublisherAddress" ] } }, { "text": { "query": "Piano", "path": [ "PublisherName", "PublisherAddress" ] } }, { "embeddedDocument": { "operator": { "compound": { "must": [ { "text": { "query": "Big", "path": [ "Books.Title", "Books.Author" ] } }, { "text": { "query": "Piano", "path": [ "Books.Title", "Books.Author" ] } } ] } }, "path": "Books" } } ] } } }

How should the aggregation be formulated to return all documents that MUST have “Big” and “Piano”? “Big” is in the “PublisherName” field, and “Piano” is in the “Books.Title” field. Both MUST exist for the document to be returned.