簡體   English   中英

Elasticsearch為嵌套數組創建映射

[英]Elasticsearch create a mapping for nested array

我必須為需要索引的json數據使用elasticsearch和python創建索引,但我有一個嵌套數組數組[[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]解析為對象,但發現了具體值')需要幫助以解決此問題

您需要為此使用嵌套映射 這將確保每個嵌套對象都獨立於其他對象進行處理。 參閱文件

無論如何,我認為不可能為匿名的二級嵌套數組建立索引。 您需要在嵌套級別中命名屬性。

因此,假定屬性的順序(如映射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
   }
]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM