Elasticsearch returns null values in response of an aggregation query

时间:2017-06-12 16:58:28

标签: elasticsearch

I have an index with a single type and I want to run some aggregation queries on it; the mapping is here:

{
                "settings": {
                    "index":   {
                        "number_of_shards": 1,
                        "number_of_replicas": 2
                    }
                },
                "mappings": {
                    "v1":   {
                        "_all": {"enabled": false},
                        "properties": {
                            "@timestamp": {
                                "type": "date",
                                "format":  "strict_date_optional_time||epoch_millis",
                                "index": true

                            },
                            "processingTime":       {"type": "long", "index": false},
                            "batchSize":            {"type": "long", "index": false},
                            "general": {
                                "type": "nested",
                                "properties": {
                                    "total":        {"type": "long"},
                                    "migrated":     {"type": "long"},
                                    "joined":       {"type": "long"},
                                    "registered":   {"type": "long"}
                                }
                            },
                            "scoped": {
                                "type": "nested",
                                "properties": {
                                    "since":        {"type": "long"},
                                    "loggedIn":     {"type": "long"},
                                    "joined":       {"type": "long"},
                                    "registered":   {"type": "long"}
                                 }
                            }
                        }
                    }
                }
            }

Let's see my query; a simple date-histogram query to gather basic stats by minute :

{
    "size": 0,
    "aggs": {
       "x": {
            "date_histogram":{
               "field":    "@timestamp",
               "interval": "minute"
            },
            "aggs": {
                "stat-x": { "stats": {"field": "general.registered"}}
            }
        }
    }
}

But when I run my query (the above one) I get null values as aggregated stats that I can't understand why!:

{
    "_shards": {
        "failed": 0,
        "successful": 1,
        "total": 1
    },
    "aggregations": {
        "general": {
            "doc_count": 2,
            "max-x": {
                "avg": null,
                "count": 0,
                "max": null,
                "min": null,
                "sum": null
            }
        }
    },
    "hits": {
        "hits": [],
        "max_score": 0.0,
        "total": 2
    },
    "timed_out": false,
    "took": 18
}

I don't have any idea why it's not working! mapping, types and query seem to be correct! Can anyone help me!

1 个答案:

答案 0 :(得分:0)

问题在于一般范围架构/映射的定义;它们应该 Inner Objects ,但我已将它们定义为 Netsted Object ;然后弹性不能索引它们!