NestedQuery document (Data API 21.3)

A nested query queries nested documents that are part of a larger document. The classical example is a product master with variants (in one big document) where you want to constrain a search to masters that have variants that match multiple constraints (like color = blue AND size = M). This query is not compatible with some search types. Example: finds all the documents that has firstname = "John" and lastname = "Doe"
  {
   "query": {
     "bool_query": {
       "must": [
         {
           "nested_query": {
             "path": "order.shipping_addresses",
             "query": {
               "bool_query": {
                 "must": [
                   {
                     "bool_query": {
                       "must": [
                         {
                           "term_query": {
                             "fields": [ "order.shipping_addresses.first_name" ],
                             "operator": "is",
                             "values": [ "John" ]
                           }
                         }
                       ]
                     }
                   },
                   {
                     "bool_query": {
                       "must": [
                         {
                           "term_query": {
                             "fields": [ "order.shipping_addresses.last_name" ],
                             "operator": "is",
                             "values": [ "Doe" ]
                           }
                         }
                       ]
                     }
                   }
                 ]
               }
             },
             "score_mode": "avg"
           }
         }
       ]
     }
   }
 }
 
Property Type Constraints Description
path String mandatory=true, nullable=false  
query Query {BoolQuery, FilteredQuery, MatchAllQuery, NestedQuery, TermQuery, TextQuery} mandatory=true, nullable=false  
score_mode Enum {avg, total, max, none}    
X OCAPI versions 15.x and 16.x will be retired on March 31, 2021. For dates and more information, see the OCAPI versioning and deprecation policy and this Knowledge Article.
X Privacy Update: We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used. By continuing to use this site you are giving us your consent to do this. Privacy Policy.