I'm new to Elasticsearch and I'm using NEST. When I run my query in the browser (host/logstash-2019.03.17/_search?pretty) I get the following result:
{
"took" : 138,
"timed_out" : false,
"shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 10,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "logstash-2019.03.17",
"_type" : "logevent",
"_id" : "aa7djGkB1zvCMljS8jPd",
"_score" : 1.0,
"_source" : {
"@timestamp" : "2019-03-17T18:15:43.9506399Z",
"level" : "Info",
"message" : "Attempting to get results from ElasticSearch",
"logger" : "App.Api.Controllers.MyController"
}
}, OTHER HITS IN THE SAME FORMAT
However, when I'm trying to query the same index using ElasticClient i get the following 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 115.”
I thought NEST is capable of autodeserializing JSON correctly on condition that it is provided with a class whose properties correspond to "_source" object fields. At least this is what you can infer from this tutorial.
Here is my POCO class follwed by the query which throws the exception:
public class Logevent
{
public string Id { get; set; }
public DateTime Timestamp { get; set; }
public string Level { get; set; }
public string Message { get; set; }
public string Logger { get; set; }
}
var client = new ElasticClient();
var searchResponse = client.Search<Logevent>(s => s.Index("logstash-2019.03.17").Query(q => q.Match(m => m.Field(f => f.Level).Query("message"))));
Could anyone explain what I'm doing wrong?
aa7djGkB1zvCMljS8jPdis not a valid Guid.. maybe you should make your Id property a string. - stuartd'hits.total.value', line 1, position 115.) - stuartd