试试搜索一下吧

求解,elasticsearch5.4 aggregations查询一个字段被拆分

Elasticsearch | 作者 imsa | 发布于2017年12月01日 | 阅读数:2412

查询:

{
"from": 0,
"size": 0,
"query": {
"bool": {
"filter": [
{
"bool": {
"must": [
{
"bool": {
"must": [
{
"match_phrase": {
"rep_date": {
"query": "2017-11-29",
"slop": 0,
"boost": 1
}
}
},
{
"match_phrase": {
"project_id": {
"query": 6164,
"slop": 0,
"boost": 1
}
}
},
{
"match_phrase": {
"domain": {
"query": "com.book2345.reader",
"slop": 0,
"boost": 1
}
}
}
],
"disable_coord": false,
"adjust_pure_negative": true,
"boost": 1
}
}
],
"disable_coord": false,
"adjust_pure_negative": true,
"boost": 1
}
}
],
"disable_coord": false,
"adjust_pure_negative": true,
"boost": 1
}
},
"_source": {
"includes": [
"domain",
"SUM"
],
"excludes": []
},
"stored_fields": "domain",
"aggregations": {
"domain": {
"terms": {
"field": "domain",
"size": 200,
"min_doc_count": 1,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_term": "asc"
}
]
},
"aggregations": {
"SUM(bid)": {
"sum": {
"field": "bid"
}
}
}
}
}
}
 
 
查询结果
 {
  "took" : 9,
  "timed_out" : false,
  "_shards" : {
    "total" : 24,
    "successful" : 24,
    "failed" : 0
  },
  "hits" : {
    "total" : 6,
    "max_score" : 0.0,
    "hits" : [ ]
  },
  "aggregations" : {
    "domain" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : [
        {
          "key" : "com.book2345",                              ————————————被拆分成两个字段
          "doc_count" : 6,
          "SUM(bid)" : {
            "value" : 743366.0
          }
        },
        {
          "key" : "reader",
          "doc_count" : 6,
          "SUM(bid)" : {
            "value" : 743366.0
          }
        }
      ]
    }
已邀请:

mafa1993

赞同来自:

mapping里设置一个keyword, 用于保存完整字段, 聚合是用keyword, 不然会被分词

要回复问题请先登录注册