标签: elasticlinq

了解 ElasticLinq 实际上在做什么

我需要ElasticDatastore能够根据业务逻辑中的任意标准返回文档列表。

该方法目前看起来像这样......

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;
}
Run Code Online (Sandbox Code Playgroud)

我这样称呼它

var newItems = dataStore.Items(x=>
        x.SomeField == node.SomeValue.ToString()
        & (x.AssignedTo == null
         | x.AssigmentExpires < DateTime.UtcNow)
    ).ToList();
Run Code Online (Sandbox Code Playgroud)

就目前情况而言,该方法返回零结果。通过使用弹性头(和卷曲),我可以验证是否存在符合索引中指定条件的文档。

我的第一个猜测是 EsLinq 预期的字段名称不正确(案例......索引是使用Nest构建的)。但是,我找不到一个好方法来检查 EsLinq 实际发送到 elasticsearch 的内容。

我可以

esLinq.Query<Item>().ToElasticSearchQuery();
Run Code Online (Sandbox Code Playgroud)

并获取一个表示(空白)查询的 json 字符串,但是...Query<Item>().Where(predicate)返回一个IEnumerable<Item>没有ToElasticSearchQuery扩展名的字符串。

编译器接受

ret.AsQueryable().ToElasticSearchQuery()
Run Code Online (Sandbox Code Playgroud)

但我在运行时得到ArgumentException

Query must be of type …
Run Code Online (Sandbox Code Playgroud)

.net c# linq elasticsearch elasticlinq

1
推荐指数
1
解决办法
802
查看次数

标签 统计

.net ×1

c# ×1

elasticlinq ×1

elasticsearch ×1

linq ×1