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?
The first answer by Val solves the problem for me too. But I just wanted to list out some corner cases which can lead to misleading numbers.
For example
This will match
grep type
thrice while it should do that only twice i.e. it should not match "content_type". This scenario has an easy fix.Instead of
Use
to get an exact match of '"type"'
For example
In this case also the match is thrice instead of twice. But using
is not going to cut it. We will have to skip fields with the "type" keyword as substring as well as an exact match. In this case we can add an additional filter like so:
In addition to the above 2 scenarios, if you are using the api programmatically to push numbers for tracking i.e. into something like AWS cloudwatch or Graphite, you can use the following code to call the API - get the data, and recursively search for the keyword "type" - while skipping any fuzzy matches and resolving deeper into fields with the exact name "type".
The above code is also posted as a gist here - https://gist.github.com/saurabh-hirani/e8cbc96844307a41ff4bc8aa8ebd7459
You can try this:
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:Just a quick way to get a relative estimate in Kibana without writing a script (I don't believe this is 100% precise, but it's an easy way to tell if your dynamic fields are blowing up to huge numbers for some reason).
Run this query in the Kibana dev tools
GET /index_name/_mapping
Inside the Kibana output, perform a search for all instances of
"type"
(including quotes). This will count the instances and get you the answer. (In this example, 804)This can be helpful if you scratching your head as to why you're getting the
[remote_transport_exception]
error ofLimit of total fields [1000] in index [index_name] has been exceeded
A field can have more than one "type": e.g.
We can ignore "type" within "fields" to get exact field count. One example is:
You can get that information with the
_mapping
endpoint of the index API, see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.htmlWith curl:
curl [elasticsearch adress]/[index]/_mapping?pretty