如何将多个条件组合到Elasticsearch NEST查询中

时间:2019-03-05 13:39:21

标签: elasticsearch nest

我是NEST的新手。尽管我在各个论坛中进行搜索,但我仍不明白如何将多个条件组合到一个NEST查询中。

我的C#代码在这里:

var mediaIds = "my-vid-123|my-vid-456"; // This is in fact passed from UI.
var stationId = "1"; // Also passed from UI.


QueryContainer query = new QueryContainer();

if (!string.IsNullOrEmpty(mediaIds))
{
    var lstMediaIds = mediaIds.Split(new string[] { "|" }, StringSplitOptions.RemoveEmptyEntries).ToList();
    QueryContainer qr = new QueryContainer();
    lstMediaIds.ForEach(vi => {
        qr &= new TermQuery { Field = "VideoID", Value = vi};
    });

    query &= qr;
}

if (stationId != "" & stationId != "0")
{
    query &= new TermQuery
    {
        Field = "StationID",
        Value = stationId
    };
}

var result = _db.Search<MediaSummary>(s => s
                .Index("mediasummary-*")
                .Type(typeof(MediaSummary))
                .Skip(skip)
                .Take(take)
                .Query(q => query)
                );

var count = result.Total; //Always comes 0
var mediaSumm = result.Documents.ToList();  //Empty list

尽管记录从 Kibana 显示,但count始终为零,并且mediaSumm列表为空。 我在哪里做错了?请指导。

0 个答案:

没有答案