CountRequest does not carry over default index for ElasticSearch 7.10.1

Hi:

I am fairly new to the NEST Library. I am using both the Count function and the Search function, below is some sample code I wrote to recreate the issue:

    using System;
    using Nest;

    namespace NestCountTest
    {
        class Program
        {
            static void Main(string[] args)
            {
                var settings = new ConnectionSettings(new Uri("http://localhost:9200")).DefaultIndex("test1").ThrowExceptions();

                var client = new ElasticClient(settings);

                client.Ping();

                var searchResult = client.Search<Data>(new SearchRequest<Data>
                {
                    Query= new QueryContainer(new MatchAllQuery())
                });

                var countResult = client.Count(new CountRequest
                {
                    Query = new QueryContainer(new MatchAllQuery())
                });

                Console.WriteLine(searchResult .Documents.Count);
                Console.WriteLine(countResult.Count);
            }
        }
    }

I have 3 records set in test1 index, the searchResult returns 3 documents. But the countResults returns much more than that as it is counting the documents within the entire cluster. Is this inconsistency of behavior by design? (the SearchRequest taking the default index from client but he CountRequest does not). Also, if I want to make the CountRequest give the correct response. I will need to write code like below by specifying the index I want the CountRequest to point to:

    var countResult = client.Count(new CountRequest("test1")
    {
          Query = new QueryContainer(new MatchAllQuery())
    });

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.