Elasticsearch inner-hits on child type not in the query


#1

Struggling with inner-hits on elasticsearch. Would appreciate any help.

I have two child types: childA and childB.
I am querying parents of childA like this

"query":{
    "bool": {
        "should": {
            "has_child": {
                "type": "ChildA",
                "query": {
                    "match": {
                        "name": {
                            "query": "a" 
                        }
                    }
                }
            }
        }
    }
} 

My problem is how to include in the results all child docs of type childB as well without affecting results from the above query.

I was thinking to use inner-hits on a has_child query(type childB) for that but my query doesn't depend on childB type.

Anyone has an idea?

Thanks in advance


#2

I found a way to include childB type docs.

I combine the following query with above query (has_child on childA type) in a filter query to get childB docs also. I am not really sure if its a good way though(thinking about performance)

{
      "query":{
        "bool":{
          "should":[
            {
              "bool":{
                "must_not":[
                  {
                    "has_child":{
                      "type":"ChildB",
                      "query":{
                        "match_all":{}
                      },
                      "inner_hits":{}
                    }
                  }
                ]
              }
            },
            {
              "has_child":{
                "type":"ChildB",
                "query":{
                  "match_all":{}
                },
                "inner_hits":{}
              }
            }
          ]
        }
      }
    }

(system) #3

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