I have this search query to find the query search term "red dog" in the root Title and Description and also match the nested comments document.
GET /_all/video/_search
{
"query":{
"bool":{
"should":[
{
"multi_match":{
"query":"red dog",
"fields":[
"Title",
"Description"
],
"type": "cross_fields",
"operator":"and"
}
},
{
"nested":{
"path":"Comments",
"query":{
"multi_match":{
"query":"red dog",
"fields":[
"Comments.Description",
"Comments.Description.folded"
],
"type": "cross_fields",
"operator":"and"
}
}
}
}
]
}
}
}
Unfortunately for me, comments are sometimes null when I persist them to ElasticSearch, is it possible to do some sort of "include if document exists" condition?
Update
I still get the same error
[nested] failed to find nested object under path [Comments]
When I try to query using exists
GET /_all/video/_search
{
"query":{
"bool":{
"should":[
{
"multi_match":{
"query":"lisa",
"fields":[
"Title",
"Description"
],
"type":"cross_fields",
"operator":"and"
}
},
{
"nested":{
"path":"Comments",
"query":{
"filtered":{
"query":{
"match_all":{}
},
"filter":{
"exists":{
"field":"Comments.Description"
}
}
}
}
}
}
]
}
}
}
My mapping for everything
{
"en":{
"mappings":{
"video":{
"properties":{
"Comments":{
"type":"nested",
"properties":{
"Description":{
"type":"string",
"analyzer":"english",
"fields":{
"folded":{
"type":"string",
"analyzer":"folding"
}
}
}
}
},
"Description":{
"type":"string",
"analyzer":"english",
"fields":{
"folded":{
"type":"string",
"analyzer":"folding"
}
}
},
"Title":{
"type":"string",
"analyzer":"english",
"fields":{
"folded":{
"type":"string",
"analyzer":"folding"
}
}
}
}
}
}
}
}
And my settings
{
"settings": {
"analysis": {
"analyzer": {
"folding": {
"tokenizer": "standard",
"filter": [
"lowercase",
"asciifolding"
]
}
}
}
}
}