如何通过使用Nest C#在Elasticsearch查询(EQL)中使用不存在或为null?

问题描述 投票:0回答:1

每个人都知道,Nest Elasticsearch并不容易,而且很无聊,无法为查找某些东西进行明确的查询。我也为这个问题感到困惑。结果,我无法在查询中使用“不为空”和null。

   var list = client.Count<LogMessage>(s => s.Index("xxx-*").Query(q =>
            !q.Term(t => t.Field(f => f.Test.Suffix("keyword")).Value(null)) &&
            q.Term(t => t.Field(f => f.Environment.Suffix("keyword")).Value("yyy")) &&
            q.DateRange(t => t.Field(f => f.LogDate).GreaterThan(DateTime.Now.AddMinutes(-15)))));

Null或string。Empty在这里不起作用。如何使用NOT null或Not Empty?

c# elasticsearch kibana nest elk
1个回答
0
投票

IMO,这并不是一个NEST可用性问题,因为在Elasticsearch本身中做到这一点并不容易。通过对该字段取一个通配符查询(.Wilcard)和/或使用.Exists查找不具有该字段的文档,我已经取得了成功,因为空值未存储在文档中,并且空值很难搜索在非关键字文字栏位中输入,因为分析器不会寻找空白值。

© www.soinside.com 2019 - 2024. All rights reserved.