question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

7.0.0 - Cannot parse hits._source into ISearchResponse.Documents

See original GitHub issue

NEST/Elasticsearch.Net version: 7.0.0-alpha1

Elasticsearch version: 7.0.0

Description of the problem including expected versus actual behavior:

Hi, I’ve sent search request via Nest IElasticClient.SearchAsync() as following:

GET /player_profile*/_search
{
  "query": {
    "bool": {
      "should": [
        {
          "match": {
            "LoginId": {
              "query": "loginId1"
            }
          }
        },
        {
          "match": {
            "MobileNumber": {
              "query": "loginId1"
            }
          }
        },
        {
          "match": {
            "Email": {
              "query": "loginId1"
            }
          }
        }
      ]
    }
  },
  "_source": {
    "includes": [
      "PlayerId"
    ]
  }
}

result

{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : {
      "value" : 1,
      "relation" : "eq"
    },
    "max_score" : 0.6931472,
    "hits" : [
      {
        "_index" : "player_profile",
        "_type" : "doc",
        "_id" : "663b433e-f36b-1410-8104-004df507d47e",
        "_score" : 0.6931472,
        "_source" : {
          "PlayerId" : "663b433e-f36b-1410-8104-004df507d47e"
        }
      }
    ]
  }
}

POCO class in c#

public sealed class PlayerElkData
{
        public Guid PlayerId { get; set; }
        public string MobileNumber { get; set; }
        public string Email { get; set; }
        public string LoginId { get; set; }
}

The search result could be deserialized into ISearchResponse.Hits, however ISearchResponse.Documents and ISearchResponse.Hits[0].Source are both empty objects

It should deserialize “663b433e-f36b-1410-8104-004df507d47e” into PlayerId property

Is there something wrong in request, response or the POCO class?

Any suggestion would be appreciated, thank you!

Provide DebugInformation (if relevant):

(some part of ip address were masked)

Valid NEST response built from a successful low level call on POST: /player_profile/_search?typed_keys=true Audit trail of this API call:

  • [1] SniffOnStartup: Took: 00:00:00.2516981
  • [2] SniffSuccess: Node: http://172.16..:9200/ Took: 00:00:00.2463194
  • [3] PingSuccess: Node: http://172.16..:9200/ Took: 00:00:00.0203828
  • [4] HealthyResponse: Node: http://172.16..:9200/ Took: 00:00:00.0987998 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: <Response stream not captured or already read to completion by serializer. Set DisableDirectStreaming() on ConnectionSettings to force it to be set on the response.>

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
russcamcommented, Apr 29, 2019

the serializer in NEST 7.0 is stricter with regards to JSON field -> POCO property name casing. Where 6.x would be somewhat case insensitive during deserialization, 7.x is not.

The default casing is Camel casing in NEST, so the serializer looks for a playerId field in JSON to deserialize into the PlayerId property. If the DefaultFieldNameInferrer() is specified to use Pascal casing then deserialization works as expected

void Main()
{
	
	var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));

	var bytes = Encoding.UTF8.GetBytes(@"{
  ""took"" : 1,
  ""timed_out"" : false,
  ""_shards"" : {
    ""total"" : 5,
    ""successful"" : 5,
    ""skipped"" : 0,
    ""failed"" : 0
  },
  ""hits"" : {
    ""total"" : {
      ""value"" : 1,
      ""relation"" : ""eq""
    },
    ""max_score"" : 0.6931472,
    ""hits"" : [
      {
        ""_index"" : ""player_profile"",
        ""_type"" : ""doc"",
        ""_id"" : ""663b433e-f36b-1410-8104-004df507d47e"",
        ""_score"" : 0.6931472,
        ""_source"" : {
          ""PlayerId"" : ""663b433e-f36b-1410-8104-004df507d47e""
        }
      }
    ]
  }
}");

	var connection = new InMemoryConnection(bytes);
	
	var settings = new ConnectionSettings(pool, connection)
		.DefaultFieldNameInferrer(f => f);

	var client = new ElasticClient(settings);
	
	var searchResponse = client.Search<PlayerElkData>(s => s.Index("foo"));
	//  663b433e-f36b-1410-8104-004df507d47e as expected
	var id = searchResponse.Documents.First().PlayerId;
}

public sealed class PlayerElkData
{
	public Guid PlayerId { get; set; }
	public string MobileNumber { get; set; }
	public string Email { get; set; }
	public string LoginId { get; set; }
}

@Mpdreamz @codebrain being more lenient here for document POCOs would have a performance impact, as it would require encoding differently cased property names into an AutomataDictionary against which the POCO property name is matched.

0reactions
russcamcommented, May 8, 2019

Thanks @codebrain. This is something we should definitely call out 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Breaking changes in 7.0 | Elasticsearch Guide [7.17]
Using the deprecated names on new indices starting with version 7.0.0 will be prohibited and throw an error when indexing or analyzing documents....
Read more >
Can't get any documents with NEST from elasticsearch
I use Searchblox to index and search my files, which itself calls ES 2.x to do the job. Searchblox uses a "mapping.json" file...
Read more >
Retrieve selected fields from a search | Elasticsearch ...
For standard fields, this means that the fields option looks in _source to find the values, then parses and formats them using the...
Read more >
ElasticSearch rescorer plugin. How to parse inner hits with ...
Currently when I hit some document I use every element in my_nested_field to rescore the top level document. I would like to use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found