1
votes

I am trying to get the date parsed into a string format as month and numerical year format like "JAN, 92". My mapping is as below:

size" => 0,
      "query" => {
        "bool" => {
         "must" => [
            {
              "term" => {
                "checkin_progress_for" => {
                 "value" => "Goal"
                }
              }
            },
            {
             "term" => {
               "goal_owner_id" => {
                 "value" => "#{current_user.access_key}"
               }
             }
           }
          ]
        }
      },
      "aggregations" => {
        "chekins_over_time"  => {
          "range" => {
            "field" => "checkin_at",
            "format" => "MMM, YY",
            "ranges" => [
              {
                "from" => "now-6M",
                "to" => "now"
              }
            ]
          },
          "aggs"  => {
            "checkins_monthly" => {
              "date_histogram" => {
                "field" => "checkin_at",
                "format" => "MMM, YY",
                "interval" => "month",
                "min_doc_count" => 0,
                "missing" => 0,
                "extended_bounds"  => {
                  "min"  => "now-6M",
                  "max"  => "now"
                }
              }
            }
          }
        }
      }
    }

I throws the following error:

elasticsearch.transport.RemoteTransportException: [captia-america][127.0.0.1:9300][indices:data/read/search[phase/query]] Caused by: elasticsearch.ElasticsearchParseException: failed to parse date field [0] with format [MMM, YY]

If I remove the {MMM, YY} and put the normal date format it works. What could the solution to rectify this.Help appreciated.

1
This is your query, but not yet your mapping. Please post the definition of checkin_at. - drjz

1 Answers

0
votes

Your checkins_monthly aggregation is a bit wrong. The missing part should have the same format for the date to use when the field is missing. A 0 is not actually a date.

For example:

  "aggs": {
    "checkins_monthly": {
      "date_histogram": {
        "field": "checkin_at",
        "format": "MMM, YY",
        "interval": "month",
        "min_doc_count": 0,
        "missing": "Jan, 17",
        "extended_bounds": {
          "min": "now-6M",
          "max": "now"
        }
      }
    }