Excluding max value from Data table

Hi,

I am trying to achieve a result set where if there are 10 records, I want only 9 of them. Excluding the one which has maximum id.

For instance, there are 4 docs in my index.

{
  "took" : 2,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 4,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "rank",
        "_type" : "data",
        "_id" : "2",
        "_score" : 1.0,
        "_source" : {
          "id" : 2,
          "name" : "Rank2"
        }
      },
      {
        "_index" : "rank",
        "_type" : "data",
        "_id" : "4",
        "_score" : 1.0,
        "_source" : {
          "id" : 4,
          "name" : "Rank4"
        }
      },
      {
        "_index" : "rank",
        "_type" : "data",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "id" : 1,
          "name" : "Rank1"
        }
      },
      {
        "_index" : "rank",
        "_type" : "data",
        "_id" : "3",
        "_score" : 1.0,
        "_source" : {
          "id" : 3,
          "name" : "Rank3"
        }
      }
    ]
  }
}

Mapping as

{
  "rank" : {
    "mappings" : {
      "data" : {
        "properties" : {
          "id" : {
            "type" : "long"
          },
          "name" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }
      }
    }
  }
}

I want to fetch only last 3 records.

A query something like

GET rank/_search
{
  "from":1,
  "query":{
    "match_all": {}
  },
  "sort": [
    {
      "id": {
        "order": "desc"
      }
    }
  ]
}

Since I am using from:1, it would exclude id:4. I needed the same results in Kibana Data Table. Kindly guide how should I proceed.

Thanks.

Good day, Aditi! Does the size query parameter help?

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html

Hello

Good day to you too :slight_smile:

Not sure if I can use the size parameter since I may not know the maximum number of fields.

For instance, there can be 30 ids, 35 ids and the index may grow. I need a 29ids in my table(30-1) or if the index gets updated with 35 ids, then 34ids. If there is a way to set the "from" parameter in table, it might be helpful.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.