# Querying a multiple level nested object

**URL:** <https://discuss.elastic.co/t/querying-a-multiple-level-nested-object/56889>\
**Category:** Elasticsearch\
**Created:** [August 1, 2016, 12:18pm UTC](https://discuss.elastic.co/t/querying-a-multiple-level-nested-object/56889 "2016-08-01T12:18:01Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [August 3, 2016, 2:55pm UTC](https://discuss.elastic.co/t/querying-a-multiple-level-nested-object/56889/5 "2016-08-03T14:55:54Z")

</div>

Hi,  
I tried to recreate your mapping (not 100% exactly probably, but more or less) and your query worked for me, just returning one user with that id. Here's what I did, you can compare that to your own mapping to spot possible differences:

```auto
PUT /nested_test
{
  "mappings": {
    "t": {
      "properties": {
        "categories": {
          "type": "nested",
          "properties": {
            "name": {
              "type": "string"
            },
            "list": {
              "type": "nested",
              "properties": {
                "url_site": {
                  "type": "string"
                },
                "persons": {
                  "type": "nested",
                  "properties": {
                    "total_customers": {
                      "type": "integer"
                    },
                    "total_subscribers": {
                      "type": "integer"
                    },
                    "details": {
                      "type": "nested",
                      "properties": {
                        "person_id": {
                          "type": "string"
                        },
                        "person_date_registration": {
                          "type": "date"
                        },
                        "person_date_subscription": {
                          "type": "date"
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

PUT /nested_test/t/1
{
  "categories" : {
    "name" : "cat1",
    "list" : {
      "url_site" : "www.bla.org",
      "persons" : {
        "total_customers" : 10,
        "total_subscribers" : 10,
        "details" : {
          "person_id" : 1
        }
      }
    }
  }
}

PUT /nested_test/t/2
{
  "categories" : {
    "name" : "cat2",
    "list" : {
      "url_site" : "www.bleep.org",
      "persons" : {
        "total_customers" : 10,
        "total_subscribers" : 10,
        "details" : {
          "person_id" : 2
        }
      }
    }
  }
}

PUT /nested_test/t/3
{
  "categories" : {
    "name" : "cat3",
    "list" : {
      "url_site" : "www.blubb.org",
      "persons" : {
        "total_customers" : 10,
        "total_subscribers" : 10,
        "details" : {
          "person_id" : 3
        }
      }
    }
  }
}

POST /nested_test/t/_search
{
  "query": {
    "nested": {
      "path": "categories",
      "query": {
        "nested": {
          "path": "categories.list",
          "query": {
            "nested": {
              "path": "categories.list.persons.details",
              "query": {
                "bool": {
                  "must": {
                    "match": {
                      "categories.list.persons.details.person_id": 1
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

returns ==>

"hits": {
    "total": 1,
    "max_score": 1.9162908,
    "hits": [
      {
        "_index": "nested_test",
        "_type": "t",
        "_id": "1",
        "_score": 1.9162908,
        "_source": {
          "categories": {
            "name": "cat1",
            "list": {
              "url_site": "www.bla.org",
              "persons": {
                "total_customers": 10,
                "total_subscribers": 10,
                "details": {
                  "person_id": 1
                }
              }
            }
          }
        }
      }
    ]
  }

```

btw. if you are just interested in the document without scoring, you can use the `filter` section in the `match`query instead of `must`.

---

_[View the full topic](https://discuss.elastic.co/t/querying-a-multiple-level-nested-object/56889)._
