2012-12-06 26 views
8

Bir dizinde _timestamp özelliğini tanımlamayı denedim.Elasticsearch _timestamp

{"ok":true,"acknowledged":true} sonra bir _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" 
     } 
    } 
    } 
}' 

ile eşlemesi tanımlamaya çalıştı ve ben den cevap olarak alırsınız: Yani ilk ben indeksi sunucusundan

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

yanıtı oluşturmak sunucu

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

Haritalarımın nesi yanlış? Böyle _ttl ve _timestamp olarak

cevap

16

Özel alanlar properties nesne olarak aynı seviyede tanımlanması adres:

: _timestamp üst düzeyde tanımlanır rağmen fields içine iade edilecektir olsa
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

Not

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'un fields=_timestamp veya fields=_timestamp,_source tarafından açıkça talep edilmesi gerektiğini unutmayın.

Not: _timestamp yalnızca bu alan 'store': true olarak işaretlendiğinde döndürülebilir.

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

sonuç verir:

{ 
    "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 ] 
    } ] 
    } 
} 

Ve şimdi sort[0] ilk değeridir (ve bu durumda tek Ama böyle _timestamp göre sıralama bu değeri erişmek için bir yol vardır) sıralama değeri: _timestamp. Bu şekilde kullanıldığında _timestamp'un "store": true olarak işaretlenmesi gerekmez.

+0

Uzun zamandır, dizinimdeki "_timestamp" ayarlarının yanlış olduğunu veya belgelerimin bu alana geri gelmemesi nedeniyle bir şey olduğunu düşündüm. Notu yazdığınız için teşekkür ederiz. '_timestamp' '' fields = _timestamp 'veya' fields = _timestamp, _source 'tarafından açıkça talep edilmesi gerektiğini unutmayın. Bu gerçekten bana yardımcı oldu! –

+0

@JesseWebb: Rica ederim! –