I'd like to iterate over my searchResponse so I can use the value from an id field in every found document in order to do a new search where this id matches another one in another index.
So first I'm doing this
var groupSearch = await EsClient().SearchAsync<GroupDto>(s => s
.Query(q => q
.Match(m => m
.Field(f => f.GroupId)
.Field(f => f.GroupName))
));
and then I'd like to do something like this
SimpleUnitDto unit;
GroupDto group = (GroupDto)groupSearch;
group.Units = new List<SimpleUnitDto>();
foreach (Guid groupId in groupSearch.Hits.Select(g => g.Source.GroupId))
{
var unitSearch = await EsClient().SearchAsync<SimpleUnitDto>(s => s
.Index("units")
.Query(q => q
.MultiMatch(m => m
.Fields(f => f
.Field(ff => ff.UnitId)
.Field(ff => ff.UnitName))
) && +q
.Term(t => t
.Field("groupid")
.Value(groupId)
));
unit = (SimpleUnitDto)unitSearch;
group.Units.Add(unit);
group = groupDict[groupId];
}
return groupDict.Values
This is not a working example but it's how i think it should work.
Could anyone assist?