【问题标题】:Elasticsearch create a mapping for nested arrayElasticsearch 为嵌套数组创建映射
【发布时间】:2016-07-05 02:51:00
【问题描述】:

我必须使用 elasticsearch 和 python 为需要索引的 json 数据创建索引示例我有一个嵌套数组数组 [[39.909971141540645, 1452077285.150548, 1452077286.196072, 1.0455241203308105]] 我需要为这个数组定义一个映射,比如第一个字段是 count ,第二个字段是 start_time, end_time, duration 。请帮助如何声明嵌套数组的映射。

我已经声明了使用 python 和 elasticsearch 模块的映射

index_mapping={
 "properties": {
"speed_events":{
"type":"object",
"properties":{
"count":{"type":"double"},
"start_time":{"type":"date"},
 "end_time":{"type":"date"},
"duration":{"type":"double"}
}}}
es.indices.put_mapping(index=index_name, doc_type=type_name,      body=index_mapping)

[speed_events] 的抛出错误对象映射试图将字段 [null] 解析为对象,但找到了具体值') 需要帮助来解决这个问题

【问题讨论】:

    标签: python arrays json elasticsearch schema


    【解决方案1】:

    您需要为此使用nested mapping。 这将确保每个嵌套对象都独立于其他对象进行处理。见documentation

    无论如何,我认为不可能索引匿名的两级嵌套数组。 您需要在嵌套级别中命名属性。

    因此,假设映射count, start_time, end_time, duration 中的属性顺序将不起作用:

    [  
       [  
          1,
          '1999-01-01',
          '2000-01-01',
          14.6
       ],
       [  
          2,
          '1999-01-01',
          '2000-01-01',
          16.6
       ]
    ]
    

    但您应该改为生成如下内容:

    [  
       {  
          'count':1,
          'start_time':'1999-01-01',
          'end_time':'2000-01-01',
          'duration':14.6
       },
       {  
          'count':2,
          'start_time':'1999-01-01',
          'end_time':'2000-01-01',
          'duration':16.6
       }
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-26
      • 1970-01-01
      • 2019-08-13
      • 2013-07-21
      • 1970-01-01
      • 2013-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多