Problems with entering data using Elasticsearch DSL

I try to use Elasticsearch DSL docs' Persistence Example to input data. ( But it can't run on python3. Code show as below:

from datetime import datetime
from elasticsearch_dsl import Document, Date, Integer, Keyword, Text
from elasticsearch_dsl.connections import connections


class Article(Document):
title = Text(analyzer='snowball', fields={'raw': Keyword()})
body = Text(analyzer='snowball')
tags = Keyword()
published_from = Date()
lines = Integer()

class Index:
    name = 'blog'
    settings = {
      "number_of_shards": 2,

def save(self, ** kwargs):
    self.lines = len(self.body.split())
    return super(Article, self).save(** kwargs)

def is_published(self):
    return >= self.published_from


article = Article(meta={'id': 42}, title='Hello world!', tags=['test'])
article.body = ''' looong text '''
article.published_from =

article = Article.get(id=42)


The error is that ImportError: cannot import name 'Document' from 'elasticsearch_dsl'.
And I try to use DocType to replace Document. The program tells me that ValueError: Empty value passed for a required argument 'index'.
So I change </Article.init()> to </Article.init('blog')>. It also cannot run. It shows that elasticsearch.exceptions.RequestError: RequestError(400, 'mapper_parsing_exception', 'Root mapping definition has unsupported parameters: [doc : {properties={published_from={type=date}, title={analyzer=snowball, fields={raw={type=keyword}}, type=text}, body={analyzer=snowball, type=text}, lines={type=integer}, tags={type=keyword}}}]') .
I want to know how could I deal with this problem?

My system operation is Win10.
Python version: 3.7
Elasticsearch version: 7.1.1

I try to use elasticsearch version 6.8 and elasticsearch_dsl version 6.4.0. The problem is solved. But I still want to use the latest version^_^

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.