Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Get OpenSearch mapping with Python
Laysa Uchoa
Laysa Uchoa

Posted on

     

Get OpenSearch mapping with Python

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 calledget_mapping as shown:

importpprintINDEX_NAME='epicurious-recipes'mapping_data=os_client.indices.get_mapping(INDEX_NAME)# Find index doc_typedoc_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)
Enter fullscreen modeExit fullscreen mode

You should be able to see the fields's output:

['calories','categories','date','desc','directions','fat','ingredients','protein','rating','sodium','title']
Enter fullscreen modeExit fullscreen mode

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'}}
Enter fullscreen modeExit fullscreen mode

Read more about OpenSearch mapping in theofficial OpenSearch documentation.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

grateful for helpful compiler messages. Working as Cloud Engineer at Nordcloud.
  • Location
    Munich, Germany
  • Joined

More fromLaysa Uchoa

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp