Val's first answer solves the problem for me as well. But I just wanted to list some corner cases that can lead to misleading numbers.
- The document has fields with the word type.
for instance
"content_type" : { "type" : "text", "fields" : { "keyword" : { "type" : "keyword", } } },
This will match the grep type three times, while it should only do it twice, that is, it should not match "content_type". This script is easy to fix.
Instead
curl -s -XGET localhost:9200/index/_mapping?pretty | grep type
using
curl -s -XGET localhost:9200/index/_mapping?pretty | grep '"type"'
to get an exact type match
- The document has a field with the exact name "type"
for instance
"type" : { "type" : "text", "fields" : { "keyword" : { "type" : "keyword" } } },
In this case, also a match three times, and not twice. But using
curl -s -XGET localhost:9200/index/_mapping?pretty | grep '"type"'
not going to cut it. We will need to skip fields with the keyword "type" as a substring, as well as with an exact match. In this case, we can add an additional filter as follows:
curl -s -XGET localhost:9200/index/_mapping?pretty |\ grep '"type"' | grep -v "{"
In addition to the above 2 scenarios, if you use the API to transmit numbers for tracking, that is, something like an AWS or Graphite cloud clock, you can use the following code to call the API - retrieve data and perform a recursive keyword search. "type" - while skipping any fuzzy matches and delving into the fields with the exact name "type".
import sys import json import requests
The above code is also posted here as a hist - https://gist.github.com/saurabh-hirani/e8cbc96844307a41ff4bc8aa8ebd7459