C# ElasticClient search - field name upper case issue

My record is like this:
"_index": "cmmtest2",
"id": "q3_WdIgBcz5F0I953TG",
"_score": 1,
"_source": {
"characteristic": "150 W8 Prof 0.1 J",
"actual": 0.019991,
"nominal": 0,
"partno": "2022_7933 S2",
"XBAR": "XX"

My code is:

        public class Record2
            public string characteristic { get; set; }
            public float actual { get; set; }
            public float nominal { get; set; }
            public string partno { get; set; }
            public string XBAR { get; set; }

        public static string Initial2()
            var settings = new ConnectionSettings(new Uri("http://localhost:9200")).DefaultIndex("cmmtest2");
            var client = new ElasticClient(settings);
            var searchResponse = client.Search<Record2>(s=>s.Size(300));
            var record = searchResponse.Hits;
            return record.ToString();

I can get value from "Hits" if the field name is in lower case, but cannot get value in upper case like "XBAR".

In python or other tools, it doesn't matter. Does it have any solution?

Hi, @Yujie_S.

The default behaviour when serialising document type properties is case-sensitive and applies camelCasing. You can control this globally or on a per-property basis.

In your case, you should look at introducing the PropertyName attribute as per this documentation. That documentation also provides full guidance on field name inference.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.