コード例 #1
0
        public void MultipleLayerClass_Test()
        {
            var typeMapping = new TypeMapping <Multiple1LayerClass>();
            var mappings1   = new KeyValuePair <Expression <Func <Multiple1LayerClass, object> >, FieldTypes>(ic => ic.Obj, FieldTypes.Object);
            var mappings2   = new KeyValuePair <Expression <Func <Multiple1LayerClass, object> >, FieldTypes>(ic => ic.Nested, FieldTypes.Nested);

            typeMapping.AddMapping(mappings1, mappings2);

            typeMapping.AddNestedMapping(mlc => mlc.Nested,
                                         new KeyValuePair <Expression <Func <Multiple2LayerClass, object> >, FieldTypes>(ml2 => ml2.Word, FieldTypes.Keyword),
                                         new KeyValuePair <Expression <Func <Multiple2LayerClass, object> >, FieldTypes>(ml2 => ml2.Value, FieldTypes.Double),
                                         new KeyValuePair <Expression <Func <Multiple2LayerClass, object> >, FieldTypes>(ml2 => ml2.DateTime, FieldTypes.Date));

            typeMapping.AddObjectMapping(mlc => mlc.Obj,
                                         new KeyValuePair <Expression <Func <Multiple2LayerClass, object> >, FieldTypes>(ml2 => ml2.Word, FieldTypes.Keyword),
                                         new KeyValuePair <Expression <Func <Multiple2LayerClass, object> >, FieldTypes>(ml2 => ml2.Value, FieldTypes.Double),
                                         new KeyValuePair <Expression <Func <Multiple2LayerClass, object> >, FieldTypes>(ml2 => ml2.DateTime, FieldTypes.Date));

            var mlTm = typeof(Multiple1LayerClass).GetTypeMapping <Multiple1LayerClass>();


            var json1 = JsonConvert.SerializeObject(new { mappings = typeMapping });
            var json2 = JsonConvert.SerializeObject(new { mappings = mlTm });

            Assert.AreEqual(json1, json2);
        }
コード例 #2
0
        public void TypeMappingJson_1()
        {
            var typeMapping = new TypeMapping <IndexedClass>();
            var mappings    =
                new KeyValuePair <Expression <Func <IndexedClass, object> >, FieldTypes>(ic => ic.Objects,
                                                                                         FieldTypes.Nested);

            typeMapping.AddMapping(mappings);

            typeMapping.AddNestedMapping(ic => ic.Objects, new KeyValuePair <Expression <Func <IndexedClass2, object> >, FieldTypes>(ic => ic.BString,
                                                                                                                                     FieldTypes.Keyword));

            var json = JsonConvert.SerializeObject(new { mappings = typeMapping });

            Assert.AreEqual("{\"mappings\":{\"h73.Elastic.TypeMappingTests.IndexedClass\":{\"properties\":{\"Objects\":{\"properties\":{\"BString\":{\"type\":\"keyword\"}},\"type\":\"nested\"}}}}}", json);
        }