Build a Query based off the result of another query

Hi guys,
I would like to know if it is possible to make a query based off the result of another query.
For example, there are indices for school and students.

School
{
	"settings": { ... },
	"mappings": {
		"properties": {
			"schoolId":{
				"type":"keyword"
			},
			"students":{
				"type":"keyword" //array of student ids
			},
			...
		}
	}
}

Students
{
	"settings": { ... },
	"mappings": {
		"properties": {
			"studentId":{
				"type":"keyword"
			},
			"firstName":{
				"type":"text"
			},
			...
		}
	}
}

If I would like to get all the schools that have the students whose first name is "John," is there any way that I can make a query to get the student ids with a name with "John" and get all the schools based on the results?

I think it would be similar to make sub queries in SQL, but I cannot find a way in Elasticsearch.

Is it possible in elastic query? If it is, then how should I make a query?

Welcome to our community! :smiley: We aren't all guys though :slight_smile:

Yes you can, but you need to handle that in your client code. There's nothing native to Elasticsearch that will do this for you.

1 Like

Thank you!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.