Python Elasticsearch - ошибка во время --populate - PullRequest
0 голосов
/ 13 апреля 2020

Может ли кто-нибудь помочь мне разобраться в этой ошибке ниже?

Имя и версия вашей операционной системы:

ES Docker

Любые подробности о ваши локальные настройки, которые могут быть полезны при устранении неполадок:

  1. asticsearch == 6.3.1
  2. asticsearch-dsl == 6.1.0
  3. django -elasticsearch -dsl == 0.5.1

Подробные шаги для воспроизведения ошибки:

Ошибка

Lib: https://github.com/sabricot/django-elasticsearch-dsl

Код: documents.py

from elasticsearch_dsl import analyzer, tokenizer
from django.utils.html import format_html
from django.db.models.query import QuerySet

from apps.comprasnet.models import PregaoItens, PregaoWeb, UasgWeb, Modalidade, TermoHomologacao


pregaoitens = Index('pregaoitens')
pregaoitens.settings(
    number_of_shards=1,
    number_of_replicas=0
)


@pregaoitens.doc_type
class IndexPregaoItens(DocType):

    licitacao = fields.ObjectField(properties={
        'licitacao_id': fields.TextField(),
    })

    uasg = fields.ObjectField(properties={
        'co_uasg': fields.IntegerField(),
        'uf': fields.TextField(),
    })

    modalidade = fields.ObjectField(properties={
        'codigo': fields.IntegerField(),
    })

    # index.map.totalfields.limit
    termo = fields.ObjectField(properties={
        'id': fields.TextField(),
    })

    descricao = fields.TextField(
        fields={
            'raw': fields.KeywordField(),
            'suggest': fields.CompletionField()
        },
        fielddata=True,
        analyzer='keyword'
    )

    html_strip = analyzer(
        'html_strip',
        tokenizer="whitespace",
        filter=["lowercase", "snowball", "stemmer", "asciifolding", "trim"],
        char_filter=["html_strip"]
    )

    descricao_comp = fields.TextField(
        analyzer="standard",
        fields={
            'raw': fields.KeywordField(),
            'suggest': fields.CompletionField()
        }
    )

    uasg_name = fields.TextField(
        analyzer=html_strip,
        fields={'raw': fields.KeywordField()}
    )

    uf = fields.TextField(fielddata=True)

    valor_estimado = fields.FloatField()
    lance_per = fields.FloatField()
    desconto_nego = fields.FloatField()
    lance_real = fields.FloatField()
    valor_nego = fields.FloatField()
    valor_equalizado = fields.FloatField()
    valor_total = fields.FloatField()
    bec_proposta_valor = fields.FloatField()

    unidade_id = fields.TextField(fielddata=True)

    class Meta:
        model = PregaoItens
        related_models = [PregaoWeb, UasgWeb, Modalidade, TermoHomologacao]
        fields = [
            'id',
            'nu_pregao',
            'modalidade_desc',
            'objeto',
            'dt_entrega_proposta',
            'dt_abertura_proposta',
            'dt_homologacao',
            'download_link',
            'nu_item',
            'tipo',
            'prgcod',
            'grupo',
            'quant',
            'unidade',
            'situacao',
            'fornecedor',
            'fornecedor_cnpj',
            'srp',
            'base',
            'cliente',
            'generico',
            'codigo_br',
            'fabricante',
            'marca',
            'modelo',
            'resultadopfid',
            'licitacoese_id',
            'nome_unidade',
            'licitacao_id_bec',
            'processo_bec',
            'pregao_eletronico_bec',
            'bec_preco_id',
            'bec_grupo',
            'part_number'
        ]

    queryset_pagination = 2000

    def _get_actions(self, object_list, action):
        if self._doc_type.queryset_pagination and isinstance(object_list, QuerySet):
            pks = object_list.order_by('pk').values_list('pk', flat=True)
            len_pks = len(pks)
            for start_pk_index in range(0, len_pks, self._doc_type.queryset_pagination + 1):
                end_pk_index = start_pk_index + self._doc_type.queryset_pagination
                if end_pk_index >= len_pks:
                    end_pk_index = len_pks - 1
                ranged_qs = object_list.filter(pk__range=[
                    pks[start_pk_index],
                    pks[end_pk_index]
                ])
                for object_instance in ranged_qs:
                    yield self._prepare_action(object_instance, action)
        else:
            yield from super()._get_actions(object_list, action)

    def get_instances_from_related(self, related_instance):
        return related_instance.pregaoitens_set.all()

    def prepare_pregaoweb(self, licitacao_id):
        if licitacao_id is PregaoWeb:
            return {
                'licitacao': licitacao_id
            }

    def prepare_uasgweb(self, co_uasg):
        if co_uasg is UasgWeb:
            return {
                'uasg': co_uasg
            }

    def prepare_modalidade(self, codigo):
        if codigo is Modalidade:
            return {
                'modalidade': codigo
            }

    def prepare_termohomologacao(self, licitacao_id):
        if licitacao_id is TermoHomologacao:
            return {
                'termo': licitacao_id
            }

    def get_valor_final(self):
        if self.valor_total:
            if self.valor_total < 0.01:
                return 0.01
            else:
                return self.valor_total
        return 0.0

    def get_srp(self):
        if self.srp:
            return 'Sim'
        else:
            return 'Não'

    def get_link_ata(self):
        if self.base == 'ComprasNet':
            return format_html(
                '<a class="btn btn-xs btn-default btn-rounded" '
                'href="http://comprasnet.gov.br/livre/pregao/AtaEletronico.asp?'
                'co_no_uasg=%s&&uasg=%s&numprp=%s" target="_blank">Ata</a>' % (
                    self.uasg.co_uasg, self.uasg.co_uasg, self.nu_pregao))

    def get_edital(self):
        return format_html(
            '<a class="btn btn-xs btn-default btn-rounded" '
            'href="%s" target="_blank">Edital</a>' % self.download_link)

    def get_anexos(self):
        return format_html(
            '<a class="btn btn-xs btn-default btn-rounded" '
            'href="http://comprasnet.gov.br/livre/pregao/AnexosProposta.asp?'
            'uasg=%s&numprp=%s&prgcod=%s" target="_blank">Anexos</a>' % (
                self.uasg.co_uasg, self.nu_pregao, self.prgcod))

    def get_termo_link(self):
        return format_html(
            '<a class="btn btn-xs btn-default btn-rounded" '
            'href="http://comprasnet.gov.br/livre/pregao/termohom.asp?'
            'prgcod=%s&co_no_uasg=%s&numprp=%s" target="_blank">Termo de Homologação</a>' % (
                self.prgcod, self.uasg.co_uasg, self.nu_pregao))

    def get_termo_adjudicacao_link(self):
        return format_html(
            '<a class="btn btn-xs btn-default btn-rounded" '
            'href="http://comprasnet.gov.br/livre/pregao/termojulg.asp?prgcod=%s&Acao=A&co_no_uasg=%s&numprp=%s'
            '&f_lstSrp=&f_Uf=&f_numPrp=&f_coduasg=&f_tpPregao=&f_lstICMS=&f_dtAberturaIni=&f_dtAberturaFim=" '
            'target="_blank">Termo de Adjudicação</a>' % (
                self.resultadopfid, self.uasg.co_uasg, self.nu_pregao))

    def get_resultado_por_fornecedor_link(self):
        return format_html(
            '<a class="btn btn-xs btn-default btn-rounded" '
            'href="http://comprasnet.gov.br/livre/pregao/FornecedorResultado.asp?prgcod=%s&strTipoPregao=E" '
            'target="_blank">Resultado por Fornecedor</a>' % (
                self.resultadopfid))

    def get_proposta_inicial(self):
        if self.base == 'ComprasNet':
            if self.srp:
                return self.valor_estimado
            else:
                return self.valor_estimado / self.quant
        elif self.base == 'BEC':
            # print(Proposta.objects.filter(licitante=self.fornecedor).filter(preco=self.bec_preco_id).get())
            # return float(0)
            if self.bec_proposta_valor is not None:
                return self.bec_proposta_valor

            return None

Говорит всем, кто может помочь. :)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...