처음에는 색인 생성을 설정해야합니다. Elasticsearch는 기본값이 좋지만 제공된 값이 타임 스탬프, 정수 또는 문자열인지 여부를 판별하는 것은 불가능합니다. 그래서 당신의 일은 Elasticsearch에게 같은 것에 대해 말해야합니다.
예를 들어 설명하겠습니다. 다음 문서를 색인하려고하는 것입니다 고려하자 : 당신이 인덱스가없는 그래서 처음에
{
"@version": "1",
"@timestamp": "2014-07-04T13:13:35.372Z",
"type": "automatic",
"installer_version": "0.3.0",
"log_type": "access.log",
"user_id": "1",
"event_timestamp": "1404474613",
"run_id": "9"
}
을하고 색인과 같이 HTTP 요청함으로써 문서 :
POST /test/date_experiments
{
"@version": "1",
"@timestamp": "2014-07-04T13:13:35.372Z",
"type": "automatic",
"installer_version": "0.3.0",
"log_type": "access.log",
"user_id": "1",
"event_timestamp": "1404474613",
"run_id": "9"
}
이를 test
이라는 새 색인과 test
이라는 이라는 색인에 새 문서 유형을 만듭니다.
GET /test/date_experiments/_mapping
그리고 당신이 결과에서 얻을 것은 Elasticsearch에 의해 생성 된 자동 생성 매핑 :
{
"test": {
"date_experiments": {
"properties": {
"@timestamp": {
"type": "date",
"format": "dateOptionalTime"
},
"@version": {
"type": "string"
},
"event_timestamp": {
"type": "string"
},
"installer_version": {
"type": "string"
},
"log_type": {
"type": "string"
},
"run_id": {
"type": "string"
},
"type": {
"type": "string"
},
"user_id": {
"type": "string"
}
}
}
}
}
을
당신은 그렇게하여이 문서 유형 date_experiments
의 매핑을 확인하실 수 있습니다
event_timestamp
필드 형식이 string
으로 설정되어 있는지 확인하십시오. 그래서 date_histogram
이 작동하지 않습니다. @timestamp
필드의 유형은 이미 date
입니다. 왜냐하면 Elasticsearch가 귀하의 의도를 쉽게 알 수있는 표준 형식으로 날짜를 푸시했기 때문입니다. 그 필드에서 날짜를 푸시하는 것이 었습니다.
/test/date_experiments
에 DELETE
요청을 전송하여이 매핑을 삭제하고 처음부터 시작할 수 있습니다.
이번에는 문서를 먼저 푸시하는 대신 Google의 요구 사항에 따라 매핑하여 event_timestamp
필드를 날짜로 간주합니다.내가 date
에 event_timestamp
필드의 유형을 변경 한
PUT /test/date_experiments/_mapping
{
"date_experiments": {
"properties": {
"@timestamp": {
"type": "date"
},
"@version": {
"type": "string"
},
"event_timestamp": {
"type": "date"
},
"installer_version": {
"type": "string"
},
"log_type": {
"type": "string"
},
"run_id": {
"type": "string"
},
"type": {
"type": "string"
},
"user_id": {
"type": "string"
}
}
}
}
주의 사항 :
는 다음 HTTP 요청을합니다. Elasticsearch는 날짜를 입력 한
@timestamp
필드의 경우와 같이 몇 가지 표준 형식을 잘 알고 있기 때문에 형식을 지정하지 않았습니다. 이 경우 Elasticsearch는 UNIX 타임 스탬프를 푸시하고 내부적으로 변환하여 날짜로 처리하고 모든 날짜 연산을 허용하려고한다는 것을 이해할 수 있습니다. 밀고있는 날짜가 표준 형식이 아닌 경우 매핑에 날짜 형식을 지정할 수 있습니다.
이제 문서 인덱싱을 시작하고 이전과 같은 방법으로 날짜 쿼리와 패싯을 실행할 수 있습니다.
mapping 및 date format에 대해 자세히 알아보십시오.