/HW-Wireframe

A web skeleton built using HTML and CSS.

Primary LanguageCSS

HW-Wireframe

A web skeleton built using HTML and CSS.

Count of Accounts by State

Must be keyword field

GET bank/account/_search { "size": 0, "aggs": { "states": { "terms": { "field": "state.keyword" } } } }

This is the equivalent of using match_all

GET bank/account/_search { "size": 0, "query": { "match_all": {} }, "aggs": { "states": { "terms": { "field": "state.keyword" } } } }

Aggs work in the context of the query, so apply a filter like normal

GET bank/account/_search { "size": 0, "query": { "match": { "state.keyword": "CA" } }, "aggs": { "states": { "terms": { "field": "state.keyword" } } } }

You can also filter on terms

GET bank/account/_search { "size": 0, "query": { "bool": { "must": [ {"match": {"state.keyword": "CA"}}, {"range": {"age": {"gt": 35}}} ] } }, "aggs": { "states": { "terms": { "field": "state.keyword" } } } }

Lets add a metric back in

GET bank/account/_search { "size": 0, "query": { "bool": { "must": [ {"match": {"state.keyword": "CA"}}, {"range": {"age": {"gt": 35}}} ] } }, "aggs": { "states": { "terms": { "field": "state.keyword" }, "aggs": {"avg_bal": {"avg": {"field": "balance"} }} } } }

You can also just filter the results

GET bank/account/_search { "size": 0, "query": { "match": {"state.keyword": "CA"} }, "aggs": { "over35":{ "filter": { "range": {"age": {"gt": 35}} }, "aggs": {"avg_bal": {"avg": {"field": "balance"} }} } } }

Look at state avg and global average

GET bank/account/_search { "size": 0, "aggs": { "state_avg": { "terms": { "field": "state.keyword" }, "aggs": {"avg_bal": {"avg": {"field": "balance"}}} }, "global_avg": { "global": {}, "aggs": {"avg_bal": {"avg": {"field": "balance"}}} } } }