Skip to content

Instantly share code, notes, and snippets.

@kartikpuri95
Created December 28, 2019 18:22
Show Gist options
  • Save kartikpuri95/118b36f926a8c0f0d6402646ea6aa654 to your computer and use it in GitHub Desktop.
Save kartikpuri95/118b36f926a8c0f0d6402646ea6aa654 to your computer and use it in GitHub Desktop.
Add class and save index
from elasticsearch_dsl import connections,Document,Text,Keyword,Date
from elasticsearch import Elasticsearch
connections.create_connection(hosts=['127.0.0.1'], timeout=20)
es=Elasticsearch()
class Blogpost(Document):
Title=Text()
published_date=Date()
published_by=Text()
tags=Keyword()
body=Text()
class Index:
name='blog_index' #index will be created automatically
bg=Blogpost()
bg.title="A better way to use elasticsearch python"
bg.published_date="12-01-2019"
bg.published_by="Kartik"
bg.tags=['tech','elasticsearch','python']
bg.body="Who does not love object-oriented programming paradigms"
bg.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment