2016-07-27 103 views
1

我正在處理一個ElasticSearch查詢,該查詢應該讓我回到所有文檔現在是1年前的日期字段,然後按月對它們進行分組(每個月給我總數),但是我沒有寫這個查詢。按月分組的ElasticSearch聚合信息

這是我有:

{ 
    "query": { 
    "bool": { 
     "must": [ 
     { 
      "terms": { 
      "account_id": [ 
       1 
      ] 
      } 
     } 
     ] 
    } 
    }, 
    "aggs": { 
    "growth": { 
     "date_range": { 
     "field": "member_since", 
     "format": "YYYY-MM-DD", 
     "ranges": [ 
      { 
      "to": "now-1Y/M" 
      }, 
      { 
      "from": "now-1Y/M" 
      } 
     ] 
     } 
    } 
    }, 
    "size": 100 
} 

我運行像這樣的查詢:

POST https://my-es-cluster-url.com,但我不斷收到此錯誤:

{ 
    "error": { 
    "root_cause": [ 
     { 
     "type": "parse_exception", 
     "reason": "unit [Y] not supported for date math [-1Y/M]" 
     } 
    ], 
    "type": "search_phase_execution_exception", 
    "reason": "all shards failed", 
    "phase": "query_fetch", 
    "grouped": true, 
    "failed_shards": [ 
     { 
     "shard": 0, 
     "index": "index0", 
     "node": "MkypXlGdQamAplca1JIgZQ", 
     "reason": { 
      "type": "parse_exception", 
      "reason": "unit [Y] not supported for date math [-1Y/M]" 
     } 
     } 
    ] 
    }, 
    "status": 400 
} 
+0

:因此,你應該嘗試使用? – Ibrahim

回答

1

我複製你的問題更簡單的查詢我的數據。

"query": { 
    "range": { 
     "recent_buy_transaction": { 
      "from": "now-1Y" 
     } 
    } 
} 

我得到了同樣的錯誤。

ElasticSearchParseException[unit [Y] not supported for date math [-1Y]]

然而,使用小ý解決該問題。您正在使用哪個ES版本

now-1y/M

documentation

The supported time units are: y (year), M (month), w (week), d (day), h (hour), m (minute), and s (second).