【问题标题】:Elasticsearch NEST Document count for default index默认索引的 Elasticsearch NEST 文档计数
【发布时间】:2019-03-04 11:23:55
【问题描述】:

我正在为 Elasticsearch 6 使用 NEST,并希望获取默认索引的文档数。

documentation 指的是 API 的 1.1 版本,它似乎不再起作用。

我已经使用默认索引创建了连接设置:

var connectionSettings = new ConnectionSettings().DefaultIndex("test_docs");

当我尝试 1.1 api 文档中的代码时:

var result = client.Count();

我收到以下错误:

方法的类型参数 'ElasticClient.Count(Func, ICountRequest>)' 不能从用法推断。尝试指定类型参数 明确的。

当我提供一个类型时,它会附加到路径中。例如:

client.Count<TestDocument>();

当我真正需要的是http://localhost:9200/test_docs/_count时,生成一个http://localhost:9200/test_docs/testdocument/_count的URL

【问题讨论】:

    标签: elasticsearch nest


    【解决方案1】:

    你可以使用

    var countResponse = client.Count<TestDocument>(c => c.AllTypes());
    

    将调用 API

    GET http://localhost:9200/test_docs/_count
    

    【讨论】:

    • 谢谢!那行得通,我没有意识到我需要包括 AllTypes
    • c.AllTypes() 丢失
    【解决方案2】:

    对于那些需要新方法的人(比如我自己)。我将使用以下内容从特定索引中获取计数。

    var countRequest = new CountRequest(Indices.Index("videos"));
    long count = (await _ecClient.CountAsync(countRequest)).Count;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-11
      • 2015-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-16
      相关资源
      最近更新 更多