2017-08-31 172 views
1

我应该保存下列数据Elasticsearch:如何在Elasticsearch中有效地存储我的表格数据?

mytypes = { 
     'type1': (
      date(2015, 3, 12), 
      date(2015, 5, 6) 
     ), 
     'type2': (
      date(2015, 4, 11), 
      date(2015, 4, 14), 
      date(2015, 4, 20) 
     ) 
    } 

我不知道什么是在Elasticsearch一个高效的数据结构。例如,我为type1创建了以下示例数据结构,但它看起来太硬编码给我。有没有更灵活的方式在Elasticsearch中存储这种数据?

PUT myconstants 
{ 
    "mappings": { 
     "type1": { 
     "_all": { 
     "enabled": true 
     }, 
     "properties": { 
      "date1": { 
      "type":"date" 
      }, 
      "date2": { 
      "type":"date" 
      } 
     } 
     } 
    } 
} 

回答

0

您可以只使用一个字段,并且可以将数组索引到它。所以,你可以把你的映射是这样的:

PUT myconstants 
{ 
    "mappings": { 
    "type1": { 
    "_all": { 
     "enabled": true 
    }, 
    "properties": { 
     "dates": { 
     "type":"date" 
     } 
    } 
    } 
} 

,然后在多日期添加文档:

PUT myconstants/type1/1 
{ 
    "dates": ["2017-01-01", "2017-01-02"] 
} 
相关问题