I am learning to use Elasticsearch as a basic recommender engine. My elasticsearch document contains records with nested entities as follows
POST feeds/_doc
{
"feed_id": "1",
"title": "Mateen",
"body": "This is mateen",
"comment": [
{
"c_id": "11",
"feed_id": "1",
"c_text": "get well soon mateen"
},
{
"c_id": "12",
"feed_id": "1",
"c_text": " Ali here"
}
]
}
POST feeds/_doc
{
"feed_id": "3",
"title": "jose ",
"body": "This is Jose allen",
"comment": [
{
"c_id": "13",
"feed_id": "2",
"c_text": "hey"
},
{
"c_id": "13",
"feed_id": "3",
"c_text": " here"
}
]
}
The Mapping is
PUT feeds
{
"mappings": {
"properties": {
"comment":{
"type": "nested"
}
}
}
}
I would like to search for feeds who specifically have title="mateen",body="Terminator" and comment.c_text="Rambo". and if that text is not matced by any body and title and only matched in any comment.c_text it will give me the body title and that matched comment.c_text onlyyy
I have used a nested queries which currently looks like this
GET feeds/_search
{
"query": {
"nested": {
"path": "comment",
"query": {
"multi_match": {
"query": "ali",
"fields": ["body","title","comment.c_text"]
}
}
}
}
}
and sceond try
{
"query": {
"bool": {
"must": [
{
"match": {
"title": {
"query": "ali"
}
}
},
{
"match": {
"body": {
"query": "ali"
}
}
},
{
"nested": {
"path": "comment",
"query": {
"match": {
"comment.c_text": {
"query": "ali"
}
}
}
}
}
]
}
}
}
however when i execute this queery i know there is no ali in body and title but it has ali in one of comment.c_text so i am expecting to show me the body and title of that commenct as well can anyone help me in this senario