It was my understanding that if you have an enum in a search document, it would be converted to an int. Unless I am doing something wrong, this does not seem to be happening and the only way I can get this to work is by converting the enum to a string. This seems wrong. Can someone tell me if I have done something wrong or if this is just not possible?
Example:
public enum WebSearchRecordType{
Unknown = 0,
Doc1 = 1,
Doc2 = 2
}
public class WebSearchDocument{
public Guid Id {get;set;}
public WebSearchRecordType RecordType { get; set; }
}
If I use something like the above while trying to create the index, I get the following error:
Message: "Property recordType has unsupported type Web.Search.WebSearchRecordType\r\nParameter name: propertyType"
Azure Search does not support enum types as field types. Instead, you'll need to map between enums and one of the supported data types yourself (either int or string, depending on whether you want the label or the underlying value to be stored in the index). One way to achieve this is mark your enum property with [JsonIgnore]
, then implement a second property of the desired field type and map between it and your enum in the getter/setter. Note that you can control how property names are mapped to index fields with the [JsonProperty("...")]
attribute.
Also, your model class uses Guid
as the type of the key field. This is also not supported. You can use the same technique to map your own Guid
property to a string property that is actually mapped to the corresponding index field.