本节参考 官方文档 检索示例:

导入样本测试数据

https://gitee.com/xlh_blog/common_content/blob/master/es%E6%B5%8B%E8%AF%95%E6%95%B0%E6%8D%AE.json
POST /bank/account/_bulk
image.png
测试数据样本模板

  1. {
  2. "account_number": 1,
  3. "balance": 39225,
  4. "firstname": "Amber",
  5. "lastname": "Duke",
  6. "age": 32,
  7. "gender": "M",
  8. "address": "880 Holmes Lane",
  9. "employer": "Pyrami",
  10. "email": "amberduke@pyrami.com",
  11. "city": "Brogan",
  12. "state": "IL"
  13. }

检索示例介绍

下面的请求都是在Kibana dev-tools 操作

请求接口

  1. GET /bank/_search
  2. {
  3. "query": {
  4. "match_all": {}
  5. },
  6. "sort": [
  7. {
  8. "account_number": "asc"
  9. }
  10. ]
  11. }
  12. // query: 查询条件
  13. // sort: 排序条件

结果

  1. {
  2. "took" : 537, // 检索毫秒数
  3. "timed_out" : false, // 是否超时
  4. "_shards" : {
  5. "total" : 1,
  6. "successful" : 1,
  7. "skipped" : 0,
  8. "failed" : 0
  9. },
  10. "hits" : {
  11. "total" : {
  12. "value" : 1000, // 查询条数
  13. "relation" : "eq"
  14. },
  15. "max_score" : null,
  16. "hits" : [ // hits: 查询到的所有数据
  17. {
  18. "_index" : "bank",
  19. "_type" : "account",
  20. "_id" : "0",
  21. "_score" : null,
  22. "_source" : {
  23. "account_number" : 0,
  24. "balance" : 16623,
  25. "firstname" : "Bradshaw",
  26. "lastname" : "Mckenzie",
  27. "age" : 29,
  28. "gender" : "F",
  29. "address" : "244 Columbus Place",
  30. "employer" : "Euron",
  31. "email" : "bradshawmckenzie@euron.com",
  32. "city" : "Hobucken",
  33. "state" : "CO"
  34. },
  35. "sort" : [
  36. 0
  37. ]
  38. },
  39. ...
  40. ]
  41. }
  42. }

响应字段解释

  • took – 使用Elasticsearch运行查询所用的时间(毫秒)
  • timed_out – 搜索请求是否超时
  • _shards – 搜索了多少个碎片,以及有多少个碎片成功、失败或被跳过。
  • max_score – 最相关文件的得分
  • hits.total.value - 找到了多少匹配的文档
  • hits.sort - 文档的排序位置(当不按相关性得分排序时)
  • hits._score - 文档的相关性评分(在使用Match_All时不适用)

    响应结果说明

    Elasticsearch 默认会分页返回10条数据,不会一下返回所有数据。

    请求方式说明

    ES支持两种基本方式检索;

  • 通过REST request uri 发送搜索参数 (uri +检索参数);

  • 通过REST request body 来发送它们(uri+请求体);

也就是说除了上面示例的请求接口,根据请求体进行检索外;
还可以用GET请求参数的方式检索:

  1. GET bank/_search?q=*&sort=account_number:asc
  2. // q=* (查询所有)
  3. // sort=account_number:asc (按照account_number进行升序排列)

Query DSL

本小节参考官方文档:Query DSL
Elasticsearch提供了一个可以执行查询的Json风格的DSL。这个被称为Query DSL,该查询语言非常全面。

基本语法格式

一个查询语句的典型结构:

  1. QUERY_NAME:{
  2. ARGUMENT:VALUE,
  3. ARGUMENT:VALUE,...
  4. }

如果针对于某个字段,那么它的结构如下:

  1. {
  2. QUERY_NAME:{
  3. FIELD_NAME:{
  4. ARGUMENT:VALUE,
  5. ARGUMENT:VALUE,...
  6. }
  7. }
  8. }

请求示例:

  1. GET /bank/_search
  2. {
  3. "query": {
  4. "match_all": {}
  5. },
  6. "from": 0,
  7. "size": 5,
  8. "sort": [
  9. {
  10. "account_number": {
  11. "order": "desc"
  12. },
  13. "balance": {
  14. "order": "asc"
  15. }
  16. }
  17. ]
  18. }
  19. # match_all: 查询类型 [代表查询所有的索引], es中可以在query中组合非常多的查询类型完成复杂查询;
  20. # from+size: 限定, 完成分页功能; 从第几条数据开始, 每页有多少数据
  21. # sort: 排序, 多字段排序, 会在前序字段相等时后续字段内部排序, 否则以前序为准;

