def update_by_query(index, doc_type, data, projection, _filter, es_params, _as=None, pop_fields=None): _id, obj = util.obj_from_oplog(data=data, _filter=_filter, projection=projection, pop_fields=pop_fields) if not obj and not _as: es_client.delete_by_query(index=index, doc_type=doc_type, body={'query': {'term': {'_id': _id}}}) else: obj = util.dict_projection(obj, projection) if isinstance(obj, dict) and len(obj) > 0: _as = _as + '.' if _as else '' inline = '' if obj: for k in obj: ks = copy.deepcopy(k) for key in re.findall(r'\.\d+', k): ks = ks.replace(key, '[{0}]'.format(key[1:])) inline += 'ctx._source.{0}{1}=params.{2};'.format(_as, ks, k.replace('.', '')) for k in obj: if k.find('.') > -1: kr = k.replace('.', '') obj[kr] = obj[k] del obj[k] else: inline += 'ctx._source.{0}={};'.format(_as) query = {'term': {(_as + '_id'): _id}} body = {'query': query, 'script': {'inline': inline, 'params': obj, 'lang': 'painless'}} es_client.update_by_query(index=index, doc_type=doc_type, body=body, conflicts='proceed', params=es_params)
def on_insert(data): _id, obj = util.obj_from_oplog(data, order_cursor.filter) if _id and obj: parent = obj.get('car_change_plan_id') obj = util.dict_projection(obj, order_cursor.projection) es_client.index(index=opt['index'], doc_type=opt['type'], id=_id, parent=parent, params=opt['params'], body=obj)
def on_update(data): _id, obj = util.obj_from_oplog(data, car_offer_cursor.filter) if _id and obj: index_one(_id) else: es_sync_util.delete(index=opt['index'], doc_type=opt['type'], data=data, _filter=car_offer_cursor.filter, es_params=opt['params'])
def on_insert(data): _id, obj = util.obj_from_oplog(data, impression_track_cursor.filter) if _id and obj: obj = util.dict_projection(obj, impression_track_cursor.projection) obj = _.assign(obj, track_util.url_split(_.get(obj, 'uri'))) es_client.index(index=opt['index'], doc_type=opt['type'], id=_id, params=opt['params'], body=obj)
def on_insert(data): _id, obj = util.obj_from_oplog(data,pos_order_cursor.filter, pop_fields=pos_order_cursor.pop_fields) if _id and obj: parent = _.get(obj,'order') obj = util.dict_projection(obj, pos_order_cursor.projection) if parent: es_client.index(index=opt['index'], doc_type=opt['type'], id=_id, parent=parent, params=opt['params'], body=obj) else: es_client.index(index=opt['index'], doc_type=opt['type'], id=_id, params=opt['params'], body=obj)
def on_delete(data): _id = util.obj_from_oplog(data, car_offer_cursor.filter)[0] if _id: c = es_client.count(index=opt['index'], doc_type=opt['type'], body={'query': { 'term': { '_id': _id } }}, filter_path=['count']) if _.get(c, 'count') > 0: es_sync_util.delete(index=opt['index'], doc_type=opt['type'], data=data, _filter=car_offer_cursor.filter, es_params=opt['params'])
def on_insert(data): _id, obj = util.obj_from_oplog(data, used_car_offer_cursor.filter) if _id and obj: index_one(_id)
def delete(index, doc_type, data, _filter, es_params=None): _id = util.obj_from_oplog(data, _filter)[0] if _id: es_client.delete_by_query(index=index, doc_type=doc_type, body={'query': {'term': {'_id': _id}}}, params=es_params)
def on_insert(data): _id, obj = util.obj_from_oplog(data, car_change_plan_cursor.filter) if _id and obj: index_one(_id)