Hi,
In the results the _source contains the JSON you provided at index time. If
you want to get the long value of the date, you can use a script_fields :
{
"query": {
"match_all": {}
},
"script_fields": {
"dateAsLong": {
"script": "doc['date'].value"
}
},
"aggs": {
"messages_by_time": {
"date_histogram": {
"field": "date",
"interval": "day"
}
}
}
}
It seems a little odd to me to index a date field as a formatted string and
having to retrieve it as a long because of the framework you use. Maybe I
suggest to try to stick to only one type and look after Jest to convert the
type as needed.
-- Tanguy
Le jeudi 2 octobre 2014 10:35:45 UTC+2, [email protected] a écrit :
>
> Hello there,
>
> My question :
> When I make a search query of indexed element, i want to parse the result
> of date object value into a Java Object. To make that properly, and because
> I use the Jest API, I need that the Json output format to be in Long, and
> not in the formated String way.
> Can I configure the query or the index to get the result in long value (as
> date are stored in long value).
>
> I need to keep the Date Object mapping and not a long one because I use
> some specific aggregation in some query, and it's date, so I want to use
> the date Object...
> The problem don't appear when you use date aggregation like
> date_histogram, because in result, you got the key in both formated way
> (Long and String).
>
> Here an example to detail :
>
> Mapping of the index :
> PUT /testindex/test/_mapping
> {
> "test": {
> "properties": {
> "date": {
> "type": "date",
> "format": "dateOptionalTime"
> }
> }
> }
> }
>
> I use the format to put element.
>
> then I do some search query :
> GET /testindex/test/_search
> {
> "query": {
> "match_all": {}
> }
> }
>
> result are this way :
> {
> "took": 0,
> ...
>
> },
> "hits": {
> ...
> "hits": [
> {
> "_index": "testindex",
> "_type": "test",
> "_id": "...",
> "_score": 1,
> "_source": {
> "date": "2014-09-25T11:24:36",
> }
> }
> ]
> }
> }
>
> but I want a date like "date": 1411509600000.
> After what I will use Jest or other way to get the value and create a Date
> Java Object with the long value.
>
> For instance :
> new
> Date(resultElasticsearch.getJsonObject().get("hits").getAsJsonObject().get("hits").getAsJsonArray().get(0).getAsJsonObject().get("_source").getAsJsonObject().get("date").getAsLong());
>
>
--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/e62b5d15-21f7-4645-9103-0369e34a31e4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.