elasticsearchelasticsearch-5elasticsearch-net

Why is elasticsearch's Nest lowlevel Search method ignoring type and index name defined in SearchDescriptor<>() object


NEST/Elasticsearch.Net version:5.6.5

Elasticsearch version:5.4.3

We are trying to fetch result from our index using the LowLevelClient. We are using the below SearchAsync API

 var searchDescriptor = new SearchDescriptor<MyType>()
                                                       .Type("mytype")
                                                       .Index("myindex")
                                                       .Query(....)
                                                       .Aggregation(ag => ag.Terms(... Aggregation(ag1 => ag1.Min(...TopHits(...)))));
            var memoryStream = new MemoryStream();
            _client.Serializer.Serialize(searchDescriptor, memoryStream);
            var response = await _client.LowLevel.SearchAsync<byte[]>(memoryStream.ToArray()).ConfigureAwait(false);
           //_client - instance of Nest.ElasticClient
           //Next Step - Deserialize the response

This is giving me results from other indices also(a combination of results from the various indices) and my deserialization is breaking. The client is ignoring type and index name and calling POST /_search API instead of POST /myindex/mytype/_search on the elastic search

Note:

  1. We need to call a lower-level client because we are using a custom deserializer for performance concern

What is the issue here?


Solution

  • Found a workaround

    The SearchAsync<>() method have overloaded method _client.LowLevel.SearchAsync<T>(string indexName, string typeName, T t)

    Passing the index name and type name will narrow to search to that particular index.

    But the question still remains, why it is not taking the index and type name from SearchDescriptor object.