[英]How to efficiently move data from elasticsearch index (with one shard) to another index (with 5 shards)?
[英]How to sum of fields in elasticsearch and move another index
下面是我的映射。如果他們的名字相同,我想支付總和。 並將其放在支付領域。 然后,我想收集這樣的數據。
{
"person" : {
"mappings" : {
"dynamic_templates" : [
{
"strings" : {
"match_mapping_type" : "string",
"mapping" : {
"type" : "keyword"
}
}
}
],
"properties" : {
"userid" : {
"type" : "keyword"
},
"name" : {
"type" : "keyword"
},
"payment" : {
"type" : "keyword",
"fields" : {
"numeric" : {
"type" : "integer"
}
}
}
}
}
}
}
舉個例子
索引1
userid name payment
1234 Marco 20
2312 Sylvia 50
5653 Ruben 35
1234 Marco 30
預期結果
索引1
userid name payment
1234 Marco 50
2312 Sylvia 50
5653 Ruben 35
您需要的是利用Transform API 。 這將對您的數據運行聚合查詢並將聚合結果存儲到新索引中。
PUT _transform/person_payments
{
"source": {
"index": "person",
"query": {
"match_all": {}
}
}
},
"pivot": {
"group_by": {
"name": {
"terms": {
"field": "name"
}
}
},
"aggregations": {
"sum_payments": {
"sum": {
"field": "payment.numeric"
}
}
}
},
"dest": {
"index": "person_payments"
}
}
創建后,您可以使用POST _transform/person_payments/_start
開始轉換,完成后您將擁有一個名為person_payments
的新索引,其中包含您需要的數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.