I have an index that can either be a thread or a thread_item, where a thread is the parent of one or more thread_item. In the template, I have the following defined in my template for a field called messages:
...
"message" : {
"properties" : {
"mentions" : {
"type" : "nested",
"properties" : {
"contact" : {
"type" : "nested",
"properties" : {
"first_name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"id" : {
"type" : "long"
},
"last_name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
}
}
...
I would like to use a nested filter to find a thread which has a child thread_item that has a matching mention.contact.first_name value:
{
"query":{
"bool":{
"filter":{
"has_child":{
"type":"thread_item",
"query":{
"nested":{
"path":"message.mentions",
"query":{
"nested":{
"path":"message.mentions.contact",
"query":{
"term":{
"message.mentions.contact.first_name":"aaron"
}
}
}
}
}
}
}
}
}
}
}
The above does not work even when there is an existing matching record. If i remove the has_child portion of the query, it does work and returns the correct record:
{
"query":{
"bool":{
"filter":{
"nested":{
"path":"message.mentions",
"query":{
"nested":{
"path":"message.mentions.contact",
"query":{
"match":{
"message.mentions.contact.first_name":"aaron"
}
}
}
}
}
}
}
}
}
Is there something wrong with the way I'm writing the has_child query? I've written many other queries using this relationship which all work fine, so I'm pretty sure it's not a type issue.