As shown in the picture I have a groups field with an array of string values.
However, I am getting an exception when trying to map it to a List<string> property.
Something like Error converting value \"[134706634,134706635]\" to type System.Collections.Generic.IList[System.String]'
I tried using some various attributes that elasticsearch provides but none worked. A json converter attribute works fine but need to write a lot of code to make it work the way I want.
Is there a cleaner and more native way to do this with NEST ?
C# Code:
var groupQuery = await
elastic.SearchAsync<CorrelationGroup>(s => s
.Query(q => q
.Bool(b => b
.Must(
m => m.ConstantScore(c => c
.Filter(f => f
.Term(x => x.Type, counterType))
),
m => m.ConstantScore(c => c.
Filter(f => f
.Term(x => x.TypeValue, counterTypeValue))))))
.Index("correlation-groups").AllTypes());
public class CorrelationGroup
{
[Text(Name = "type")]
public string Type { get; set; }
[Text(Name = "type_value")]
public string TypeValue { get; set; }
public List<string> Groups { get; set; }
}
Source json file:
[
{
"type": "APN",
"type_value": "internet",
"groups": [150994936,150994940]
},
{
"type": "APN",
"type_value": "internet",
"groups": [150984921,150984922]
},
{
"type": "APN",
"type_value": "internet",
"groups": [150984917,150984918,150984921,150984922]
}
]
My template is:
{
"template": "correlation-groups",
"settings" : {
"number_of_shards" : 2,
"number_of_replicas" : 0,
"index" : {
"store" : { "compress" : { "stored" : true, "tv": true } }
}
},
"dynamic_templates": [
{
"string_template" : {
"match" : "*",
"mapping": { "type": "string", "index": "not_analyzed" },
"match_mapping_type" : "string"
}
}
],
"mappings": {
"_default_": {
"properties": {
"type": { "type": "string", "index": "not_analyzed" },
"type_value": { "type": "string", "index": "not_analyzed" },
"groups": { "type": "string"}
}
}
}
}


\"[134706634,134706635]\"? It's very likely that yourgroupsarray has been stringified at some point and stored as a string.