2015-06-04 50 views
1

我试图建立一个对象,它看起来像这样的映射排除继承的对象属性:如何从映射

class TestObject 
{ 
    public long TestID { get; set; } 

    [ElasticProperty(Type = FieldType.Object)] 
    public Dictionary<long, List<DateTime>> Items { get; set; } 
} 

我用下面的映射代码(其中客户端是IElasticClient):

this.Client.Map<TestObject>(m => m.MapFromAttributes()); 

我碰到下面的映射结果:

{ 
"mappings": { 
    "testobject": { 
    "properties": { 
     "items": { 
     "properties": { 
      "comparer": { 
      "type": "object" 
      }, 
      "count": { 
      "type": "integer" 
      }, 
      "item": { 
      "type": "date", 
      "format": "dateOptionalTime" 
      }, 
      "keys": { 
      "properties": { 
       "count": { 
       "type": "integer" 
       } 
      } 
      }, 
      "values": { 
      "properties": { 
       "count": { 
       "type": "integer" 
       } 
      } 
      } 
     } 
     }, 
     "testID": { 
     "type": "long" 
     } 
    } 
    } 
} 

这将成为一个问题,当我想要做这样的搜索:

{ 
    "query_string": { 
     "query": "[2015-06-03T00:00:00.000 TO 2015-06-05T23:59:59.999]", 
      "fields": [ 
       "items.*" 
       ] 
       } 
      } 

这导致例外,我猜是因为在项目的所有字段对象是同一类型的不行。什么是适当的映射到这种类型的搜索?

回答

1

我能够通过使用以下映射来解决这个:

this.Client.Map<TestObject>(m => m.MapFromAttributes()) 
    .Properties(p => p 
     .Object<Dictionary<long, List<DateTime>>>(o => o.Name("items")));