I'm using elasticsearch c# ISearchResponse search. I want to get results from 2 indexes in 1 search. I want to get all users from the "user" index that their field "doc.Users_Email" is counting more than x times in the field "doc.SentMail_Recipients.recipients_email" from the "mail" index.
How can I do that? This example of a search request in my code:
public List<string> Example()
{
ISearchResponse<object> result = _mainManager.Client.Search<object>(q => q
.Index(ElasticIndex.User.ToString().ToLower())
.Query(c => c.Term("example")
.Size(10000));
return _mainManager.GetIdsListResult(result);
}
I tried this:
ISearchResponse<object> result = _mainManager.Client.Search<object>(q => q
.Index(new[] { "user", "mail" })
.Size(3000)
.Query(q1 => q1
.Nested(n => n
.Path("doc")
.Query(q2 => q2
.Terms(t => t
.Field("doc.Users_Email")
)
)
)
)
.Aggregations(a => a
.Nested("docs", n => n
.Path("doc")
.Aggregations(a1 => a1
.Terms("mails", t => t
.Field("doc.SentMail_Recipients.recipients_email")
.MinimumDocumentCount(10) // Set x as the minimum doc count
)
)
)
)
);
List<string> userIds = _mainManager.GetIdsListResult(result);