#!/usr/bin/env python
import sys, optparse,requests, json
'''
This tool prints all the types names in a an elasticsearch index
Parameters: IP address and index 
'''
def find_types(address, index):
  url = 'http://' + address + ':9200/' + index + '/_mapping' 
  response = requests.get(url)
  data = json.loads(response.text)
  i = 0
  for key in data[index]['mappings'].keys():
   print key
   i+=1
  print 
  print "The are", i,  "types in the", index, "index" 

def main():
  p = optparse.OptionParser(description='get all the types name from an elasticsearch index')
  p.add_option('-a', '--address', action ='store', help='The address of the host')
  p.add_option('-i', '--index', action ='store', help='The Name of the Index')
  options, arguments = p.parse_args()
  if options.address is None:
   print "no address"
  elif options.index is None:
   print "no index"
  else:
    find_types(options.address, options.index)
if __name__ == '__main__':
  main()
