Elasticsearch:Aggregation有时返回垃圾值

时间:2015-08-03 15:13:57

标签: python elasticsearch

我对Elasticsearch比较陌生。如果有人能帮我解决聚合查询中的问题,我真的很感激。我在一个节点上有5个集群的默认设置。我的索引包含如下映射:

    mapping = {
      "my_index": {
        "date_detection": False,
        "dynamic_templates": [{
          "string_fields": {
            "mapping": {
              "type": "string",
              "fields": {
                "raw": {
                  "index": "not_analyzed",
                  "ignore_above": 256,
                  "type": "string"
                }
              }
            },
            "match_mapping_type": "string",
            "match": "*"
          }
        }]
      }
    }

我已经为我的要求创建了聚合查询,如下所示:

records = es.search(index="my_index",doc_type="marksheet",body={ "aggs": { "student_name": { "terms": { "field": "name.raw","order": { "total_score" : "desc" } }, "aggs": { "total_score": { "sum": { "field": "score" } } } } } } )

这个查询完全正常,就像我需要它一样,大多数时候。但有时,由于原因未知,同样的查询会返回非常大或非常小的结果,例如: 1.4e-322

我无法找到一个正确的理由来解释为什么会发生这种情况。真的很感激有人可以帮我解决这个问题。谢谢!

更新:

运行以下聚合后:

{"aggs":{"score_stats":{"stats":{"field":"score"}}}}

我在聚合键中得到结果:

{u'score_stats': {u'count': 1186, u'max': 5e-323, u'sum': 4.5187e-320, u'avg': 4e-323, u'min': 2e-323}}

更新2:

运行查询后如下:

curl -XGET localhost:9200/my_index/marksheet/_search?_source=score&size=100&pretty&filter_p‌​ath=hits.hits.score

输出中的命中键如下:

"hits" : [ {
  "_index" : "my_index",
  "_type" : "marksheet",
  "_id" : "AU61alGT0VlANyomm3HT",
  "_score" : 1.0,
  "_source":{"score":10}
}, {
  "_index" : "my_index",
  "_type" : "marksheet",
  "_id" : "AU61alGV0VlANyomm3HV",
  "_score" : 1.0,
  "_source":{"score":10}
}, {
  "_index" : "my_index",
  "_type" : "marksheet",
  "_id" : "AU61alGa0VlANyomm3Ha",
  "_score" : 1.0,
  "_source":{"score":8}
}, {
  "_index" : "my_index",
  "_type" : "marksheet",
  "_id" : "AU61alGf0VlANyomm3Hh",
  "_score" : 1.0,
  "_source":{"score":8}
}, {
  "_index" : "my_index",
  "_type" : "marksheet",
  "_id" : "AU61alGk0VlANyomm3Hn",
  "_score" : 1.0,
  "_source":{"score":6}
}, {
  "_index" : "my_index",
  "_type" : "marksheet",
  "_id" : "AU61alGp0VlANyomm3Hu",
  "_score" : 1.0,
  "_source":{"score":10}
}, {
  "_index" : "my_index",
  "_type" : "marksheet",
  "_id" : "AU61alGu0VlANyomm3H0",
  "_score" : 1.0,
  "_source":{"score":10}
}, {
  "_index" : "my_index",
  "_type" : "marksheet",
  "_id" : "AU61alGz0VlANyomm3H7",
  "_score" : 1.0,
  "_source":{"score":10}
}, {
  "_index" : "my_index",
  "_type" : "marksheet",
  "_id" : "AU61alHA0VlANyomm3IN",
  "_score" : 1.0,
  "_source":{"score":8}
}, {
  "_index" : "my_index",
  "_type" : "marksheet",
  "_id" : "AU61alHD0VlANyomm3IR",
  "_score" : 1.0,
  "_source":{"score":10}
},
...

0 个答案:

没有答案