Skip to content

Create to_elastic method #28895

@kDmartel

Description

@kDmartel

Code Sample, a copy-pastable example if possible

Problem description

Create method to export a pandas dataframe data to elasticsearch json format like to_excel, to_csv, to_sql methods.

Input

df : pandas dataframe
index : str : elasticsearch index
type : str : elasticsearch type
EX :
df.head()
Name Age Weight
0 Kevin 26 94
1 Marc 32 70
2 Louis 35 80

index = 'personnes'

type = 'homme'

Usage

df.to_elastic(file_path, 'index'=index, 'type'=type)

Expected Output

{"index":{"_index": "personnes","_type":"homme","_id":1}}
{"fields" : {"Name" : "Kevin","Age" : 26,"Weight" : 94}
{"index" :{"_index": "personnes","_type":"homme","_id":2}}
{"fields" : {"Name" : "Marx","Age" : 32,"Weight" : 70}
{"index" :{"_index": "personnes","_type":"homme","_id":3}}
{"fields" : {"Name" : "Louis","Age" : 35,"Weight" : 80}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions