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
Post a Comment