Get the number of fields on an index

Fairy picture Fairy · Nov 14, 2016 · Viewed 12k times · Source

For optimization purposes, I am trying to cut down my total field count. However before I am going to do that I want to get an idea of how many fields I actually have. There doesn't seem to be any Information in the _stats endpoint and I can't quite figure out how the migration tool does its field count calculation.

Is there some way, either with an endpoint or by other means, to get the total field count of a specified index?

Answer

Val picture Val · Nov 17, 2016

To build a bit further upon what the other answer provided, you can get the mapping and then simply count the number of times the keyword type appears in the output, which gives the number of fields since each field needs a type:

curl -s -XGET localhost:9200/index/_mapping?pretty | grep type | wc -l