Elasticsearch术语聚合文档计数问题

时间:2016-07-13 12:50:58

标签: elasticsearch

这是我发送给ElasticSearch的请求:

{
  "aggregations":{
    "followUpActivity.metainfo.metainfos.string1":{
      "terms":{
        "field":"metainfos.string1",
        "missing":"null",
        "order":{
          "_count":"asc"
        }
      }
    }
  }
}

我在字段metainfos.string1上请求存储桶并按_count排序。这是回复:

{
  "took":7,
  "timed_out":false,
  "_shards":{
    "total":1,
    "successful":1,
    "failed":0
  },
  "hits":{
    "total":3,
    "max_score":1.0,
    "hits":[
      {
        "_index":"living_v1",
        "_type":"fuas",
        "_id":"be9b29f3-37a5-11e6-a66a-30b5c2122322",
        "_score":1.0,
        "_routing":"living_team",
        "_source":{
          "user":"living_team",
          "timestamp":"2016-06-22T11:27:25.531Z",
          "metainfos":{
            "string1":[
              "s1",  <<<<<<<<<<<<<--------------
              "s2"   <<<<<<<<<<<<<--------------
            ]
          }
        }
      },
      {
        "_index":"living_v1",
        "_type":"fuas",
        "_id":"c3af0f64-37a5-11e6-a66a-30b5c2122322",
        "_score":1.0,
        "_routing":"living_team",
        "_source":{
          "user":"living_team",
          "timestamp":"2016-06-22T12:30:01.625Z",
          "metainfos":{
            "string1":[
              "s1",    <<<<<<<<<<<<<--------------
              "s2"     <<<<<<<<<<<<<--------------
            ]
          }
        }
      },
      {
        "_index":"living_v1",
        "_type":"fuas",
        "_id":"ee790469-48f3-11e6-9f47-30b5c2122322",
        "_score":1.0,
        "_routing":"living_team",
        "_source":{
          "user":"living_team",
          "timestamp":"2016-07-13T13:33:41.231Z",
          "metainfos":{
            "string1":[
              "s2"    <<<<<<<<<<<<<--------------
            ]
          }
        }
      }
    ]
  },
  "aggregations":{
    "followUpActivity.metainfo.metainfos.string1":{
      "doc_count_error_upper_bound":0,
      "sum_other_doc_count":0,
      "buckets":[
        {
          "key":"s2",
          "doc_count":2       <<<<<<<<<<<<<--------------
        },
        {
          "key":"s1",
          "doc_count":3       <<<<<<<<<<<<<--------------
        }
      ]
    }
  }
}

如您所见,有两个存储桶:s1s2。但是,s1仅存在于两个文档中,但ES告诉我doc_count = 3 !!!此外,s2出现在三个文件中,但ES告诉我doc_count = 2 !!!!

我只使用一个节点执行它。

有什么想法吗?

MAPPING

{
  "living_v1":{
    "mappings":{
      "fuas":{
        "properties":{
          "metainfos":{
            "properties":{
              "string1":{
                "type":"string"
              }
            }
          },
          "timestamp":{
            "type":"date",
            "format":"strict_date_optional_time||epoch_millis"
          },
          "user":{
            "type":"string",
            "index":"not_analyzed"
          }
        }
      }
    }
  }
}

0 个答案:

没有答案