sudo-suhas/elastic-builder

Sort.toJSON() wrong format!?

Hypopheralcus opened this issue · 3 comments

let sortField = new Sort('MyFieldToSort', 'desc');

sortField.toJSON()

Result:
{ MyFieldToSort: 'desc' }

Expected result:
{ "MyFieldToSort": { "order": "desc" } }

Okay thanks. So this is a Bug in the Elasticsearch.Net/NEST Client. Because the generated Syntax forces the RequestResponseSerializer.Deserialize() to fail with the message: "Character: { expected." If I change the JSON from ESB the Deserialize works.

NEST now supports deserializing the short forms of sort in 7.8.1 (elastic/elasticsearch-net#4806).

Historically, NEST has generally only supported serializing and deserializing the long form of sort/queries/etc., but in more recent versions, support for deserializing short forms has been added where it is missing (serialization will still use the long form). So, if you come across a case where NEST does not deserialize the short form of something, please do open an issue, thanks!