0
votes

I have some documents in an index. my document look like this:

{
  "_index" : "news_collection",
  "_type" : "news",
  "_id" : "54dafbf0e4b0e3cf93676007",
  "_score" : 0.2631625,
  "_source":{"title":"some title","content":"example content"
             ,"publication_date":"Dec 31, 2006 11:11:00 PM"},
 {
  "_index" : "news_collection",
  "_type" : "news",
  "_id" : "54dafbf0e4b0e3cf93676007",
  "_score" : 0.2631625,
  "_source":{"title":"some title","content":"example content"
            ,"publication_date":"Dec 31, 2006 11:11:00 PM"},

I want to group my document in month interval. I tried to do this code:

curl -XPOST 'localhost:9200/news_collection/_search?pretty' -d '
{ 
  "aggs" : {
    "articles_over_time" : {
        "date_histogram" : {
            "field" : "publication_date",
            "interval" : "day",
            "format" : "MMM dd, yyyy h:mm:ss aa" 
        }
    }
  } 
}'

but elastic search get me an error:

 "error" : "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[_6V06L2iS4672onsoOixbA]    [news_collection][0]:   ClassCastException[org.elasticsearch.index.fielddata.plain.PagedBytesIndex     FieldData cannot be cast to  

org.elasticsearch.index.fielddata.IndexNumericFieldData]} ...

I very tried to change date format and field name but not woking.

1
Is publication_date defined as a date in your mapping?Olly Cruickshank
thank you, the problem was in date data type :)mahdi

1 Answers

1
votes

The date format has to be given during indexing and not while searching. You need to define this field as date core type in the schema and then index the documents. After that you can do aggregation on that field. The format specified in the aggregation is the format to which you want the output as and not the field format of already indexed document.