# Search within a list of objects

**URL:** <https://discuss.elastic.co/t/search-within-a-list-of-objects/62119>\
**Category:** Elasticsearch\
**Created:** [October 4, 2016, 12:51am UTC](https://discuss.elastic.co/t/search-within-a-list-of-objects/62119 "2016-10-04T00:51:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielordonez](https://avatars.discourse-cdn.com/v4/letter/d/94ad74/32.png) [@danielordonez](https://discuss.elastic.co/u/danielordonez)\
**Post date:** [October 4, 2016, 12:51am UTC](https://discuss.elastic.co/t/search-within-a-list-of-objects/62119/1 "2016-10-04T00:51:57Z")

</div>

Hi,

I might be asking something generic but I haven't figured it out myself, hope you can help.

Imagine I have this data:

```
"doctors" : {
    "doctor_1" : {
        "name" : "daniel"
    },
   "doctor_2" : {
        "name" : "david"
    }
}

patients : {
    "doctor_1" : {
        "patient_1" : {
            "name" : "Luisa"
        },
        "patient_2" : {
            "name" : "John"
        }
    },
    "doctor_2" : {
        "patient_1" : {
            "name" : "Charlie"
        },
        "patient_2" : {
            "name" : "Robert"
        },
        "patient_3" : {
            "name" : "John"
        }
    }
}

```

As you can see, patients are grouped under the doctor's Id.

**How would I perform a query for a patient's name but within a specific doctor and get returned the patient's object?**

For example:

I want to search for "John" under the Patients table but only within the "doctor\_2" object and get returned the "patient\_3" object instead of the "doctor\_2" object which contains "John" in the "patient\_3" object.

Any help is appreciated

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [October 4, 2016, 1:37pm UTC](https://discuss.elastic.co/t/search-within-a-list-of-objects/62119/2 "2016-10-04T13:37:25Z")

</div>

Read about [object](https://www.elastic.co/guide/en/elasticsearch/reference/current/object.html), [nested](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html), and [parent/child](https://www.elastic.co/guide/en/elasticsearch/guide/current/parent-child.html). One of those is probably what you want.

The word `table` isn't really a thing in Elasticsearch. If you try to map Elasticsearch concepts into relational database concepts you are going to have a hard time.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:15pm UTC](https://discuss.elastic.co/t/search-within-a-list-of-objects/62119/3 "2017-07-05T22:15:08Z")

</div>

Closed on July 5, 2017, 10:15pm UTC


