This is how you do nested queries in elastic4s:
First of all, setting up the index such that you have a nested type:
client.execute {
create index "nested" mappings {
"show" as {
"actor" typed NestedType
}
}
}
Then with some sample data
client.execute(
index into "nested/show" fields(
"name" -> "game of thrones",
"actor" -> Seq(
Map("name" -> "peter dinklage", "birthplace" -> "Morristown"),
Map("name" -> "pedro pascal", "birthplace" -> "Santiago")
)
)
)
Then the key part. To search, you used the nested
(or in elastic4s 1.4 beta, nestedQuery
) to "drop into" the nested scope, where you can search using any standard query type. Here I am just using a simple termQuery
search.
client.execute {
search in "nested/show" query nested("actor").query(termQuery("actor.name" -> "dinklage"))
}