Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions kibana/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def update_urls(self):
self.get_url = ('http://%s:%s/' % (self._host[0], self._host[1]) +
'%s/' % self.index +
'index-pattern/%s/' % self._index_pattern)
# 'http://localhost:9200/.kibana/index-pattern/aaa*/_update'
self.update_url = ('http://%s:%s/' % (self._host[0], self._host[1]) +
'%s/' % self.index +
'index-pattern/%s/_update' % self._index_pattern)

@property
def index_pattern(self):
Expand Down Expand Up @@ -142,16 +146,16 @@ def dedup_field_cache(self, field_cache):
def post_field_cache(self, field_cache):
"""Where field_cache is a list of fields' mappings"""
index_pattern = self.field_cache_to_index_pattern(field_cache)
# self.pr_dbg("request/post: %s" % index_pattern)
resp = requests.post(self.post_url, data=index_pattern).text
# resp = {"_index":".kibana","_type":"index-pattern","_id":"aaa*","_version":1,"created":true} # noqa
resp = requests.put(self.update_url, data=index_pattern).text
# resp = {"_index":".kibana","_type":"index-pattern","_id":"aaa*","_version":???, ???} # noqa
resp = json.loads(resp)
return 0
# TODO detect failure (return 1)

def field_cache_to_index_pattern(self, field_cache):
"""Return a .kibana index-pattern doc_type"""
mapping_dict = {}
# consider ignoring customFormats to maintain existing value
mapping_dict['customFormats'] = "{}"
mapping_dict['title'] = self.index_pattern
# now post the data into .kibana
Expand Down