Explanation:
Don’t think there is any way to do exactly that. But since everything in the index automatically gets thrown in the mapping, we know that the mapping contains at least every field in the index. From there, you can loop through each field in the mapping and run a count on the number of results in the index that have that field. If the count is more than 0, then that field exists; if the count is 0, then that field is not part of the index. Since we know that every field in the index will exist in your mapping, this should cover all possibilities.
Some example API calls:
# Get the mapping
$ curl -XGET 'http://localhost:9200/index/type/_mapping?pretty'
# Count a field
$ curl -XGET 'http://localhost:9200/index/type/_count' -d '
{
"query" : {
"constant_score" : {
"filter" : {
"exists" : { "field" : "name_from_mapping" }
}
}
}
}'
Documentation:
GETmapping- count API
- exists filter