0

ES Version : 7.10.2

I have a requirement to show index statistics, I have come across the index stats API which does fulfill my requirement.

But the issue is I don't necessarily need all the fields for a particular metric.

Ex: curl -XGET "http://localhost:9200/order/_stats/docs"

It shows response as below (omitted for brevity)

"docs" : {
          "count" : 7,
          "deleted" : 0
        }

But I only want "count" not "deleted" field, from this.

So, in Index Stats API documentation, i came across a query param as :

fields:

(Optional, string) Comma-separated list or wildcard expressions of fields to include in the statistics.

Used as the default list unless a specific field list is provided in the completion_fields or fielddata_fields parameters

As per above when I perform curl -XGET "http://localhost:9200/order/_stats/docs?fields=count"

It throws an exception

{
  "error" : {
    "root_cause" : [
      {
        "type" : "illegal_argument_exception",
        "reason" : "request [/order/_stats/docs] contains unrecognized parameter: [fields]"
      }
    ],
    "type" : "illegal_argument_exception",
    "reason" : "request [/order/_stats/docs] contains unrecognized parameter: [fields]"
  },
  "status" : 400
}

Am I understanding the usage of fields correctly ?

If yes/no, how can I achieve the above requirement ?

Any help is much appreciated :)

Nishikant Tayade
  • 483
  • 3
  • 12

1 Answers1

1

You can use the filter_path argument, like:

curl -XGET "http://localhost:9200/order/_stats?filter_path=_all.primaries.docs.count

This will return you only one field like:

{
  "_all" : {
    "primaries" : {
      "docs" : {
        "count" : 10
      }
    }
  }
}
Vakhtang
  • 431
  • 2
  • 9
  • Thanks! This does work, but what does the "fields" mention in the docs for index stats API then used for, could you clarify? – Nishikant Tayade Jun 08 '22 at 13:26
  • Furthermore I am using RESTHighLevelClient which doesn't support filter_paths :( – Nishikant Tayade Jun 08 '22 at 13:33
  • I don't know why the "fields" argument doesn"t work (BTW he doesn't work even if you use it in regular request). You right, sometime, RESTHighLevelClient have the problems with arguments. So in this case i prefere to use Low level client:) This is pretty easy to move between the clients (at least in the Java) – Vakhtang Jun 08 '22 at 19:13
  • Yes, I saw that filter path can be added as param RESTHighLevelClient but not with the ES version I am using, and low level client I can't use, as I am not owner of the code, Thanks though I have up-voted the answer :) – Nishikant Tayade Jun 09 '22 at 04:31