2

Is it possible to have a mapping in Elasticsearch with null_value that equals to "now" in a field with type "date"? Something like this:

"mappings": {
  "doc": {
    "properties": {
      "last_updated": {
        "type": "date",
        "format": "yyyy-MM-dd HH:mm:ss",
        "null_value": "now"
      }
    }
  }
}

So when I search the last_updated field will be equal to the current time, if no value exists?

5
  • github.com/elasticsearch/elasticsearch/issues/4718# Commented Oct 31, 2014 at 13:43
  • So it is possible, if I define a timestamp? Commented Oct 31, 2014 at 13:46
  • "_timestamp" is a pre-defined field. You just need to enable it, by default is disabled. And that github issue is against 1.4.0.Beta1, so in a non-GA version of ES. Commented Oct 31, 2014 at 14:10
  • Ok, so this will just add the timestamp when indexed, it will not check current time when searching? Commented Nov 1, 2014 at 10:40
  • _timestamp is deprecated. Commented Aug 6, 2019 at 10:03

1 Answer 1

2

I don't think you can do that. You have to do it when indexing your documents, that's what i do.

from the documentation:

When specifying the mapping for a string, numeric, boolean or date field, you can also set a null_value which will be used whenever an explicit null value is encountered. A field without a value will still be excluded from the inverted index.

When choosing a suitable null_value ensure that:

  • it matches the field’s type. You can’t use a string null_value in a field of type date
  • it is different from the normal values that the field may contain, to avoid confusing real values with null values
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.