使用Bulk-API使用Elasticsearch-py向ElasticSearch添加时间戳

Coo*_*ire 4 python elasticsearch kibana kibana-4 elasticsearch-py

我正在尝试为我的数据添加时间戳,使用elasticsearch-py批量索引,然后使用kibana显示数据.

我的数据显示在kibana中,但我的时间戳没有被使用.当我在配置索引模式后进入"发现"选项卡时,我得到0结果(是的,我尝试调整搜索时间).

这是我的批量索引json的样子:

{'index': 
         {'_timestamp': u'2015-08-11 14:18:26', 
          '_type': 'webapp_fingerprint', 
          '_id': u'webapp_id_redacted_2015_08_13_12_39_34',
          '_index': 'webapp_index'
         }
}

****JSON DATA HERE***
Run Code Online (Sandbox Code Playgroud)

这将被elasticsearch接受并将被导入Kibana,但_timestamp字段实际上不会被索引(当在"时间字段名称"下配置索引模式时,它确实显示在下拉列表中).

我也试过像这样格式化metaFields:

{'index': {
           '_type': 'webapp_fingerprint', 
           '_id': u'webapp_id_redacted_2015_08_13_12_50_04', 
           '_index': 'webapp_index'
          }, 
           'source': {
                      '_timestamp': {
                                     'path': u'2015-08-11 14:18:26',
                                     'enabled': True, 
                                     'format': 'YYYY-MM-DD HH:mm:ss'
                                    }
                     }
}
Run Code Online (Sandbox Code Playgroud)

这也行不通.

最后,我尝试在索引中包含_timestamp字段并应用格式,但我在弹性搜索时出错.

{'index': {
           '_timestamp': {
                          'path': u'2015-08-11 14:18:26', 
                          'enabled': True, 
                          'format': 'YYYY-MM-DD HH:mm:ss'
                         }, 
           '_type': 'webapp_fingerprint', 
           '_id': u'webapp_id_redacted_2015_08_13_12_55_53', 
           '_index': 'webapp_index'
          }
}
Run Code Online (Sandbox Code Playgroud)

错误是:

elasticsearch.exceptions.TransportError: 
TransportError(500,u'IllegalArgumentException[Malformed action/metadata 
line [1], expected a simple value for field [_timestamp] but found [START_OBJECT]]')
Run Code Online (Sandbox Code Playgroud)

任何人可以提供的帮助将不胜感激.如果我没有充分解释这个问题,我会道歉.如果我需要澄清更多,请告诉我.谢谢.

Coo*_*ire 5

修正了我自己的问题.基本上,我需要在创建索引时为时间戳添加映射.

request_body = {
    "settings" : {
        "number_of_shards": 1,
        "number_of_replicas": 0
    },
    "mappings" : {
        "_default_":{
            "_timestamp":{
                 "enabled":"true",
                 "store":"true",
                 "path":"plugins.time_stamp.string",
                 "format":"yyyy-MM-dd HH:m:ss"
             }
         }
    }
}
print("creating '%s' index..." % (index_name))
res = es.indices.create(index = index_name, body = request_body)
print(" response: '%s'" % (res))
Run Code Online (Sandbox Code Playgroud)