Dates

When a group of related items are indexed, by default they are stored in elasticsearch in a dated index, for example “relateditems-YYYY-MM-DD”:

Each date based index, is an index of it’s own in elasticsearch. If you were searching directly against elasticsearch you could independently search the one dated index.

The date of the index is based on the UTC date of either:

  • The date contained within the RELATED ITEMS POST (converted to UTC)
  • The current date set on the server on which the indexing application is running.

The previous POST contained no date. However, the following example POST contains a date that is in UTC timezone. As an index named ”relateditems-2013-12-25” will be created and the 4 related item documents indexed within that index.

{
    "channel": "de", 
    "date": "2013-12-25T09:44:41.943", 
    "items": [
        {
            "id": "1", 
            "type": "map"
        }, 
        {
            "id": "2", 
            "type": "compass"
        }, 
        {
            "id": "3", 
            "type": "torch"
        }, 
        {
            "channel": "uk", 
            "id": "4", 
            "type": "torch"
        }
    ], 
    "site": "amazon"
}

As mentioned above, if the date in the related items POST contains a date with time zone information, it will be converted to UTC, and then the date used. For example, the below POST contains:

"date": "2013-12-24T09:44:41.943+10:00"

Given this date, the 4 related item documents will be indexed within the index named:

relateditems-2013-12-23

The reason being that “2013-12-24T09:44:41.943+10:00” is “2013-12-23T23:44:41.943” in UTC timezone. The resulting 4 related documents will contain the UTC timestamp.

{
    "channel": "de", 
    "date": "2013-12-24T09:44:41.943+10:00", 
    "items": [
        {
            "id": "1", 
            "type": "map"
        }, 
        {
            "id": "2", 
            "type": "compass"
        }, 
        {
            "id": "3", 
            "type": "torch"
        }, 
        {
            "channel": "uk", 
            "id": "4", 
            "type": "torch"
        }
    ], 
    "site": "amazon"
}

An example document indexed in ”relateditems-2013-12-23” looks as follows (taken from elasticsearch head):

{
    _index: relateditems-2013-12-23
    _type: related
    _id: EmHW1qQBQv2BMgmQAlyMiA
    _version: 1
    _score: 1
    _source: {
        id: 3
        date: 2013-12-23T23:44:41.943Z
        related-with: [
            4
            1
            2
        ]
        type: torch
        site: amazon
        channel: de
    }
}

The document itself is:

{
    "id": "3" ,
    "date": "2013-12-23T23:44:41.943Z",
    "related-with": [ "4","1","2"],
    "type": "torch",
    "site": "amazon",
    "channel": "de"
}