elasticsearch_dsl.exceptions.IllegalOperation

来源:14-12 scrapy写入数据到elasticsearch中 - 1

慕移动5647440

2018-07-10

http://img.mukewang.com/szimg/5b4426c50001af2812381454.jpg

elasticsearch_dsl.exceptions.IllegalOperation: Index object cannot have multiple types, doc already set, trying to assign article

写回答

3回答

慕婉清7334940

2018-09-02

https://pypi.org/project/elasticsearch-dsl/5.1.0/

1
0

lihsing

2018-12-18

我安装的是Elasticsearch 6.x,看了文档6.x就不支持一个Index有多个DocType了,所以不能这么建。如果是Elaticsearch 6.x的话,正确的方法是这样的:

from elasticsearch_dsl.analysis import CustomAnalyzer
from elasticsearch_dsl import (Document, Completion, Text, Date, Keyword, Integer)


class IKMaxWordAnalyzer(CustomAnalyzer):
    def get_analysis_definition(self):
        return {}


ik_max_word_analyzer = IKMaxWordAnalyzer('ik_max_word', filter=['lowercase'])


class ArticleType(Document):
    suggest = Completion(analyzer=ik_max_word_analyzer)
    title = Text(analyzer='ik_max_word')
    create_date = Date()
    url = Keyword()
    url_object_id = Keyword()
    front_image_url = Keyword()
    front_image_path = Keyword()
    praise_nums = Integer()
    comment_nums = Integer()
    fav_nums = Integer()
    tags = Text(analyzer='ik_max_word')
    content = Text(analyzer='ik_max_word')

    class Index:
        name = 'jobbole_article'
        settings = {
            'number_of_shards': 1,
            'number_of_replicas': 1
        }


if __name__ == '__main__':
    from elasticsearch_dsl.connections import connections
    connections.create_connection(hosts=['127.0.0.1'])
    ArticleType.init()


0
0

mingliangzhu

2018-07-11

兄弟,你搞定没?

0
3
慕移动5647440
elasticsearch 5.2.0 elasticsearch-dsl 5.1.0
2018-07-11
共3条回复

Scrapy打造搜索引擎 畅销4年的Python分布式爬虫课

带你彻底掌握Scrapy,用Django+Elasticsearch搭建搜索引擎

5795 学习 · 6290 问题

查看课程