Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

microsecond 단위 date도 사용 가능한지? #24

Closed
higee opened this issue Jul 4, 2018 · 0 comments
Closed

microsecond 단위 date도 사용 가능한지? #24

higee opened this issue Jul 4, 2018 · 0 comments

Comments

@higee
Copy link
Owner

higee commented Jul 4, 2018

입력은 가능하나 sorting 등은 사용할 수 없다


elasticsearch 6.2에서 사용 가능한 date type의 format

  • 자세히 보면 단위가 millisecond까지인 걸 확인할 수 있다
  • 그렇다면 millisecond 이하 microsecond 등의 format은 사용할 수 없는걸까?
  • 예를 들어 2018-07-05 04:24:56.170243를 색인한다고 하자

방법1

  • mapping
PUT default-format
{
  "mappings": {
    "_doc": {
      "properties": {
        "@timestamp" : {
          "type" : "date"
        }
      }
    }
  }
}
  • indexing
POST default-format/_doc
{
  "@timestamp" : "2018-07-05 04:24:56.170243"
}
  • result : format error가 발생하여 색인이 되지 않는다
{
  "error": {
    "root_cause": [
      {
        "type": "mapper_parsing_exception",
        "reason": "failed to parse [@timestamp]"
      }
    ],
    "type": "mapper_parsing_exception",
    "reason": "failed to parse [@timestamp]",
    "caused_by": {
      "type": "illegal_argument_exception",
      "reason": "Invalid format: \"2018-07-05 04:24:56.170243\" is malformed at \" 04:24:56.170243\""
    }
  },
  "status": 400
}

방법2

  • mapping
PUT customized-format
{
  "mappings": {
    "_doc": {
      "properties": {
        "@timestamp" : {
          "type" : "date",
          "format" : "yyyy-MM-dd HH:mm:ss.SSSSSS"
        }
      }
    }
  }
}
  • indexing
POST customized-format/_doc
{
  "@timestamp" : "2018-07-05 04:24:56.170243"
}
  • result : 색인이 잘 된다
{
  "_index": "customized-format",
  "_type": "_doc",
  "_id": "55TFZmQByNsCKuKnb22Y",
  "_version": 1,
  "result": "created",
  "_shards": {
    "total": 2,
    "successful": 1,
    "failed": 0
  },
  "_seq_no": 0,
  "_primary_term": 1
}

주의할 점

  • elasticsearch는 기본적으로 millisecond 단위까지만 제공한다
  • 그러므로 위의 방법2와 같이 하면 색인은 되나 microsecond 단위로 비교하기는 어렵다
  • 예시 : 아래와 같은 Documents 2개를 색인하자
POST customized-format/_doc
{
  "@timestamp" : "2018-07-05 04:24:56.170243"
}

POST customized-format/_doc
{
  "@timestamp" : "2018-07-05 04:24:56.170244"
}
  • 검증

    • Kibana : millisecond 이하로는 구분할 수 없어 2개의 Document를 시간순으로 정렬할 수 없다
       
    screen shot 2018-07-05 at 4 37 09 am  
    • Elasticsearch : sort를 해도 millisecond 이하로는 대소를 비교할 수 없다
       
      • query
         
      GET customized-format/_search
      {
        "query": {
          "match_all": {
          }
        },
        "sort": [
          {
            "@timestamp": {
              "order": "desc"
            }
          }
        ]
      }
      
      • result : Document 2개의 sort 값이 같은 걸 확인할 수 있다
         
      {
        "took": 0,
        "timed_out": false,
        "_shards": {
          "total": 5,
          "successful": 5,
          "skipped": 0,
          "failed": 0
        },
        "hits": {
          "total": 2,
          "max_score": null,
          "hits": [
            {
              "_index": "customized-format",
              "_type": "_doc",
              "_id": "CZTJZmQByNsCKuKnu25J",
              "_score": null,
              "_source": {
                "@timestamp": "2018-07-05 04:24:56.170244"
              },
              "sort": [
                1530764696170
              ]
            },
            {
              "_index": "customized-format",
              "_type": "_doc",
              "_id": "B5TJZmQByNsCKuKnsG6f",
              "_score": null,
              "_source": {
                "@timestamp": "2018-07-05 04:24:56.170243"
              },
              "sort": [
                1530764696170
              ]
            }
          ]
        }
      }
      

Source

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant