Date Histogram Display like "1 hour ago", "2 days ago", etc

Hello,

I've got no experience writing "script" in ElasticSearch. I have a
datehistogram facets and it's giving me the facet values as long int.

Using "script", is there a way to return the following facet values?

30 minutes ago
1 hour ago
5 hours ago
1 day ago
6 days ago
1 month ago

Can this be done using the script parameter?

Thanks so much!

Raul

Hi Raul

I've got no experience writing "script" in Elasticsearch. I have a
datehistogram facets and it's giving me the facet values as long int.

Using "script", is there a way to return the following facet values?

30 minutes ago
1 hour ago
5 hours ago
1 day ago
6 days ago
1 month ago

Can this be done using the script parameter?

The best way to do this would be to use a range facet, and to pass it a
separate range for each of the periods you list above:

clint

Hi Clint,

Thanks for the insights. Yes, I realized that range is the appropriate
facet type for this solution and create a decoration at application
level to say if its 30 minutes, 1 day, 1 week etc.

I'm taking the idea from the sample query in the documentaton (http://
Elasticsearch Platform — Find real-time answers at scale | Elastic)
{
"query" : {
"match_all" : {}
},
"facets" : {
"range1" : {
"range" : {
"key_script" : "doc['date'].date.minuteOfHour",
"value_script" : "doc['num1'].value",
"ranges" : [
{ "to" : 50 },
{ "from" : 20, "to" : 70 },
{ "from" : 70, "to" : 120 },
{ "from" : 150 }
]
}
}
}
}

Thanks
Raul

On Jul 14, 11:06 pm, Clinton Gormley clin...@iannounce.co.uk wrote:

Hi Raul

I've got no experience writing "script" in Elasticsearch. I have a
datehistogram facets and it's giving me the facet values as long int.

Using "script", is there a way to return the following facet values?

30 minutes ago
1 hour ago
5 hours ago
1 day ago
6 days ago
1 month ago

Can this be done using the script parameter?

The best way to do this would be to use a range facet, and to pass it a
separate range for each of the periods you list above:

Elasticsearch Platform — Find real-time answers at scale | Elastic...

clint

Hi Clint,

Well, I respond too quickly. I'm not really comprehending the
key_script and value_script and what value should I be using for these
two parameters..

Would it be okay if you can provide an example for this? Appreciated.

Thanks,
raul

On Jul 14, 11:43 pm, rmartinez jun...@gmail.com wrote:

Hi Clint,

Thanks for the insights. Yes, I realized that range is the appropriate
facet type for this solution and create a decoration at application
level to say if its 30 minutes, 1 day, 1 week etc.

I'm taking the idea from the sample query in the documentaton (Elasticsearch Platform — Find real-time answers at scale | Elastic)
{
"query" : {
"match_all" : {}
},
"facets" : {
"range1" : {
"range" : {
"key_script" : "doc['date'].date.minuteOfHour",
"value_script" : "doc['num1'].value",
"ranges" : [
{ "to" : 50 },
{ "from" : 20, "to" : 70 },
{ "from" : 70, "to" : 120 },
{ "from" : 150 }
]
}
}
}

}

Thanks
Raul

On Jul 14, 11:06 pm, Clinton Gormley clin...@iannounce.co.uk wrote:

Hi Raul

I've got no experience writing "script" in Elasticsearch. I have a
datehistogram facets and it's giving me the facet values as long int.

Using "script", is there a way to return the following facet values?

30 minutes ago
1 hour ago
5 hours ago
1 day ago
6 days ago
1 month ago

Can this be done using the script parameter?

The best way to do this would be to use a range facet, and to pass it a
separate range for each of the periods you list above:

Elasticsearch Platform — Find real-time answers at scale | Elastic...

clint

Hi Raul

Well, I respond too quickly. I'm not really comprehending the
key_script and value_script and what value should I be using for these
two parameters..

I'd just provide the datetime values from my app, so:

curl -XGET 'http://127.0.0.1:9200/_search?pretty=1' -d '
{
"facets" : {
"my_range" : {
"range" : {
"created" : [
{ "from" : "2011-07-14 12:00:00" },
{
"to" : "2011-07-14 12:00:00",
"from" : "2011-07-14 11:00:00"
}
,
{ etc }
]
}
}
},
"size" : 0
}
'

alternatively, you can use milliseconds since the epoch time, eg:

1310661229000 == Thu Jul 14 16:33:45 2011 GMT

so 30 mins before that would be:
1310661229000 - (30 * 60 * 1000)

etc

Thanks Clint,

The use of milliseconds works for me.

Here's what I came up with (some PHP code!)

On Jul 15, 12:35 am, Clinton Gormley clin...@iannounce.co.uk wrote:

Hi Raul

Well, I respond too quickly. I'm not really comprehending the
key_script and value_script and what value should I be using for these
two parameters..

I'd just provide the datetime values from my app, so:

curl -XGET 'http://127.0.0.1:9200/_search?pretty=1' -d '
{
"facets" : {
"my_range" : {
"range" : {
"created" : [
{ "from" : "2011-07-14 12:00:00" },
{
"to" : "2011-07-14 12:00:00",
"from" : "2011-07-14 11:00:00"
}
,
{ etc }
]
}
}
},
"size" : 0}

'

alternatively, you can use milliseconds since the epoch time, eg:

1310661229000 == Thu Jul 14 16:33:45 2011 GMT

so 30 mins before that would be:
1310661229000 - (30 * 60 * 1000)

etc