2014-06-21 31 views
1

我有一个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这样我就可以诊断我的问题打?

回答

4

如果安装Fiddler,您可以看到发送和返回的确切HTTP。或者您可以使用:

  1. 的.ToQueryInfo()方法和检查。体和.Uri性能
  2. 上ElasticContext器ILOG接口捕捉到的原始查询和响应

我会想象问题在于CLR对象和文档字段名称之间的映射 - 默认情况下,ElasticMapping类骆驼案例字段名称和尝试复数类型名称。您可以使用构造器开关将其关闭或为您自己的特定约定进行子类化。

此外,我认为你的查询应该说||对于OR而言,这些布尔运算符是受支持的,但是|和&按位操作都没有。

相关问题