返回部分字段

请求示例:

  1. GET /bank/_search
  2. {
  3. "query": {
  4. "match_all": {}
  5. },
  6. "from": 0,
  7. "size": 5,
  8. "sort": [
  9. {
  10. "account_number": {
  11. "order": "desc"
  12. }
  13. }
  14. ],
  15. "_source": ["balance","firstname"]
  16. }
  17. # _source: 指定返回结果中包含的字段名

结果示例:

  1. {
  2. "took" : 259,
  3. "timed_out" : false,
  4. "_shards" : {
  5. "total" : 1,
  6. "successful" : 1,
  7. "skipped" : 0,
  8. "failed" : 0
  9. },
  10. "hits" : {
  11. "total" : {
  12. "value" : 1000,
  13. "relation" : "eq"
  14. },
  15. "max_score" : null,
  16. "hits" : [
  17. {
  18. "_index" : "bank",
  19. "_type" : "account",
  20. "_id" : "999",
  21. "_score" : null,
  22. "_source" : {
  23. "firstname" : "Dorothy",
  24. "balance" : 6087
  25. },
  26. "sort" : [
  27. 999
  28. ]
  29. }
  30. ]
  31. }
  32. }

match-匹配查询

精确查询-基本数据类型(非文本)

  1. GET /bank/_search
  2. {
  3. "query": {
  4. "match": {
  5. "account_number": 20
  6. }
  7. }
  8. }
  9. # 查找匹配 account_number 20 的数据 非文本推荐使用 term

模糊查询-文本字符串

  1. GET /bank/_search
  2. {
  3. "query": {
  4. "match": {
  5. "address": "mill lane"
  6. }
  7. }
  8. }
  9. # 查找匹配 address 包含 mill lane 的数据

match 即全文检索,对检索字段进行分词匹配,会按照响应的评分 _score 排序,原理是倒排索引。

精确匹配-文本字符串

  1. GET /bank/_search
  2. {
  3. "query": {
  4. "match": {
  5. "address.keyword": "288 Mill Street"
  6. }
  7. }
  8. }
  9. # 查找 address 288 Mill Street 的数据。
  10. # 这里的查找是精确查找,只有完全匹配时才会查找出存在的记录,
  11. # 如果想模糊查询应该使用match_phrase 短语匹配

match_phrase-短语匹配

将需要匹配的值当成一整个单词(不分词)进行检索

  1. GET /bank/_search
  2. {
  3. "query": {
  4. "match_phrase": {
  5. "address": "mill lane"
  6. }
  7. }
  8. }
  9. # 这里会检索 address 匹配包含短语 mill lane 的数据

multi_math-多字段匹配

  1. GET /bank/_search
  2. {
  3. "query": {
  4. "multi_match": {
  5. "query": "mill",
  6. "fields": [
  7. "city",
  8. "address"
  9. ]
  10. }
  11. }
  12. }
  13. # 检索 city address 字段匹配包含 mill 的数据, 会对查询条件分词
  14. # 类似数据库的 (where city like '%mill%' and address like %mill%)

bool-复合查询

复合语句可以合并,任何其他查询语句,包括符合语句。这也就意味着,复合语句之间可以互相嵌套,可以表达非常复杂的逻辑。

  • must:必须达到 must 所列举的所有条件;must 中的条件使用 AND 拼接
  • must_not:必须不匹配 must_not 所列举的所有条件;对 must 进行取反
  • should:应该满足 should 所列举的条件;should 中的条件使用 OR 拼接
    1. GET /bank/_search
    2. {
    3. "query": {
    4. "bool": {
    5. "must": [
    6. {
    7. "match": {
    8. "gender": "M"
    9. }
    10. },
    11. {
    12. "match": {
    13. "address": "mill"
    14. }
    15. }
    16. ]
    17. }
    18. }
    19. }
    20. # 查询 gender 包含 M address 包含 mill 的数据
    21. # where gender like '%M%' and address like '%mill%'

filter-结果过滤

