python elasticsearch bulk_Python elasticsearch助手.bulk错误地失败了?(缺少脚本或文档)...

在python函数中使用以下有效负载[{'_id': '979507', [15/1871]

'_index': 'follow-search-alias',

'_op_type': 'update',

'_type': 'follow',

'script': {'inline': 'ctx._source.followers += follower',

'lang': 'groovy',

'params': {'follower': ['3054805']}}},

{'_id': '979507',

'_index': 'follow-search-alias',

'_op_type': 'update',

'_type': 'follow',

'script': {'inline': 'ctx._source.following += user_being_followed',

'lang': 'groovy',

'params': {'user_being_followed': []}}},

{'_id': '3054805',

'_index': 'follow-search-alias',

'_op_type': 'update',

'_type': 'follow',

'script': {'inline': 'ctx._source.followers += follower',

'lang': 'groovy',

'params': {'follower': []}}},

{'_id': '3054805',

'_index': 'follow-search-alias',

'_op_type': 'update',

'_type': 'follow',

'script': {'inline': 'ctx._source.following += user_being_followed',

'lang': 'groovy',

'params': {'user_being_followed': ['979507']}}}]

使用python的elasticsearch时,我得到以下错误助手.bulk()

^{pr2}$

到底怎么会这样?此数组中的每个元素都有一个脚本标记。这个函数本身已经在很多其他情况下起作用了,只是这一个和其他一些精选的例子不一样。在

在shell中手动运行它可以工作,但不能在这个函数中运行?在

功能如下:@classmethod

def add_follows(cls, follows):

docs = []

user_ids = [f.follower_id for f in follows] + [f.followed_id for f in follows]

users = User.query.filter(User.id.in_(user_ids)).all()

valid_user_ids = set([u.id for u in users])

grouped_follows = {}

for follow in follows:

if (follow.follower_id not in valid_user_ids) or (follow.followed_id not in valid_user_ids):

continue

if not follow.follower_id in grouped_follows:

grouped_follows[follow.follower_id] = {

'followers': [],

'following': []

}

if not follow.followed_id in grouped_follows:

grouped_follows[follow.followed_id] = {

'followers': [],

'following': []

}

grouped_follows[follow.follower_id]['following'].append(str(follow.followed_id))

grouped_follows[follow.followed_id]['followers'].append(str(follow.follower_id))

for user_id, data in grouped_follows.items():

follower_action = {

'_index': FSC.FOLLOW_SEARCH_INDEX_NAME,

'_type': FSC.FOLLOW_SEARCH_MAPPING_NAME,

'_id': str(user_id),

'_op_type': 'update',

'script': {

'inline': 'ctx._source.followers += follower',

'params': {

'follower': data['followers']

},

'lang': 'groovy'

}

}

followed_action = {

'_index': FSC.FOLLOW_SEARCH_INDEX_NAME,

'_type': FSC.FOLLOW_SEARCH_MAPPING_NAME,

'_id': str(user_id),

'_op_type': 'update',

'script': {

'inline': 'ctx._source.following += user_being_followed',

'params': {

'user_being_followed': data['following']

},

'lang': 'groovy'

}

}

docs += [follower_action, followed_action]

print docs

if docs:

helpers.bulk(es, docs, request_timeout=300)

我正在一个shell中运行这个。我甚至写了两行字:global payload

payload = docs

在空壳里# after the above function fails

In [96]: helpers.bulk(es, payload)

Out[96]: (4, [])

所以它有效吗?相同的有效载荷?功能相同?刚才它在功能之外?考虑到这些问题,我甚至不敢相信这个库会投入生产。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值