Elasticsearch에서 내 인덱스 "records"및 유형 "records".이 인덱스 유형에는 일부 문서가 포함됩니다. 인덱스 유형 매핑의 구조
"mappings": {
"records": {
"date_detection": false,
"properties": {
"dateModified": {
"format": "dd/mm/yyyy",
"type": "date"
},
"org": {
"type": "string"
}
}
}
}
내 문서는
{
"org": "pm",
"dateModified": "01/12/2015"
},
{
"org": "muthuraj",
"dateModified": "10/01/2013"
},
{
"org": "user",
"dateModified": "12/05/2015"
},
{
"org": "satish",
"dateModified": "2/05/2014"
}
문서 dateModified> "02/05/2013"을 가져 오는 쿼리를 작성합니다.
{
"query": {
"bool": {
"must": [
{
"range": {
"records.dateModified": {
"gt": "02/05/2013"
}
}
}
]
}
}
}
{
"took": 14,
"timed_out": false,
"_shards": {
"total": 2,
"successful": 2,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 1,
"hits": [
{
"_index": "records",
"_type": "records",
"_id": "NXD8t3TSQxev2WMcNTdchQ",
"_score": 1,
"_source": {
"org": "pm",
"dateModified": "01/12/2015"
}
}
,
{
"_index": "records",
"_type": "records",
"_id": "vyxdivH8RLujCFSNWMQTdg",
"_score": 1,
"_source": {
"org": "muthuraj",
"dateModified": "10/01/2013"
}
}
,
{
"_index": "records",
"_type": "records",
"_id": "QqDTULhwSqOGykYCOOrcHw",
"_score": 1,
"_source": {
"org": "user",
"dateModified": "12/05/2015"
}
}
,
{
"_index": "records",
"_type": "records",
"_id": "btPGMDPgRPimNgLHK2y2OA",
"_score": 1,
"_source": {
"org": "satish",
"dateModified": "2/05/2014"
}
}
]
}
}
"dateModified": "10/01/2013"이것은 "2/05/2015"보다 작지만 결과가 이렇게 나오는 이유이기도합니다. 이 문제를 해결하는 방법
문제는 "format": "dd/mm/yyyy"
입니다. ES mm
는 분을 의미 한다고 생각 하므로 MM
. ES의 날짜 형식이 약간 혼란스럽고 문서화가 잘되어 있지 않다는 사실을 항상 발견했지만 매우 강력합니다. 이 참조를 살펴볼 수 있습니다 .
질문의 두 번째 버전을 사용하여 다음과 같은 색인을 설정할 수 있습니다.
DELETE /test_index
PUT /test_index
{
"settings": {
"number_of_shards": 1
},
"mappings": {
"records": {
"date_detection": false,
"properties": {
"dateModified": {
"format": "dd/MM/yyyy",
"type": "date"
},
"org": {
"type": "string"
}
}
}
}
}
POST /test_index/records/_bulk
{"index":{"_id":1}}
{"org": "pm","dateModified": "01/12/2015"}
{"index":{"_id":2}}
{"org": "muthuraj","dateModified": "10/01/2013"}
{"index":{"_id":3}}
{"org": "user","dateModified": "12/05/2015"}
{"index":{"_id":4}}
{"org": "satish","dateModified": "2/05/2014"}
그러면 쿼리가 예상대로 작동합니다.
POST /test_index/_search
{
"query": {
"bool": {
"must": [
{
"range": {
"records.dateModified": {
"gt": "02/05/2013"
}
}
}
]
}
}
}
...
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"failed": 0
},
"hits": {
"total": 3,
"max_score": 1,
"hits": [
{
"_index": "test_index",
"_type": "records",
"_id": "1",
"_score": 1,
"_source": {
"org": "pm",
"dateModified": "01/12/2015"
}
},
{
"_index": "test_index",
"_type": "records",
"_id": "3",
"_score": 1,
"_source": {
"org": "user",
"dateModified": "12/05/2015"
}
},
{
"_index": "test_index",
"_type": "records",
"_id": "4",
"_score": 1,
"_source": {
"org": "satish",
"dateModified": "2/05/2014"
}
}
]
}
}
코드는 다음과 같습니다.
http://sense.qbox.io/gist/24e468f010ef9323e5974b1e0534c755cb097cfd
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다