Filter children in elasticsearch Nest


(Qutaiba Mustafa) #1

I want to filter children in elastic search without changing the parent node, i have something like this data, and want to all games, but only "isVisible = true" members should appear with each game

{ 
"_index": "test", 
"_type": "Game", 
"_id": "1", 
"_source": { 
"gameName" : "test game",
"teamMembers" : {
    "id" : "2",
    "name":"John",
    "isVisible" : true
    },
{
    "id" : "3",
    "name":"emma",
    "isVisible": false
}
} }

So, i want to get the above game as is but with only 1 team member (John) i am using C#, and tried this:

var result = new List<Func<QueryContainerDescriptor<Review>, QueryContainer>>();
result.Add(a => a.Nested(n => n.Path("teamMembers").Query(q => q.Match(m => m.Field("teamMembers.isVisible").Query("true")))));

but it didn't work.

Note: i am using Elastic search 5.4

Thanks in advanced.


(David Pilato) #2

I'd recommend using a top level visible property that you compute at index time. That will be the most efficient way to do that. Something like:

{ 
    "gameName" : "test game",
    "isVisible": false,
    "teamMembers" : [{
        "id" : "2",
        "name":"John",
        "isVisible" : true
    },
    {
        "id" : "3",
        "name":"emma",
        "isVisible": false
    }]
}

BTW your json looks incorrect to me.


(system) #3

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