How do i perform a “Compound/Must” across Enbedded Document and Root Document fields?
Ive create a playground for this issue im facing
Using the example I would like to search for “Big” and “Piano” across all searchable fields. Both values MUST exist. The search result should return the document with _id “101”, as “Big” exist in “PublisherName” and “Piano” exist in “Books.Title”.
Apologies - I now you’ve been asking this question in various threads and forums - thanks for your patience and for creating the most helpful playground starting point.
Here’s a modified version of your playground configuration and query: Code Playground
I simplified the configuration by removing explicit analyzer configuration and setting dynamic: true
(no difference in the index built in this example data, but wanted to remove unnecessary config to keep the problem solving here simpler). And I adjusted the query to search using two MUST text
clauses. Those text clauses query the document
version of the Books flattened fields into the parent indexed object. Whereas using embeddedDocuments
(which I left in the configuration, but isn’t being queried in this playground) queries children indexed objects in order to find parent matches. There’s detailed discussion of the differences in these ways of handling nested structures here: Data Modeling and Schema Design for Atlas Search | MongoDB
No doubt you need to query in more nuanced ways, but wanted to provide an answer to “search for “Big” and “Piano” across all searchable fields” which this playground accomplishes.
Thanks Erik. Much appreciated.