简体   繁体   中英

How to return a specific field value in elasticsearch query

I am trying to get a specific filed from a index also the lastest one , ie in desc order For example I have data

 {
"ts" : 1.626294635518096E9
"index" : random
}

I want to return ts: value only , it should be the latest ts value in index

How can i do that I need a query in format that can work in browser like http://ip:port/index_name/_search?q=

Anyone can provide some hints? Thanks

I don't think that you can all your condition requirements in the format of browser search, but in JSON format you can do it as shown below :

You can use source filtering along with sorting the documents using the below query, and with size=1 you will get only the latest document. :

{
    "size": 1,
    "sort": [
        {
            "ts": {
                "order": "desc"
            }
        }
    ],
    "_source": {
        "includes": [
            "ts"
        ]
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM