Search code examples
elasticsearchnest

Using Elasticsearch Nest 7.x to query 5.x index


I have a project using Nest 7.x and there is a query I need to make to an older 5.x elasticsearch index. When I make a call like this, I get the following error. I am guessing it is due to how the mapping types were changed in version 6 and greater. Is there any way around this to query an older index?

var result = _elasticClient.GetAsync<Category>(id)

Invalid NEST response built from a successful (404) low level call on GET: /myindex/_doc/15437 Request: <Request stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.> Response: {"_index":"2020-01-13","_type":"_doc","_id":"15437","found":false}


Solution

  • As a workaround, I did this and it appears to work. Not sure if there are any better solutions?

    var response = _elasticClient.SearchAsync<Category>(s => s
                    .Query(q => q
                        .Bool(b => b
                            .Must(
                                bs => bs.Term(p => p.Id, id),
                                bs => bs.Term(p => p.Field("_type").Value("category"))
                            )
                        )
                    )
                )