Reputation: 2291
I used to have String attribute on class properties of type enumeration in Elastic Search 2.0 so that enumeration value to be stored as string rather than integer:
public enum PaperType
{
A4 = 0,
A3 = 1
}
and class to be stored as document in ElasticSearch
[ElasticsearchType(Name = "Paper")]
public class Paper
{
[String(Store = false, Index = FieldIndexOption.Analyzed)]
public string Name { get; set; }
[String(Store = false, Index = FieldIndexOption.Analyzed)]
public PaperType Type { get; set; }
}
So in Type would be stored as A3 or A4 rather than 0 or 1.
in ElasticSearch 5, these attributes have changed,
How could I achieve the same behavior in ElasticSearch 5 or what attribute and how it should be?
Thanks
Upvotes: 1
Views: 1451
Reputation: 125498
Take a look at attribute mapping in the documentation; you're likely looking to map them as Keyword
types.
If you want to save all enum
as string, you can add the Json.Net StringEnumConverter
to the JsonSerializerSettings
to use for any type that is an enum.
Upvotes: 0