Create a mapping in a given index

    index
        Index for the mapping
    doc_type
        Name of the document type
    body
        Mapping definition as specified in https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html
    source
        URL to file specifying mapping definition. Cannot be used in combination with ``body``.

    CLI example::

        salt myminion elasticsearch.mapping_create testindex user '{ "user" : { "properties" : { "message" : {"type" : "string", "store" : true } } } }'

def mapping_create(index, doc_type, body=None, hosts=None, profile=None, source=None):
    '''
    Create a mapping in a given index

    index
        Index for the mapping
    doc_type
        Name of the document type
    body
        Mapping definition as specified in https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html
    source
        URL to file specifying mapping definition. Cannot be used in combination with ``body``.

    CLI example::

        salt myminion elasticsearch.mapping_create testindex user '{ "user" : { "properties" : { "message" : {"type" : "string", "store" : true } } } }'
    '''
    es = _get_instance(hosts, profile)
    if source and body:
        message = 'Either body or source should be specified but not both.'
        raise SaltInvocationError(message)
    if source:
        body = __salt__['cp.get_file_str'](
                  source,
                  saltenv=__opts__.get('saltenv', 'base'))
    try:
        result = es.indices.put_mapping(index=index, doc_type=doc_type, body=body)

        return result.get('acknowledged', False)
    except elasticsearch.TransportError as e:
        raise CommandExecutionError("Cannot create mapping {0}, server returned code {1} with message {2}".format(index, e.status_code, e.error))