简体   繁体   English

Elasticsearch为嵌套数组创建映射

[英]Elasticsearch create a mapping for nested array

i have to create indexing using elasticsearch and python for the json data which need to be indexed example i have an nested array array [[39.909971141540645, 1452077285.150548, 1452077286.196072, 1.0455241203308105]] i need to define an mapping for this array like first field is count , second field is start_time, end_time, duration . 我必须为需要索引的json数据使用elasticsearch和python创建索引,但我有一个嵌套数组数组[[39.909971141540645,1452077285.150548,1452077286.196072,1.0455241203308105]]我需要为此数组定义一个映射,例如第一个字段是count ,第二个字段是start_time,end_time,duration。 please help how to declare mapping for nested array. 请帮助如何声明嵌套数组的映射。

i have declared mapping using python and elasticsearch module 我已经使用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)

its throwing error object mapping for [speed_events] tried to parse field [null] as object, but found a concrete value') need help to fix this 其针对[speed_events]的抛出错误对象映射尝试将字段[null]解析为对象,但发现了具体值')需要帮助以解决此问题

You need to use nested mapping for this. 您需要为此使用嵌套映射 This will ensure each of the nested objects are treated independently from other. 这将确保每个嵌套对象都独立于其他对象进行处理。 See documentation 参阅文件

Anyway I don't think it's possible to index anonymous two level nested arrays. 无论如何,我认为不可能为匿名的二级嵌套数组建立索引。 You need to name the properties in the nested level. 您需要在嵌套级别中命名属性。

So assumming order of properties as in mapping count, start_time, end_time, duration this will not work: 因此,假定属性的顺序(如映射count, start_time, end_time, duration将不起作用:

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

but you should instead produce something like this: 但您应该改为产生以下内容:

[  
   {  
      '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
   }
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM