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
12 stars 1.15k forks source link

Property type and name attribute #8305

Closed YJTSec closed 3 months ago

YJTSec commented 3 months ago

Hi, I have an index in the Elasticsearch with these fields: id, title, price, create_time, object_color

I want to get these documents using v8 .net client so created this class:

class Document {
  public string Id {get ; set; }
  public string Title {get; set; }
  public double Price {get; set;}
  public DateTime CreateTime {get ;  set; }
  public string Color {get ;set ; }
}

When I search, the returned documents are not filled completely and the issue occurs in snake_case fields in the index. for example the returned document has Id, Title and Price values but CreateTime is not filled correctly and also Color is not filled because of different naming with the original field in the index. the previous v7 NEST client had some attributes to handle this issue like ProperyName . I didn't find something similar in the new client. Is there any solution for this issue currently? Or any method to handle class properties mapping to the original index fields?

It will be nice if some attributes exist to handle class properties easier. just like previous client: for example

class MyClass {
   [Attribute (type, relatedFiledName)]
   Property
}

Thanks.

flobernd commented 3 months ago

Hi @YJTSec ,

the new client uses System.Text.Json as the serializer framework.

You can use the JsonPropertyName attribute to set a custom name for your properties.