Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

es聚合 #31

Open
jamesBan opened this issue Apr 1, 2021 · 0 comments
Open

es聚合 #31

jamesBan opened this issue Apr 1, 2021 · 0 comments
Labels
search 搜索引擎 日志

Comments

@jamesBan
Copy link
Owner

jamesBan commented Apr 1, 2021

1、index mapping

PUT /test-003
{
  "mappings": {
    "properties": {
      "order_amount": {
        "type": "long"
      },
      "order_date": {
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
      },
      "order_category": {
        "type": "long"
      }
    }
  }
}

2、add data

POST _bulk
{ "index" : { "_index" : "test-003", "_id" : "1" } }
{"order_amount":1, "order_date": "2021-01-02", "order_category": 1}
{ "index" : { "_index" : "test-003", "_id" : "2" } }
{"order_amount":3, "order_date": "2021-01-03", "order_category": 2}
{ "index" : { "_index" : "test-003", "_id" : "3" } }
{"order_amount":5, "order_date": "2021-01-05", "order_category": 3}

3、aggs

POST test-003/_search
{
  "size": 0,
  "query": {
    "match_all": {}
  },
  "aggs": {
    "sum(order_amount)": {
      "sum": {
        "field": "order_amount"
      }
    },
    "max(order_amount)": {
      "max": {
        "field": "order_amount"
      }
    },
    "avg(order_amount)": {
      "max": {
        "field": "order_amount"
      }
    },
    "order_category": {
      "terms": {
        "field": "order_category",
        "size": 10
      },
      "aggs": {
        "order_histogram": {
          "date_histogram": {
            "field": "order_date",
            "interval": "day",
            "format": "yyyy-MM-dd",
            "min_doc_count": 0,
            "extended_bounds": {
              "min": "2021-01-01",
              "max": "2021-01-06"
            }
          }
        }
      }
    }
  }
}
@jamesBan jamesBan added 日志 search 搜索引擎 labels Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
search 搜索引擎 日志
Projects
None yet
Development

No branches or pull requests

1 participant