首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不同类型Mapper的Django弹性搜索DSL TransportError

不同类型Mapper的Django弹性搜索DSL TransportError
EN

Stack Overflow用户
提问于 2018-11-14 06:34:16
回答 1查看 193关注 0票数 0

我正在使用Python3.6、Django(2.1)、ElasticSearch(5.1.1)和Elasticsearch-dsl(5.4.0)进行一个项目,其中我需要实现搜索功能。

以下是我尝试过的:

:models.py:

代码语言:javascript
复制
class searchdatamodel(models.Model):
    id = models.IntegerField(null=False, primary_key=True)
    company_name = models.TextField(blank=True, null=True)
    city = models.TextField(blank=True, null=True)
    state = models.TextField(blank=True, null=True)
    zip_codes = models.TextField(blank=True, null=True)
    street_address = models.TextField(blank=True, null=True)
    street_address_zip = models.TextField(blank=True, null=True)
    county = models.TextField(blank=True, null=True)
    phone_number = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    fax_number = models.DecimalField(max_digits=65535, decimal_places=65535, blank=True, null=True)
    web_address = models.TextField(blank=True, null=True)
    last_name = models.TextField(blank=True, null=True)
    first_name = models.TextField(blank=True, null=True)
    contact_title = models.TextField(blank=True, null=True)
    contact_gender = models.TextField(blank=True, null=True)
    actual_employee_size = models.IntegerField(blank=True, null=True)
    employee_size_range = models.TextField(blank=True, null=True)
    actual_sales_volume = models.IntegerField(blank=True, null=True)
    sales_volume_range = models.TextField(blank=True, null=True)
    primary_sic = models.IntegerField(blank=True, null=True)
    primary_sic_description = models.TextField(blank=True, null=True)
    secondary_sic_1 = models.IntegerField(blank=True, null=True)
    secondary_sic_description_1 = models.TextField(blank=True, null=True)
    secondary_sic_2 = models.IntegerField(blank=True, null=True)
    secondary_sic_description_2 = models.TextField(blank=True, null=True)
    credit_alpha_score = models.TextField(blank=True, null=True)
    credit_numeric_score = models.IntegerField(blank=True, null=True)
    headquarters_branch = models.TextField(blank=True, null=True)
    square_footage = models.TextField(blank=True, null=True)
    registry_date = models.IntegerField(blank=True, null=True)

    class Meta:
        managed = False
        db_table = 'searchdatamodel'

    # Implement indexing for SearchDataModel model
    def indexing(self):
        SearchDataIndex.init()
        obj = SearchDataIndex(
            id=self.id,
            company_name=self.company_name,
            city=self.city,
            state=self.state,
            zip_code=self.zip_codes,
            street_address=self.street_address,
            street_address_zip=self.street_address_zip,
            county=self.county,
            phone_number=self.phone_number,
            fax_number=self.fax_number,
            web_address=self.web_address,
            last_name=self.last_name,
            first_name=self.first_name,
            contact_title=self.contact_title,
            contact_gender=self.contact_gender,
            actual_employee_size=self.actual_employee_size,
            actual_sales_volume=self.actual_sales_volume,
            primary_sic=self.primary_sic,
            primary_sic_description=self.primary_sic_description,
            registry_date=self.registry_date
        )
        obj.save()
        return obj.to_dict(include_meta=True)

:serach.py:

代码语言:javascript
复制
class SearchDataIndex(DocType):
    id = Integer()
    company_name = Text()
    city = Text()
    state = Text()
    zip_codes = Text()
    street_address = Text()
    street_address_zip = Integer()
    county = Text()
    phone_number = Text()
    fax_number = Text()
    web_address = Text()
    last_name = Text()
    first_name = Text()
    contact_title = Text()
    contact_gender = Text()
    actual_employee_size = Integer()
    actual_sales_volume = Text()
    primary_sic = Text()
    primary_sic_description = Text()
    registry_date = Date()

    class Meta:
        index = 'data-search'

    # A method for bulk indexing
    def bulk_indexing():
        SearchDataIndex.init()
        es = Elasticsearch()
        bulk(client=es, actions=(b.indexing() for b in
                        models.searchdatamodel.objects.all().iterator()))

当我尝试运行bulk_indexing函数时,它返回一个错误,如下所示:

文件"/Users/abdul/PycharmProjects/Dmitry/DVirEnv/lib/python3.6/site-packages/elasticsearch/connection/base.py",第125行,在_raise_error raise HTTP_EXCEPTIONS.get(status_code,TransportError)(status_code,error_message,additional_info)中 elasticsearch.exceptions.RequestError: TransportError(400,“非法_参数_异常”,“不同类型的映射器zip_codes,current_type整数,merged_type文本”)

我尝试过在模型中将zip_code类型更改为IntegerField,但没有成功。

这里有什么问题吗?

提前感谢!

EN

回答 1

Stack Overflow用户

发布于 2019-01-06 11:14:21

不幸的是,你不能就这样改变类型。您必须重新映射索引,它只是简单地删除索引,然后再次运行映射函数。

若要删除索引,请运行

代码语言:javascript
复制
es = Elasticsearch()
es.indices.delete(index='data-search')

然后通过再次运行大容量索引器来映射索引。

注意:任何现有的数据都将维护旧的数据类型,所以如果您需要保存数据但更改数据类型,那么这是一个完全不同的蠕虫,包括创建一个新版本的索引,并将旧数据读入其中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53294354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档