2016-07-27 11 views
1

Ich arbeite an einer ElasticSearch-Abfrage, die mir alle Dokumente zurückgeben sollte, wo ein Datumsfeld jetzt-1 Jahr ist und gruppieren sie alle nach Monat (geben mir Gesamtanzahl für jeden Monat), aber ich versage beim Schreiben dieser Abfrage.ElasticSearch Aggregat Informationen nach Monat gruppiert

Das ist, was ich habe:

{ 
    "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 
} 

ich die Abfrage wie so leite:

POST https://my-es-cluster-url.com, aber ich halte diesen Fehler:

{ 
    "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

, welche Version von ES verwenden Sie? – Ibrahim

Antwort

1

ich reproduziert Ihr Problem mit eine einfachere Abfrage meiner Daten.

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

Ich bekomme den gleichen Fehler.

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

jedoch mit kleinen y behebt das Problem. Daher sollten Sie verwenden versuchen:

now-1y/M

Vom documentation

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