Return the most recent record from ElasticSearch index

后端 未结 8 1606
执笔经年
执笔经年 2020-12-13 23:01

I would like to return the most recent record (top 1) from ElasticSearch index similar to the sql query below;

SELECT         


        
8条回答
  •  别那么骄傲
    2020-12-13 23:49

    For information purpose, _timestamp is now deprecated since 2.0.0-beta2. Use date type in your mapping.

    A simple date mapping JSON from date datatype doc:

    {
      "mappings": {
         "my_type": {
            "properties": {
              "date": {
              "type": "date" 
            }
          }
        }
      }
    }
    

    You can also add a format field in date:

    {
      "mappings": {
        "my_type": {
          "properties": {
            "date": {
              "type":   "date",
              "format": "yyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis"
            }
          }
        }
      }
    }
    

提交回复
热议问题