How do I get a list of all the fields that are present in an index (i.e. fields that occur in indexed documents, not just in the mapping)?
You may use _field_names field. The _field_names field indexes the names of every field in a document that contains any value other than null. Yes, you may only query for the existence of a field but can't aggregate on the same. The get mappings approach will not work if you are using the join functionality.
There are multiple ways to list all of the indexes contained in an Elasticsearch cluster. One common way of doing this is to use cURL and Kibana to issue HTTP requests to communicate with the Elasticsearch cluster to have it return all of the index names and their respective UUIDs.
By default, Elasticsearch indexes all data in every field and each indexed field has a dedicated, optimized data structure. For example, text fields are stored in inverted indices, and numeric and geo fields are stored in BKD trees.
Fields are the smallest individual unit of data in Elasticsearch. These are customizable and could include, for example: title, author, date, summary, team, score, etc. Each field has a defined datatype and contains a single piece of data.
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:
GET
mappingIn current(5.2) version, you can use the mapping API to get all the field names:
GET index_name/_mapping?pretty
please refer to the official document for more information.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With