| endpoint | field_caps |
|---|---|
| lang | python |
| es_version | 9.3 |
| client | elasticsearch==9.3.0 |
Use client.field_caps() to discover the capabilities of fields
across one or more indices. This is useful for building dynamic
queries when the mapping is not known in advance:
response = client.field_caps(
index="products",
fields=["price", "category", "name"],
)
for field, info in response["fields"].items():
for field_type, caps in info.items():
print(f"{field} ({field_type}): "
f"searchable={caps['searchable']}, "
f"aggregatable={caps['aggregatable']}")Use * to discover all fields, or a prefix pattern to match a
subset:
response = client.field_caps(index="products", fields=["*"])
for field, info in response["fields"].items():
types = list(info.keys())
print(f"{field}: {types}")A common use case is filtering to only fields that support aggregations:
response = client.field_caps(index="products", fields=["*"])
for field, info in response["fields"].items():
for field_type, caps in info.items():
if caps["aggregatable"]:
print(f"{field} ({field_type})")