Elasticsearch--date the use of math in the index

Source: Internet
Author: User

In Elasticsearch, it is sometimes necessary to filter the data for a certain period of time by the index date, and then use the date mathematical expression provided by ES

Describe:

Especially in the log data, just query the log data for a period of time, then you can use the date mathematical expression, which can limit the number of indexes retrieved, reduce the load on the cluster, improve system performance.

Almost all APIs support mathematical parameter values in the date index.

Index based on the mathematical expression of the date:
<static_name{date_math_expr{date_format|time_zone}}>

The meanings of each of these fields are:

Static_name: The static part of the index name

DATE_MATH_EXPR: dynamic Date expression

Date_format: Format, default is YYYY.MM.DD

Time_zone: TimeZone, default is UTC

It is important to note that the index and the part of the date expression are placed inside the <> angle brackets when using.

Examples of date mathematical expressions

For example, the time is now2024年3月22日中午12点.utc

An expression

The value of an expression
<test-{now/d}>

Curl-xpost ' 192.168.204.32:9200/<test-\{now%2fm\}>/type/1?pretty '-d ' {"name": "Xing1", age:20} ' {  "_ Index ":" test-2016.05.01 ","  _type ":" Type ",  " _id ":" 1 ",  " _version ": 1,  " _shards ": {    " total ": 2,< c7/> "Successful": 2,    "failed": 0  },  "created": true}

# curl-xpost ' 192.168.204.42:9200/<test-\{now%2fm\}>/_search?pretty '-d ' {"Query": {"Match_all": {}}} ' {  " Took ": 3,  " Timed_out ": false,  " _shards ": {    " total ": 5,    " successful ": 5,    " failed ": 0  },  " Hits ": {    " total ": 1,    " Max_score ": 1.0,    " hits ": [{      " _index ":" test-2016.05.01 ",      " _type ":" Typ E ",      " _id ":" 1 ",      " _score ": 1.0,      " _source ": {        " name ":" Xing1 ",        " age ": +      }    }]
   
    }}
   

Elasticsearch--date the use of math in the index

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.