Elasticsearch how count values from multiple document fields using aggregation

VitalyT

Suppose I have a lot of documents in the same index as following:

     "_source": {
            "customerId": "100",
            "firstName": "XAaa",
            "lastName": "XBbb",
            "price": 10,
            "revenue": 5
         }

     "_source": {
            "customerId": "100",
            "firstName": "XAaa",
            "lastName": "XBbb",
            "price": 20,
            "revenue": 15
        } 

    "_source": {
            "customerId": "200",
            "firstName": "YAaa",
            "lastName": "yBbb",
            "price": 110,
            "revenue": 20
       }....

Question

How make elasticsearch aggregation that count values from same customerId ??

Result should be something like:

          "_source": {
                "customerId": "100",
                "firstName": "XAaa",
                "lastName": "XBbb",
                "price": 30, // (10+20)
                "revenue": 20 //(5+15)
            } 

        "_source": {
                "customerId": "200",
                "firstName": "YAaa",
                "lastName": "yBbb",
                "price": 110,
                "revenue": 20
           }....

Thanks

Andrei Stefan
{
  "size": 0, 
  "aggs": {
    "per_customer": {
      "terms": {
        "field": "customerId",
        "size": 10
      },
      "aggs": {
        "total_price": {
          "sum" : { "field" : "price" }
        },
        "total_revenue": {
          "sum" : { "field" : "revenue" }
        }
      }
    }
  }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Elasticsearch how count values from multiple document fields using aggregation

From Dev

How to count fields in Mongodb Aggregation

From Dev

How to count fields in Mongodb Aggregation

From Dev

how to return the count of unique documents by using elasticsearch aggregation

From Dev

Elasticsearch - Aggregation on multiple fields in the same nested scope

From Dev

Elasticsearch group by multiple fields and sum the hours (aggregation)

From Java

How to sort multiple array independently in one mongo document using aggregation

From Dev

Using Terms aggregation in Nest elasticsearch for a specific document

From Dev

Create MongoDB fields with names based on sub-document values using aggregation pipeline?

From Dev

Count items from another document in mongodb aggregation

From Dev

Mongodb querying for aggregation with count of multiple values

From Dev

Mongodb querying for aggregation with count of multiple values

From Dev

Mongodb aggregation, how to combine or merge fields then count

From Dev

Mongodb aggregation, how to combine or merge fields then count

From Dev

How to do multi value count aggregation in elasticsearch

From Dev

Elasticsearch aggregation by 7 fields

From Dev

count documents by specific nested fields values with aggregation-framework in MongoDB

From Dev

How can I perform an aggregation on multiple fields?

From Dev

Using aggregation in MongoDB to select two or more fields of a document

From Dev

ElasticSearch match multiple fields with different values

From Dev

Return field from first and last document in Elasticsearch aggregation

From Dev

Return field from first and last document in Elasticsearch aggregation

From Dev

aggregation on fields values (regex)

From Dev

django count distinct values of multiple fields

From Dev

How to get a complete document from aggregation on mongodb

From Dev

How to return whole document from aggregation

From Dev

Aggregation distinct values in ElasticSearch

From Dev

elasticsearch unique values aggregation

From Dev

Elasticsearch: Count how often a term is in each document

Related Related

  1. 1

    Elasticsearch how count values from multiple document fields using aggregation

  2. 2

    How to count fields in Mongodb Aggregation

  3. 3

    How to count fields in Mongodb Aggregation

  4. 4

    how to return the count of unique documents by using elasticsearch aggregation

  5. 5

    Elasticsearch - Aggregation on multiple fields in the same nested scope

  6. 6

    Elasticsearch group by multiple fields and sum the hours (aggregation)

  7. 7

    How to sort multiple array independently in one mongo document using aggregation

  8. 8

    Using Terms aggregation in Nest elasticsearch for a specific document

  9. 9

    Create MongoDB fields with names based on sub-document values using aggregation pipeline?

  10. 10

    Count items from another document in mongodb aggregation

  11. 11

    Mongodb querying for aggregation with count of multiple values

  12. 12

    Mongodb querying for aggregation with count of multiple values

  13. 13

    Mongodb aggregation, how to combine or merge fields then count

  14. 14

    Mongodb aggregation, how to combine or merge fields then count

  15. 15

    How to do multi value count aggregation in elasticsearch

  16. 16

    Elasticsearch aggregation by 7 fields

  17. 17

    count documents by specific nested fields values with aggregation-framework in MongoDB

  18. 18

    How can I perform an aggregation on multiple fields?

  19. 19

    Using aggregation in MongoDB to select two or more fields of a document

  20. 20

    ElasticSearch match multiple fields with different values

  21. 21

    Return field from first and last document in Elasticsearch aggregation

  22. 22

    Return field from first and last document in Elasticsearch aggregation

  23. 23

    aggregation on fields values (regex)

  24. 24

    django count distinct values of multiple fields

  25. 25

    How to get a complete document from aggregation on mongodb

  26. 26

    How to return whole document from aggregation

  27. 27

    Aggregation distinct values in ElasticSearch

  28. 28

    elasticsearch unique values aggregation

  29. 29

    Elasticsearch: Count how often a term is in each document

HotTag

Archive