Search in child hierarchy not giving out snippet results

Hi,

In our application we have hierarchical documents (parent->child). At a high level, structure is board -> post -> comment -> reply. One of the requirements is to be able to search given text inside post hierarchy i.e if text matches any of the fields from post, comment and reply, return post with matched snippets. One problem that we are observing is, post object is always returned when it matches any of the post, comment and reply fields. But in some cases snippets are not turning up.

If you look at below query, one of the expected post document is 202_post where comment has matching string "document". But the response shows empty snippets

GET testindex/post/_search?routing=1000
{
"query": {
"bool": {
"should": [
{
"match_phrase_prefix": {
"postText_en": "document"
}
},
{
"has_child": {
"type": "comment",
"query": {
"match_phrase_prefix": {
"commentText_en": "document"
}
},
"inner_hits":{
"name": "comment",
"highlight":{
"fields":{
"commentText_en" : {}
}
}
}
}
},
{
"has_child": {
"type": "comment",
"query": {
"has_child": {
"type": "reply",
"query": {
"match_phrase_prefix": {
"replyText_en": "document"
}
},
"inner_hits":{
"name": "reply",
"highlight":{
"fields":{
"replyText_en" : {}
}
}
}
}
},
"inner_hits":{

        }
      }
    }
  ]
}

},
"highlight" : {
"fields" : {
"postText_en" : {}
}
}
}

Below is the code to populate the testindex to reproduce the scenario

Create index mappings
PUT /testindex/
{
"mappings": {
"board": {
"_routing": {
"required": true
},
"properties": {
"id": {
"type" : "text"
},
"name": {
"type" : "text"
},
"accountId":{
"type": "long"
}
}
},
"post": {
"_routing": {
"required": true
},
"properties": {
"id": {
"type" : "text"
},
"postText_en": {
"type": "text"
},
"accountId":{
"type": "long"
}
},
"_parent": {
"type": "board"
}
},
"comment": {
"_routing": {
"required": true
},
"properties": {
"id": {
"type" : "text"
},
"commentText_en": {
"type": "text"
},
"accountId":{
"type": "long"
}
},
"_parent": {
"type": "post"
}
},
"reply": {
"_routing": {
"required": true
},
"properties": {
"id": {
"type" : "text"
},
"replyText_en": {
"type": "text"
},
"accountId":{
"type": "long"
}
},
"_parent": {
"type": "comment"
}
}
}
}

Sample Data
POST /testindex/board/100_board?routing=1000
{
"id": "100_board",
"name": "sample board",
"accountId" : 1000
}
POST /testindex/post/200_post?routing=1000&parent=100_board
{
"id": "200_post",
"postText_en": "sample post document 200",
"accountId" : 1000
}
POST /testindex/comment/300_comment?routing=1000&parent=200_post
{
"id": "300_comment",
"commentText_en": "sample comment document 300",
"accountId" : 1000
}
POST /testindex/reply/400_reply?routing=1000&parent=300_comment
{
"id": "400_reply",
"replyText_en": "sample reply document 400",
"accountId" : 1000
}
POST /testindex/post/201_post?routing=1000&parent=100_board
{
"id": "201_post",
"postText_en": "sample post document 201",
"accountId" : 1000
}
POST /testindex/comment/301_comment?routing=1000&parent=201_post
{
"id": "301_comment",
"commentText_en": "sample comment 301",
"accountId" : 1000
}
POST /testindex/reply/401_reply?routing=1000&parent=301_comment
{
"id": "401_reply",
"replyText_en": "sample reply document 401",
"accountId" : 1000
}

POST /testindex/post/202_post?routing=1000&parent=100_board
{
"id": "202_post",
"postText_en": "sample post 202",
"accountId" : 1000
}
POST /testindex/comment/302_comment?routing=1000&parent=202_post
{
"id": "302_comment",
"commentText_en": "sample comment document 302",
"accountId" : 1000
}
POST /testindex/reply/402_reply?routing=1000&parent=302_comment
{
"id": "402_reply",
"replyText_en": "sample reply 402",
"accountId" : 1000
}

POST /testindex/post/203_post?routing=1000&parent=100_board
{
"id": "203_post",
"postText_en": "sample post 203",
"accountId" : 1000
}
POST /testindex/comment/303_comment?routing=1000&parent=203_post
{
"id": "303_comment",
"commentText_en": "sample comment document 302",
"accountId" : 1000
}
POST /testindex/reply/403_reply?routing=1000&parent=303_comment
{
"id": "403_reply",
"replyText_en": "sample reply document 402",
"accountId" : 1000
}

Response
{
....
....
{
"index": "testindex",
"type": "post",
"id": "202_post",
"score": 1,
"routing": "1000",
"parent": "100_board",
"source": {
"id": "202_post",
"postText_en": "sample post 202",
"accountId": 1000
},
**
"inner_hits": {
**
**
"comment": {
**
**
"hits": {
**
**
"total": 0,**
**
"max_score": null,**
**
"hits": **
**
}**
**
}_**
}
}
]
}
}

Highlighted portion in bold + italic is the problematic piece where we expected comment snippet.

Could you help me with what is going wrong here?

Thanks,
Kowndinya

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