我必须使用 elasticsearch 和 python 为需要索引的 json 数据创建索引示例我有一个嵌套数组数组 [[39.909971141540645, 1452077285.150548, 1452077286.196072, 1.0455241203308105]] 我需要为这个数组定义一个映射,比如第一个字段是计数, 第二个字段是 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] 解析为对象,但找到了一个具体值')
需要帮助来解决这个问题
最佳答案
您需要使用 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
}
]
关于python - Elasticsearch 为嵌套数组创建映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36082873/