0

I have a C# class that include a Dictionary (this is just one row of the class)

public Dictionary<string, double?> Resultat { get; set; }

When I created the Index I created that as a Collection of complex type

Collection(Edm.ComplexType)
   key (Edm.String)
   value (Edm.Double)

I use the C# native library to post documents to the search index and when I run the code I'll get an error stating that it looks for a start marker. I figured out that Azure Cognitive Search serializer converts the Dictionary to a json class instead of an json array.

the result looks a bit like:

{
  "key1": "value1",
  "key2": "value2"
}

but Cognitive Search expects the data to look like:

[
  {"key1":"value1"},
  {"key2":"value2"}
]

Since the dictionary is dynamic in both count and keys (unknown counts, and unknown keys) it cannot create the field as a Edm.Complex type.

Is there any way to send serializer instructions to Cognitive Search to serialize Dictionarys to arrays instead of objects?? Are there any other solutions?

  • Does this answer your question? [Index a dictionary property in azure search](https://stackoverflow.com/questions/58719062/index-a-dictionary-property-in-azure-search) – Bruce Johnston Aug 19 '21 at 17:26
  • Well, sort of... It does not solve my problem, it just explains a bit more about it ;) Since I use the Cognitive Search C# classes I dont have any control over the serialization so I cannot convert to an array instead of a class. I might have to create a new class that does not have a dictionary but an array of key-value pair instead – Magnus Jansson Aug 20 '21 at 06:38

0 Answers0