2012-12-06 21 views
8

मैंने इंडेक्स पर _timestamp संपत्ति को परिभाषित करने का प्रयास किया। तो सबसे पहले, मैं सूचकांक सर्वर सेElasticsearch _timestamp

curl -XPUT 'http://elasticsearch:9200/ppe/'

प्रतिक्रिया बनाने: {"ok":true,"acknowledged":true}

तो मैं एक _timestamp

curl -Xput 'http://elasticsearch:9200/ppe/log/_mapping' -d '{ 
    "log": { 
    "properties": { 
     "_ttl": { 
     "enabled": true 
     }, 
     "_timestamp": { 
     "enabled": true, 
     "store": "yes" 
     }, 
     "message": { 
     "type": "string", 
     "store": "yes" 
     }, 
     "appid": { 
     "type": "string", 
     "store": "yes" 
     }, 
     "level": { 
     "type": "integer", 
     "store": "yes" 
     }, 
     "logdate": { 
     "type": "date", 
     "format": "date_time_no_millis", 
     "store": "yes" 
     } 
    } 
    } 
}' 

साथ मानचित्रण परिभाषित करने की कोशिश की और मैं से जवाब के रूप में प्राप्त होता है सर्वर

{ 
    "error": "MapperParsingException[No type specified for property [_timestamp]]", 
    "status": 400 
} 

मेरे मैपिंग में क्या गलत है?

ऐसे _ttl और _timestamp रूप

उत्तर

16

विशेष क्षेत्रों properties वस्तु के रूप में एक ही स्तर पर परिभाषित किया जाना है:

curl -Xput 'http://elasticsearch:9200/ppe/log/_mapping' -d '{ 
    "log": { 
     "_ttl": { 
      "enabled": true 
     }, 
     "_timestamp": { 
      "enabled": true, 
      "store": "yes" 
     }, 
     "properties": { 
      "message": { 
       "type": "string", 
       "store": "yes" 
      }, 
      "appid": { 
       "type": "string", 
       "store": "yes" 
      }, 
      "level": { 
       "type": "integer", 
       "store": "yes" 
      }, 
      "logdate": { 
       "type": "date", 
       "format": "date_time_no_millis", 
       "store": "yes" 
      } 
     } 
    } 
} 
' 
3

नोट यद्यपि कि हालांकि _timestamp शीर्ष स्तर पर परिभाषित किया गया है यह fields अंदर वापस कर दी जाएगी:

curl 'http://localhost:9200/myindex/mytype/AUqL0PW7YDMmKSIKO1bk?pretty=true&fields=_timestamp' 
{ 
    "_index" : "myindex", 
    "_type" : "mytype", 
    "_id" : "AUqL0PW7YDMmKSIKO1bk", 
    "_version" : 1, 
    "found" : true, 
    "fields" : { 
    "_timestamp" : 1419684935099 
    } 
} 

ध्यान दें कि _timestamp स्पष्ट रूप से fields=_timestamp या fields=_timestamp,_source द्वारा अनुरोध किया जाना चाहिए।

ध्यान दें कि _timestamp केवल तभी वापस किया जा सकता है जब यह फ़ील्ड 'store': true के रूप में चिह्नित किया गया हो।

curl 'http://localhost:9200/myindex/mytype/_search?pretty=true' -d ' 
    { "sort": [ "_timestamp" ], "size": 1} 
' 

परिणाम देता है::

{ 
    "took" : 1, 
    "timed_out" : false, 
    "_shards" : { 
    "total" : 5, 
    "successful" : 5, 
    "failed" : 0 
    }, 
    "hits" : { 
    "total" : 3, 
    "max_score" : null, 
    "hits" : [ { 
     "_index" : "myindex", 
     "_type" : "mytype", 
     "_id" : "AUqL0PDXYDMmKSIKO1bj", 
     "_score" : null, 
     "sort" : [ 1419684933847 ] 
    } ] 
    } 
} 

और अब sort[0] पहले के लिए मूल्य है (और इस मामले में केवल लेकिन वहाँ _timestamp द्वारा यह मान जब छँटाई पहुंचने का एक तरीका है, इस तरह है) क्रम मूल्य: _timestamp_timestamp को इस तरह से उपयोग किए जाने पर "store": true के रूप में चिह्नित करने की आवश्यकता नहीं है।

+0

मैंने लंबे समय तक सोचा कि इंडेक्स पर मेरी '_imimestamp' सेटिंग्स गलत थीं या कुछ क्योंकि मेरे दस्तावेज़ इस क्षेत्र के साथ वापस नहीं आ रहे थे। नोट बनाने के लिए धन्यवाद "ध्यान दें कि '_timestamp' को 'फ़ील्ड = _timestamp' या 'फ़ील्ड = _timestamp, _source' द्वारा स्पष्ट रूप से अनुरोध किया जाना चाहिए।", यह वास्तव में मेरी मदद करता है! –

+0

@ जेसेवेब: आपका स्वागत है! –