我有一个ElasticDatastore
,我需要能够根据业务逻辑中的任意条件返回文档列表。找出ElasticLinq实际上在做什么
的方法目前看起来是这样的......
private ElasticContext esLinq;
private void initialise() {
esLinq = new ElasticContext(new ElasticConnection(endpoint, index: index));
}
public IEnumerable<Entities.Item> Items(Func<Entities.Item, bool> predicate) {
var ret = esLinq.Query<Item>().Where(predicate);
return ret;
}
我打电话像这样
var newItems = dataStore.Items(x=>
x.SomeField == node.SomeValue.ToString()
& (x.AssignedTo == null
| x.AssigmentExpires < DateTime.UtcNow)
).ToList();
就目前情况来看,该方法返回结果为零。通过使用弹性头(和卷曲),我可以验证是否有与索引中指定条件相匹配的文档。
我的第一个猜测是EsLinq预期的字段名称不正确(套管...索引是使用nest构建的)。但是,我找不到一个好的方法来检查EsLinq实际发送给elasticsearch的内容。
我可以做
esLinq.Query<Item>().ToElasticSearchQuery();
并获得其代表(空白)查询,但是,...Query<Item>().Where(predicate)
返回IEnumerable<Item>
不具有ToElasticSearchQuery
扩展名的JSON字符串。
编译器接受
ret.AsQueryable().ToElasticSearchQuery()
,但我在运行时得到一个ArgumentException
:
Query must be of type IElasticQuery<> to call ToElasticSearchQuery()
我如何可以检查EsLinq发送的查询elasticsearch这样我就可以诊断我的问题打?