Search within a list of objects


(Danielordonez) #1

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


(Nik Everett) #2

Read about object, nested, and parent/child. 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.


(system) #3