def create_mapping(new_index, alias, num_replicas=DEFAULT_NUM_REPLICAS, num_shards=DEFAULT_NUM_SHARDS): """Creates a mapping for the new index. - new_index: new index name. - alias: alias name - num_replicas: number of replicas in ES - num_shards: number of shards in ES """ log('Create the mapping for index %r, alias: %r' % (new_index, alias)) if requests.head(url('/' + alias)).status_code == 200: res = call_es('%s/_settings' % (alias)).json idx_settings = res.get(alias, {}).get('settings', {}) else: idx_settings = {} settings = { 'number_of_replicas': idx_settings.get('number_of_replicas', num_replicas), 'number_of_shards': idx_settings.get('number_of_shards', num_shards) } # Create mapping.without aliases since we do it manually if not 'stats' in alias: put_amo_mapping(new_index, aliased=False) else: put_stats_mapping(new_index, aliased=False) if django_settings.MARKETPLACE: put_mkt_stats_mapping(new_index, aliased=False) # Create new index index_url = url('/%s' % new_index) # if the index already exists we can keep it if requests.head(index_url).status_code == 200: return call_es(index_url, json.dumps(settings), method='PUT', status=(200, 201))
def create_mapping(new_index, alias, num_replicas=DEFAULT_NUM_REPLICAS, num_shards=DEFAULT_NUM_SHARDS, stdout=sys.stdout): """Creates a mapping for the new index. - new_index: new index name. - alias: alias name - num_replicas: number of replicas in ES - num_shards: number of shards in ES """ log('Create the mapping for index %r, alias: %r' % (new_index, alias), stdout=stdout) if requests.head(url('/' + alias)).status_code == 200: res = call_es('%s/_settings' % (alias)).json() idx_settings = res.get(alias, {}).get('settings', {}) else: idx_settings = {} settings = { 'number_of_replicas': idx_settings.get('number_of_replicas', num_replicas), 'number_of_shards': idx_settings.get('number_of_shards', num_shards) } # Create mapping without aliases since we do it manually if not 'stats' in alias: put_amo_mapping(new_index, aliased=False) else: put_stats_mapping(new_index, aliased=False) # Create new index index_url = url('/%s' % new_index) # if the index already exists we can keep it if requests.head(index_url).status_code == 200: return call_es(index_url, json.dumps(settings), method='PUT', status=(200, 201))