elastic / elasticsearch-net

This strongly-typed, client library enables working with Elasticsearch. It is the official client maintained and supported by Elastic.
https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/index.html
Apache License 2.0
10 stars 1.15k forks source link

Custom serializer (ConnectionSettingsAwareSerializerBase), StringEnumConverter ignored for SearchRequest #2990

Closed ghost closed 6 years ago

ghost commented 6 years ago

NEST/Elasticsearch.Net version: 6.0.0-beta1

Elasticsearch version: 6.1.1

Problem: When having a custom serializer with a Newtonsoft.Json.Converters.StringEnumConverter in place, the document is indexed properly, but when creating a search request including a term for the enum field, the value of the enum is serialized as an integer instead of a string.

Steps to reproduce:

  1. Create a NEST client with a custom serializer based derived from ConnectionSettingsAwareSerializerBase. Use StringEnumConverter.
  2. Create an index and sample document including an enum. Cross check the enum has been serialized as a string.
  3. Create a search request, including a term with the enum. The enum value is serialized as an integer instead of a string.

See attached csharp source file. Programm.txt

Index-Result:

Valid NEST response built from a successful low level call on PUT: /sample/sampledoc/11586a12341446d89c9ba71ac583ff94
# Audit trail of this API call:

 - [1] HealthyResponse: Node: http://localhost:9200/ Took: 00:00:00.1091068
# Request:
{"id":"11586a12341446d89c9ba71ac583ff94","someEnum":"Two"}
# Response:
{"_index":"sample","_type":"sampledoc","_id":"11586a12341446d89c9ba71ac583ff94","_version":1,"result":"created","_shards":{"total":1,"successful":1,"failed":0},"_seq_no":4,"_primary_term":1}

Search-Result:

Valid NEST response built from a successful low level call on POST: /sample/sampledoc/_search
# Audit trail of this API call:
 - [1] HealthyResponse: Node: http://localhost:9200/ Took: 00:00:00.1071065
# Request:
{"query":{"term":{"someEnum":{"value":2}}}}
# Response:
{"took":0,"timed_out":false,"_shards":{"total":1,"successful":1,"skipped":0,"failed":0},"hits":{"total":0,"max_score":null,"hits":[]}}
Mpdreamz commented 6 years ago

Thanks for reporting this @badpp the term should flow through the source serializer but currently does not.

Mpdreamz commented 6 years ago

Thanks for reporting @badpp this should be fixed with #2997 and should be in the next release.