并不是所有的查询都需要产生分数,特别是哪些仅用于 filtering 过滤的文档。为了不计算分数,elasticsearch 会自动检查场景并且优化查询的执行。filter 对结果进行过滤,且不计算相关性得分。

  1. GET bank/_search
  2. {
  3. "query": {
  4. "bool": {
  5. "must": [
  6. {
  7. "match": {
  8. "address": "mill"
  9. }
  10. }
  11. ],
  12. "filter": {
  13. "range": {
  14. "age": {
  15. "gte": "18",
  16. "lte": "30"
  17. }
  18. }
  19. }
  20. }
  21. }
  22. }
  23. # 这里先是查询所有匹配 address 包含 mill 的文档,
  24. # 然后再根据 age >= 18 and age <= 30 进行过滤查询结果
  25. # 过滤不会产生相关性得分

term-精确检索

Avoid using the term query for [text](https://www.elastic.co/guide/en/elasticsearch/reference/7.11/text.html) fields. 避免使用 term 查询文本字段 By default, Elasticsearch changes the values of text fields as part of analysis. This can make finding exact matches for text field values difficult. 默认情况下,Elasticsearch 会通过analysis分词将文本字段的值拆分为一部分,这使精确匹配文本字段的值变得困难。 To search text field values, use the [match](https://www.elastic.co/guide/en/elasticsearch/reference/7.11/query-dsl-match-query.html) query instead. 如果要查询文本字段值,请使用 match 查询代替。

https://www.elastic.co/guide/en/elasticsearch/reference/7.11/query-dsl-term-query.html

在上面 3.match-匹配查询 中有介绍对于非文本字段的精确查询,Elasticsearch 官方对于这种非文本字段,使用 term 来精确检索是一个推荐的选择

  1. GET bank/_search
  2. {
  3. "query": {
  4. "term": {
  5. "age": "28"
  6. }
  7. }
  8. }
  9. # 查找 age 28 的数据

Aggregation-执行聚合

https://www.elastic.co/guide/en/elasticsearch/reference/7.11/search-aggregations.html
terms:统计数量
avg:平均数
max:最大值
min:最小值

聚合语法

  1. GET /my-index-000001/_search
  2. {
  3. "aggs":{
  4. "aggs_name":{ # 这次聚合的名字,方便展示在结果集中
  5. "AGG_TYPE":{ # 聚合的类型(avg,terms)平均数、统计、最大值...
  6. }
  7. }
  8. }
  9. }

示例1-搜索 address 中包含 Mill 的所有人的年龄分布以及平均工资

  1. GET /bank/_search
  2. {
  3. "query": {
  4. "bool": {
  5. "must": [
  6. {
  7. "match": {
  8. "address": "Mill"
  9. }
  10. }
  11. ]
  12. }
  13. },
  14. "aggs": { // aggs: 聚合条件对象
  15. "ageAgg":{ // age_aggs: 自定义聚合结果对象名
  16. "terms": {
  17. "field": "age", // field: 指定聚合属性
  18. "size": 10 // size: 最大显示条数
  19. }
  20. },
  21. "balanceAgg": {
  22. "avg": {
  23. "field": "balance"
  24. }
  25. }
  26. },
  27. "size": 0 // 显示命中结果的条数
  28. }

结果

  1. {
  2. "took" : 1,
  3. "timed_out" : false,
  4. "_shards" : {
  5. "total" : 1,
  6. "successful" : 1,
  7. "skipped" : 0,
  8. "failed" : 0
  9. },
  10. "hits" : {
  11. "total" : {
  12. "value" : 4,
  13. "relation" : "eq"
  14. },
  15. "max_score" : null,
  16. "hits" : [ ]
  17. },
  18. "aggregations" : { // 聚合查询结果
  19. "ageAgg" : {
  20. "doc_count_error_upper_bound" : 0,
  21. "sum_other_doc_count" : 0,
  22. "buckets" : [
  23. {
  24. "key" : 38,
  25. "doc_count" : 2
  26. },
  27. {
  28. "key" : 28,
  29. "doc_count" : 1
  30. },
  31. {
  32. "key" : 32,
  33. "doc_count" : 1
  34. }
  35. ]
  36. },
  37. "balanceAgg" : {
  38. "value" : 25208.0
  39. }
  40. }
  41. }

示例2-按照年龄聚合,并且求这些年龄段的这些人的平均薪资

  1. GET /bank/_search
  2. {
  3. "query": {
  4. "match_all": {}
  5. },
  6. "aggs": {
  7. "ageAgg": {
  8. "terms": {
  9. "field": "age",
  10. "size": 100
  11. },
  12. "aggs": {
  13. "ageAvg": {
  14. "avg": {
  15. "field": "balance"
  16. }
  17. }
  18. }
  19. }
  20. },
  21. "size": 0
  22. }

结果

  1. {
  2. "took" : 1,
  3. "timed_out" : false,
  4. "_shards" : {
  5. "total" : 1,
  6. "successful" : 1,
  7. "skipped" : 0,
  8. "failed" : 0
  9. },
  10. "hits" : {
  11. "total" : {
  12. "value" : 1000,
  13. "relation" : "eq"
  14. },
  15. "max_score" : null,
  16. "hits" : [ ]
  17. },
  18. "aggregations" : {
  19. "ageAgg" : {
  20. "doc_count_error_upper_bound" : 0,
  21. "sum_other_doc_count" : 0,
  22. "buckets" : [
  23. {
  24. "key" : 31,
  25. "doc_count" : 61,
  26. "ageAvg" : {
  27. "value" : 28312.918032786885
  28. }
  29. },
  30. {
  31. "key" : 39,
  32. "doc_count" : 60,
  33. "ageAvg" : {
  34. "value" : 25269.583333333332
  35. }
  36. },
  37. {
  38. "key" : 26,
  39. "doc_count" : 59,
  40. "ageAvg" : {
  41. "value" : 23194.813559322032
  42. }
  43. },
  44. {
  45. "key" : 32,
  46. "doc_count" : 52,
  47. "ageAvg" : {
  48. "value" : 23951.346153846152
  49. }
  50. },
  51. {
  52. "key" : 35,
  53. "doc_count" : 52,
  54. "ageAvg" : {
  55. "value" : 22136.69230769231
  56. }
  57. },
  58. {
  59. "key" : 36,
  60. "doc_count" : 52,
  61. "ageAvg" : {
  62. "value" : 22174.71153846154
  63. }
  64. },
  65. {
  66. "key" : 22,
  67. "doc_count" : 51,
  68. "ageAvg" : {
  69. "value" : 24731.07843137255
  70. }
  71. },
  72. {
  73. "key" : 28,
  74. "doc_count" : 51,
  75. "ageAvg" : {
  76. "value" : 28273.882352941175
  77. }
  78. },
  79. {
  80. "key" : 33,
  81. "doc_count" : 50,
  82. "ageAvg" : {
  83. "value" : 25093.94
  84. }
  85. },
  86. {
  87. "key" : 34,
  88. "doc_count" : 49,
  89. "ageAvg" : {
  90. "value" : 26809.95918367347
  91. }
  92. },
  93. {
  94. "key" : 30,
  95. "doc_count" : 47,
  96. "ageAvg" : {
  97. "value" : 22841.106382978724
  98. }
  99. },
  100. {
  101. "key" : 21,
  102. "doc_count" : 46,
  103. "ageAvg" : {
  104. "value" : 26981.434782608696
  105. }
  106. },
  107. {
  108. "key" : 40,
  109. "doc_count" : 45,
  110. "ageAvg" : {
  111. "value" : 27183.17777777778
  112. }
  113. },
  114. {
  115. "key" : 20,
  116. "doc_count" : 44,
  117. "ageAvg" : {
  118. "value" : 27741.227272727272
  119. }
  120. },
  121. {
  122. "key" : 23,
  123. "doc_count" : 42,
  124. "ageAvg" : {
  125. "value" : 27314.214285714286
  126. }
  127. },
  128. {
  129. "key" : 24,
  130. "doc_count" : 42,
  131. "ageAvg" : {
  132. "value" : 28519.04761904762
  133. }
  134. },
  135. {
  136. "key" : 25,
  137. "doc_count" : 42,
  138. "ageAvg" : {
  139. "value" : 27445.214285714286
  140. }
  141. },
  142. {
  143. "key" : 37,
  144. "doc_count" : 42,
  145. "ageAvg" : {
  146. "value" : 27022.261904761905
  147. }
  148. },
  149. {
  150. "key" : 27,
  151. "doc_count" : 39,
  152. "ageAvg" : {
  153. "value" : 21471.871794871793
  154. }
  155. },
  156. {
  157. "key" : 38,
  158. "doc_count" : 39,
  159. "ageAvg" : {
  160. "value" : 26187.17948717949
  161. }
  162. },
  163. {
  164. "key" : 29,
  165. "doc_count" : 35,
  166. "ageAvg" : {
  167. "value" : 29483.14285714286
  168. }
  169. }
  170. ]
  171. }
  172. }
  173. }

示例3-查出所有年龄分布,并且这些年龄段中M的平均薪资和F的平均薪资以及这个年龄段的总体平均薪资

  1. GET /bank/_search
  2. {
  3. "query": {
  4. "match_all": {}
  5. },
  6. "aggs": {
  7. "ageAgg": {
  8. "terms": {
  9. "field": "age",
  10. "size": 100
  11. },
  12. "aggs": {
  13. "genderAgg": {
  14. "terms": {
  15. "field": "gender.keyword",
  16. "size": 10
  17. },
  18. "aggs": {
  19. "balanceAvg": {
  20. "avg": {
  21. "field": "balance"
  22. }
  23. }
  24. }
  25. },
  26. "ageBalanceAvg": {
  27. "avg": {
  28. "field": "balance"
  29. }
  30. }
  31. }
  32. }
  33. },
  34. "size": 0
  35. }

结果

  1. {
  2. "took" : 7,
  3. "timed_out" : false,
  4. "_shards" : {
  5. "total" : 1,
  6. "successful" : 1,
  7. "skipped" : 0,
  8. "failed" : 0
  9. },
  10. "hits" : {
  11. "total" : {
  12. "value" : 1000,
  13. "relation" : "eq"
  14. },
  15. "max_score" : null,
  16. "hits" : [ ]
  17. },
  18. "aggregations" : {
  19. "ageAgg" : {
  20. "doc_count_error_upper_bound" : 0,
  21. "sum_other_doc_count" : 0,
  22. "buckets" : [
  23. {
  24. "key" : 31,
  25. "doc_count" : 61,
  26. "genderAgg" : {
  27. "doc_count_error_upper_bound" : 0,
  28. "sum_other_doc_count" : 0,
  29. "buckets" : [
  30. {
  31. "key" : "M",
  32. "doc_count" : 35,
  33. "balanceAvg" : {
  34. "value" : 29565.628571428573
  35. }
  36. },
  37. {
  38. "key" : "F",
  39. "doc_count" : 26,
  40. "balanceAvg" : {
  41. "value" : 26626.576923076922
  42. }
  43. }
  44. ]
  45. },
  46. "ageBalanceAvg" : {
  47. "value" : 28312.918032786885
  48. }
  49. },
  50. {
  51. "key" : 39,
  52. "doc_count" : 60,
  53. "genderAgg" : {
  54. "doc_count_error_upper_bound" : 0,
  55. "sum_other_doc_count" : 0,
  56. "buckets" : [
  57. {
  58. "key" : "F",
  59. "doc_count" : 38,
  60. "balanceAvg" : {
  61. "value" : 26348.684210526317
  62. }
  63. },
  64. {
  65. "key" : "M",
  66. "doc_count" : 22,
  67. "balanceAvg" : {
  68. "value" : 23405.68181818182
  69. }
  70. }
  71. ]
  72. },
  73. "ageBalanceAvg" : {
  74. "value" : 25269.583333333332
  75. }
  76. },
  77. {
  78. "key" : 26,
  79. "doc_count" : 59,
  80. "genderAgg" : {
  81. "doc_count_error_upper_bound" : 0,
  82. "sum_other_doc_count" : 0,
  83. "buckets" : [
  84. {
  85. "key" : "M",
  86. "doc_count" : 32,
  87. "balanceAvg" : {
  88. "value" : 25094.78125
  89. }
  90. },
  91. {
  92. "key" : "F",
  93. "doc_count" : 27,
  94. "balanceAvg" : {
  95. "value" : 20943.0
  96. }
  97. }
  98. ]
  99. },
  100. "ageBalanceAvg" : {
  101. "value" : 23194.813559322032
  102. }
  103. },
  104. {
  105. "key" : 32,
  106. "doc_count" : 52,
  107. "genderAgg" : {
  108. "doc_count_error_upper_bound" : 0,
  109. "sum_other_doc_count" : 0,
  110. "buckets" : [
  111. {
  112. "key" : "M",
  113. "doc_count" : 28,
  114. "balanceAvg" : {
  115. "value" : 22941.964285714286
  116. }
  117. },
  118. {
  119. "key" : "F",
  120. "doc_count" : 24,
  121. "balanceAvg" : {
  122. "value" : 25128.958333333332
  123. }
  124. }
  125. ]
  126. },
  127. "ageBalanceAvg" : {
  128. "value" : 23951.346153846152
  129. }
  130. },
  131. {
  132. "key" : 35,
  133. "doc_count" : 52,
  134. "genderAgg" : {
  135. "doc_count_error_upper_bound" : 0,
  136. "sum_other_doc_count" : 0,
  137. "buckets" : [
  138. {
  139. "key" : "M",
  140. "doc_count" : 28,
  141. "balanceAvg" : {
  142. "value" : 24226.321428571428
  143. }
  144. },
  145. {
  146. "key" : "F",
  147. "doc_count" : 24,
  148. "balanceAvg" : {
  149. "value" : 19698.791666666668
  150. }
  151. }
  152. ]
  153. },
  154. "ageBalanceAvg" : {
  155. "value" : 22136.69230769231
  156. }
  157. },
  158. {
  159. "key" : 36,
  160. "doc_count" : 52,
  161. "genderAgg" : {
  162. "doc_count_error_upper_bound" : 0,
  163. "sum_other_doc_count" : 0,
  164. "buckets" : [
  165. {
  166. "key" : "M",
  167. "doc_count" : 31,
  168. "balanceAvg" : {
  169. "value" : 20884.677419354837
  170. }
  171. },
  172. {
  173. "key" : "F",
  174. "doc_count" : 21,
  175. "balanceAvg" : {
  176. "value" : 24079.04761904762
  177. }
  178. }
  179. ]
  180. },
  181. "ageBalanceAvg" : {
  182. "value" : 22174.71153846154
  183. }
  184. },
  185. {
  186. "key" : 22,
  187. "doc_count" : 51,
  188. "genderAgg" : {
  189. "doc_count_error_upper_bound" : 0,
  190. "sum_other_doc_count" : 0,
  191. "buckets" : [
  192. {
  193. "key" : "F",
  194. "doc_count" : 27,
  195. "balanceAvg" : {
  196. "value" : 22152.74074074074
  197. }
  198. },
  199. {
  200. "key" : "M",
  201. "doc_count" : 24,
  202. "balanceAvg" : {
  203. "value" : 27631.708333333332
  204. }
  205. }
  206. ]
  207. },
  208. "ageBalanceAvg" : {
  209. "value" : 24731.07843137255
  210. }
  211. },
  212. {
  213. "key" : 28,
  214. "doc_count" : 51,
  215. "genderAgg" : {
  216. "doc_count_error_upper_bound" : 0,
  217. "sum_other_doc_count" : 0,
  218. "buckets" : [
  219. {
  220. "key" : "F",
  221. "doc_count" : 31,
  222. "balanceAvg" : {
  223. "value" : 27076.8064516129
  224. }
  225. },
  226. {
  227. "key" : "M",
  228. "doc_count" : 20,
  229. "balanceAvg" : {
  230. "value" : 30129.35
  231. }
  232. }
  233. ]
  234. },
  235. "ageBalanceAvg" : {
  236. "value" : 28273.882352941175
  237. }
  238. },
  239. {
  240. "key" : 33,
  241. "doc_count" : 50,
  242. "genderAgg" : {
  243. "doc_count_error_upper_bound" : 0,
  244. "sum_other_doc_count" : 0,
  245. "buckets" : [
  246. {
  247. "key" : "F",
  248. "doc_count" : 26,
  249. "balanceAvg" : {
  250. "value" : 26437.615384615383
  251. }
  252. },
  253. {
  254. "key" : "M",
  255. "doc_count" : 24,
  256. "balanceAvg" : {
  257. "value" : 23638.291666666668
  258. }
  259. }
  260. ]
  261. },
  262. "ageBalanceAvg" : {
  263. "value" : 25093.94
  264. }
  265. },
  266. {
  267. "key" : 34,
  268. "doc_count" : 49,
  269. "genderAgg" : {
  270. "doc_count_error_upper_bound" : 0,
  271. "sum_other_doc_count" : 0,
  272. "buckets" : [
  273. {
  274. "key" : "F",
  275. "doc_count" : 30,
  276. "balanceAvg" : {
  277. "value" : 26039.166666666668
  278. }
  279. },
  280. {
  281. "key" : "M",
  282. "doc_count" : 19,
  283. "balanceAvg" : {
  284. "value" : 28027.0
  285. }
  286. }
  287. ]
  288. },
  289. "ageBalanceAvg" : {
  290. "value" : 26809.95918367347
  291. }
  292. },
  293. {
  294. "key" : 30,
  295. "doc_count" : 47,
  296. "genderAgg" : {
  297. "doc_count_error_upper_bound" : 0,
  298. "sum_other_doc_count" : 0,
  299. "buckets" : [
  300. {
  301. "key" : "F",
  302. "doc_count" : 25,
  303. "balanceAvg" : {
  304. "value" : 25316.16
  305. }
  306. },
  307. {
  308. "key" : "M",
  309. "doc_count" : 22,
  310. "balanceAvg" : {
  311. "value" : 20028.545454545456
  312. }
  313. }
  314. ]
  315. },
  316. "ageBalanceAvg" : {
  317. "value" : 22841.106382978724
  318. }
  319. },
  320. {
  321. "key" : 21,
  322. "doc_count" : 46,
  323. "genderAgg" : {
  324. "doc_count_error_upper_bound" : 0,
  325. "sum_other_doc_count" : 0,
  326. "buckets" : [
  327. {
  328. "key" : "F",
  329. "doc_count" : 24,
  330. "balanceAvg" : {
  331. "value" : 28210.916666666668
  332. }
  333. },
  334. {
  335. "key" : "M",
  336. "doc_count" : 22,
  337. "balanceAvg" : {
  338. "value" : 25640.18181818182
  339. }
  340. }
  341. ]
  342. },
  343. "ageBalanceAvg" : {
  344. "value" : 26981.434782608696
  345. }
  346. },
  347. {
  348. "key" : 40,
  349. "doc_count" : 45,
  350. "genderAgg" : {
  351. "doc_count_error_upper_bound" : 0,
  352. "sum_other_doc_count" : 0,
  353. "buckets" : [
  354. {
  355. "key" : "M",
  356. "doc_count" : 24,
  357. "balanceAvg" : {
  358. "value" : 26474.958333333332
  359. }
  360. },
  361. {
  362. "key" : "F",
  363. "doc_count" : 21,
  364. "balanceAvg" : {
  365. "value" : 27992.571428571428
  366. }
  367. }
  368. ]
  369. },
  370. "ageBalanceAvg" : {
  371. "value" : 27183.17777777778
  372. }
  373. },
  374. {
  375. "key" : 20,
  376. "doc_count" : 44,
  377. "genderAgg" : {
  378. "doc_count_error_upper_bound" : 0,
  379. "sum_other_doc_count" : 0,
  380. "buckets" : [
  381. {
  382. "key" : "M",
  383. "doc_count" : 27,
  384. "balanceAvg" : {
  385. "value" : 29047.444444444445
  386. }
  387. },
  388. {
  389. "key" : "F",
  390. "doc_count" : 17,
  391. "balanceAvg" : {
  392. "value" : 25666.647058823528
  393. }
  394. }
  395. ]
  396. },
  397. "ageBalanceAvg" : {
  398. "value" : 27741.227272727272
  399. }
  400. },
  401. {
  402. "key" : 23,
  403. "doc_count" : 42,
  404. "genderAgg" : {
  405. "doc_count_error_upper_bound" : 0,
  406. "sum_other_doc_count" : 0,
  407. "buckets" : [
  408. {
  409. "key" : "M",
  410. "doc_count" : 24,
  411. "balanceAvg" : {
  412. "value" : 27730.75
  413. }
  414. },
  415. {
  416. "key" : "F",
  417. "doc_count" : 18,
  418. "balanceAvg" : {
  419. "value" : 26758.833333333332
  420. }
  421. }
  422. ]
  423. },
  424. "ageBalanceAvg" : {
  425. "value" : 27314.214285714286
  426. }
  427. },
  428. {
  429. "key" : 24,
  430. "doc_count" : 42,
  431. "genderAgg" : {
  432. "doc_count_error_upper_bound" : 0,
  433. "sum_other_doc_count" : 0,
  434. "buckets" : [
  435. {
  436. "key" : "F",
  437. "doc_count" : 23,
  438. "balanceAvg" : {
  439. "value" : 29414.521739130436
  440. }
  441. },
  442. {
  443. "key" : "M",
  444. "doc_count" : 19,
  445. "balanceAvg" : {
  446. "value" : 27435.052631578947
  447. }
  448. }
  449. ]
  450. },
  451. "ageBalanceAvg" : {
  452. "value" : 28519.04761904762
  453. }
  454. },
  455. {
  456. "key" : 25,
  457. "doc_count" : 42,
  458. "genderAgg" : {
  459. "doc_count_error_upper_bound" : 0,
  460. "sum_other_doc_count" : 0,
  461. "buckets" : [
  462. {
  463. "key" : "M",
  464. "doc_count" : 23,
  465. "balanceAvg" : {
  466. "value" : 29336.08695652174
  467. }
  468. },
  469. {
  470. "key" : "F",
  471. "doc_count" : 19,
  472. "balanceAvg" : {
  473. "value" : 25156.263157894737
  474. }
  475. }
  476. ]
  477. },
  478. "ageBalanceAvg" : {
  479. "value" : 27445.214285714286
  480. }
  481. },
  482. {
  483. "key" : 37,
  484. "doc_count" : 42,
  485. "genderAgg" : {
  486. "doc_count_error_upper_bound" : 0,
  487. "sum_other_doc_count" : 0,
  488. "buckets" : [
  489. {
  490. "key" : "M",
  491. "doc_count" : 23,
  492. "balanceAvg" : {
  493. "value" : 25015.739130434784
  494. }
  495. },
  496. {
  497. "key" : "F",
  498. "doc_count" : 19,
  499. "balanceAvg" : {
  500. "value" : 29451.21052631579
  501. }
  502. }
  503. ]
  504. },
  505. "ageBalanceAvg" : {
  506. "value" : 27022.261904761905
  507. }
  508. },
  509. {
  510. "key" : 27,
  511. "doc_count" : 39,
  512. "genderAgg" : {
  513. "doc_count_error_upper_bound" : 0,
  514. "sum_other_doc_count" : 0,
  515. "buckets" : [
  516. {
  517. "key" : "F",
  518. "doc_count" : 21,
  519. "balanceAvg" : {
  520. "value" : 21618.85714285714
  521. }
  522. },
  523. {
  524. "key" : "M",
  525. "doc_count" : 18,
  526. "balanceAvg" : {
  527. "value" : 21300.38888888889
  528. }
  529. }
  530. ]
  531. },
  532. "ageBalanceAvg" : {
  533. "value" : 21471.871794871793
  534. }
  535. },
  536. {
  537. "key" : 38,
  538. "doc_count" : 39,
  539. "genderAgg" : {
  540. "doc_count_error_upper_bound" : 0,
  541. "sum_other_doc_count" : 0,
  542. "buckets" : [
  543. {
  544. "key" : "F",
  545. "doc_count" : 20,
  546. "balanceAvg" : {
  547. "value" : 27931.65
  548. }
  549. },
  550. {
  551. "key" : "M",
  552. "doc_count" : 19,
  553. "balanceAvg" : {
  554. "value" : 24350.894736842107
  555. }
  556. }
  557. ]
  558. },
  559. "ageBalanceAvg" : {
  560. "value" : 26187.17948717949
  561. }
  562. },
  563. {
  564. "key" : 29,
  565. "doc_count" : 35,
  566. "genderAgg" : {
  567. "doc_count_error_upper_bound" : 0,
  568. "sum_other_doc_count" : 0,
  569. "buckets" : [
  570. {
  571. "key" : "M",
  572. "doc_count" : 23,
  573. "balanceAvg" : {
  574. "value" : 29943.17391304348
  575. }
  576. },
  577. {
  578. "key" : "F",
  579. "doc_count" : 12,
  580. "balanceAvg" : {
  581. "value" : 28601.416666666668
  582. }
  583. }
  584. ]
  585. },
  586. "ageBalanceAvg" : {
  587. "value" : 29483.14285714286
  588. }
  589. }
  590. ]
  591. }
  592. }
  593. }