When no data structure is specified when loading the data, OpenSearch uses dynamic mapping to automatically detect the fields. To check the mapping definition of your data, OpenSearch client provides a function called get_mapping
as shown:
import pprint INDEX_NAME = 'epicurious-recipes' mapping_data = os_client.indices.get_mapping(INDEX_NAME) # Find index doc_type doc_type = list(mapping_data[INDEX_NAME]["mappings"].keys())[0] schema = mapping_data[INDEX_NAME]["mappings"][doc_type] fields = list(schema.keys()) pprint(fields) pprint(schema)
You should be able to see the fields's output:
['calories', 'categories', 'date', 'desc', 'directions', 'fat', 'ingredients', 'protein', 'rating', 'sodium', 'title']
And the mapping with the fields and their respective types.
{'calories': {'type': 'float'}, 'categories': {'fields': {'keyword': {'ignore_above': 256, 'type': 'keyword'}}, 'type': 'text'}, 'date': {'type': 'date'}, 'desc': {'fields': {'keyword': {'ignore_above': 256, 'type': 'keyword'}}, 'type': 'text'}, 'directions': {'fields': {'keyword': {'ignore_above': 256, 'type': 'keyword'}}, 'type': 'text'}, 'fat': {'type': 'float'}, 'ingredients': {'fields': {'keyword': {'ignore_above': 256, 'type': 'keyword'}}, 'type': 'text'}, 'protein': {'type': 'float'}, 'rating': {'type': 'float'}, 'sodium': {'type': 'float'}, 'title': {'fields': {'keyword': {'ignore_above': 256, 'type': 'keyword'}}, 'type': 'text'}}
Read more about OpenSearch mapping in the official OpenSearch documentation.
Top comments (0)