Ruby Elasticsearch API: Returning the latest entry to an index -


i've enabled "_timestamp" field in index mapping, , i've confirmed using rest api calls elasticsearch can retrieve latest entry index. post request used confirm is:

{     "query": {         "match_all": {}     },     "size": "1",     "sort": [         {             "_timestamp": {                 "order": "desc"             }         }     ] } 

now i'm trying translate ruby elasticsearch-api syntax... have far:

client = elasticsearch::client.new host: 'blahblahblah:9200' json = client.search index: 'index',                  type: 'type',                 body: { query: { match_all: {} }},                 sort: '_timestamp',                 size: 1 

i've tried several variations on above code, nothing seems return newest entry. can't find many examples online using ruby elasticsearch api syntax, appreciated!

if there way return latest entry without using "_timestamp" field, open trying well!

i found correct syntax:

json = client.search index: 'index',                     type: 'type',                     body: { query: { match_all: {} }, size: 1, sort: [ { _timestamp: { order: "desc"} } ] } 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -