Skip to content

Latest commit

 

History

History
52 lines (40 loc) · 1.27 KB

File metadata and controls

52 lines (40 loc) · 1.27 KB
endpoint field_caps
lang python
es_version 9.3
client elasticsearch==9.3.0

Elasticsearch 9.3 field_caps endpoint (Python example)

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']}")

Wildcard patterns

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}")

Checking aggregatability

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})")