ES索引:
df_case = dd.read_csv('s3://../.../df_case.csv',dtpye={'Unnamed: 0': 'float64'})
df_limdata = dd.read_csv('s3://../.../df_limdata.csv',dtpye={'Unnamed: 0': 'float64'})
case = dd.merge(df_limdata, df_case, left_on='sacc_id$',right_on='sacc_id$')
# conversion to pandas
df = case.compute()
这是我的Elasticsearch索引中的文档。我需要获取每个文档的价格和数量的总和,作为查询索引的结果。
答案 0 :(得分:0)
您可以使用Script Fields来为每次匹配返回脚本评估(基于不同的字段)
尝试以下操作:
GET test1/_search
{
"query" : {
"match_all": {}
},
"script_fields" : {
"totalcost" : {
"script" : {
"lang": "painless",
"source": "doc['price'].value * doc['qty'].value"
}
},
"sumpriceandqty" : {
"script" : {
"lang": "painless",
"source": "doc['price'].value + doc['qty'].value"
}
}
}
}
编辑:更新的索引名称
我在本地测试了它,它可以正常工作,这是输出:
{
"took": 67,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "test1",
"_type": "doc",
"_id": "_xEopmgBbjdm4NNpj-tl",
"_score": 1,
"fields": {
"sumpriceandqty": [
3.2000000029802322
],
"totalcost": [
0.6000000089406967
]
}
}
]
}
}