12

I have a c# project which i want send a request to my elastic search server. this is my connection and elastic search client :

ConnectionSettings connectionSettings;
ElasticClient elasticClient;
connectionSettings = new ConnectionSettings(new 
Uri("http://192.168.2.197:9292/"));        
elasticClient = new ElasticClient(connectionSettings);

this is my request :

var response = elasticClient.Search<NewsDataModel>(s => s
.Index("news-index")
.Type("title")
.Query(q => q.QueryString(qs => qs.Query("ny"))));

this is my model :

public class NewsDataModel  {      
public string _id { get; set; }     
public string title { get; set; }     
public string content { get; set; }       
public string summary { get; set; }
}

but when I send request, I get this exception :

Elasticsearch.Net.UnexpectedElasticsearchClientException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Int64' because the type requires a JSON primitive value (e.g. string, number, boolean, null) to deserialize correctly. To fix this error either change the JSON to a JSON primitive value (e.g. string, number, boolean, null) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'hits.total.value', line 1, position 113.'

How can I resolve this exception?

2 Answers 2

18

I had the same issue, and it seems that NEST 6.6.0 library is not compatible with Elasticsearch 7.0. I had to update NEST to 7.0.0 (alpha at this point).

Sign up to request clarification or add additional context in comments.

2 Comments

This worked for me, version 7.0.0-alpha1, thanks :)
7.0.0 release is available
0

I had the same issue when working with NEST 6.8 and connecting to ES 7.9. In the SearchDescriptor, calling TotalHitsAsInteger(true) method made it work.

        var searchResponse =  esClient.Search<_Doc>(s => s
            .Query(pq => pq.Term(new Field("type", null), "<type value>"))
            .Index("<Index Name>")
            .Size(3)
            .TotalHitsAsInteger(true)
        );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.