Created
December 28, 2019 18:22
-
-
Save kartikpuri95/118b36f926a8c0f0d6402646ea6aa654 to your computer and use it in GitHub Desktop.
Add class and save index
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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