Unable to use Parent Child relation properly in elastic search

I have a requirement to filter sub-objects of activities attribute in my user object based on its type.

My User Object Model

  {
    userId,
    fistName,
    lastName,
    activities: [
        {mode: 'Typ1', name: 'Some Name', "description": "Some Desc"},
        {mode: 'Typ2', name: 'Some Name2', "description": "Some Desc2"},
        {mode: 'Typ1', name: 'Some Name3', "description": "Some Desc3"}
    ]
}

while querying elastic 6.7, I am using parent-child relation to get my entire user model but filtered activities based on the specific value in the mode

For that, I created

PUT <my_index>/user/_mappings
{     
            "properties": {                 
                "activities": { 
                      "type": "join",
                      "relations": {
                        "activities": "activities.mode" 
                      }
                    }
            }
}

and while querying ...

GET <my_index>/user/_search
{
  "size": 1000,
  "query" : {
      "bool": {
        "must": [
            {
              "term": {
                "userId": "123456"
              }
            }
        ],
        "filter": {
          "has_parent": {
            "parent_type": "activities", 
            "query": {
              "term": {
                "activities.mode": "Typ1"
              } 
            }
          } 
        }
      }
    },
  "_source": ["userId",  "firstName", "lastName", "activities.mode", "activities.name"]
}

however, after trying the above query, I am getting something like...

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

any help here will be greatly appreciated

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