Returning the timestamp field in elasticsearch

前端 未结 2 1719
一生所求
一生所求 2020-12-31 07:42

Why can I not see the _timestamp field while being able to filter a query by it?

The following query return the correct documents, but not the timestamp itself. How

2条回答
  •  误落风尘
    2020-12-31 08:16

    It is not necessary to store the timestamp field, since its exact value is preserved as a term, which is also more likely to already be present in RAM, especially if you are querying on it. You can access the timestamp via its term using a script_value:

    {
        "query": {
            ...
        },
        "script_fields": {
            "timestamp": {
                "script": "_doc['_timestamp'].value"
            }
        }
    }
    

    The resulting value is expressed in miliseconds since UNIX epoch. It's quite obscene that ElasticSearch can't do this for you, but hey, nothing's perfect.

提交回复
热议问题