2016-02-13 45 views
0

我有ES和巢工作和搜索通配符。我想统计我所看到的记录数量和数量是否允许精确匹配,但我想要一个“喜欢”匹配(在sql中 - 作为比喻)。 下面的代码不会返回任何内容。有没有人有任何想法?Elasticsearch NEST和通配符计数

var searchDataCount = client.Count<SearchRow>(s => s.Index("myindex").AllTypes(). 
Query(q => q.QueryString(qs => qs.OnFields(j => j.searchstring).Query(@searchString)))); 

var searchDataResults = client.Search<SearchRow>(s =>s.Index("myindex").AllTypes(). 
From(startcount).Size(recordsize). Query(q => q. 
QueryString(qs => qs.OnFields(j => j.searchstring).Query(@searchString)))); 

回答

0

可能,你可以在搜索查询中使用相同的查询模块来执行搜索这类同喜欢通过增加SQL查询“*”

例如:

,如果你正在寻找的字符串作为SQL '数据%',即可以在Elastcisearch查询如下

  var searchDataResults = client 
      .Search<SearchRow>(s => s.Index("myindex") 
       .AllTypes() 
       .From(startcount) 
       .Size(recordsize) 
       .Query(q => q 
        .QueryString(qs => qs 
         .OnFields(j => j.searchstring) 
         .Query("data*")))); 

similiar例:SQL => Elasticsearch

data% => data* 
%data => *data 
%data% => *data* 
+0

是的我明白这是可能的,但client.Count根本不起作用,我也尝试使用Aggregations与ValueCount也失败。我想要的是相当于select中的select(count)(*),其中col就像ES中的'%test%'。我有搜索工作(不计算),但计数部分不起作用。 –

+0

你可以用count查询来做同样的事情 –

+0

这里的代码 - http://nest.azurewebsites.net/nest/core/count.html - 对我不起作用。即使client.count()失败,但client.search 的作品。非常令人沮丧的是没有返回错误信息。该对象只是说“不存在”的返回对象。 –

0

该解决方案的默认索引是不同的。这里是发布给我的想法 - https://github.com/elastic/elasticsearch-net/issues/1404。实际代码 -

settings = new ConnectionSettings(node, defaultIndex: "myindex"); 

默认索引需要与client.count查询中的索引相匹配。