elastic / elasticsearch-js

Official Elasticsearch client library for Node.js
https://ela.st/js-client
Apache License 2.0
5.24k stars 727 forks source link

Limit of total fields [1000] has been exceeded #1492

Closed vtr-rivia closed 3 years ago

vtr-rivia commented 3 years ago

🐛 Bug Report

I've tried to insert a document on index using elastic NodeJS library but when I'm trying to index some documents it throws me an error:

{
    "error": {
        "root_cause": [
            {
                "type": "illegal_argument_exception",
                "reason": "Limit of total fields [1000] has been exceeded"
            }
        ],
        "type": "illegal_argument_exception",
        "reason": "Limit of total fields [1000] has been exceeded"
    },
    "status": 400
}

    at Unzip.onBody [as cb] (/opt/nodejs/node_modules/@elastic/elasticsearch/lib/Transport.js:337:23)

To Reproduce

Calling index api like that

const { Client } = require('@elastic/elasticsearch')
const es = new Client({
  cloud: {
    id: process.env.ELASTIC_CLOUD_ID,
  },
  auth: {
    username: 'elastic',
    password: process.env.ELASTIC_CLOUD_PWD
  }
})

exports.insert = async (index, object) => {
  object.createdAt = DateTime.utc().toISO()
  const inserted = await es.index({ index, body: object })
  return _.assign(object, extractId(inserted))
}

Using this object

"declaracaoSaude": {
            "adulto": true,
            "homem": true,
            "imc": "string",
            "doencaCoracao": true,
            "hipertensao": true,
            "anoEventoHipertensao": "string",
            "descricaoHipertensao": "string",
            "angina": true,
            "anoEventoAngina": "string",
            "descricaoAngina": "string",
            "infarto": true,
            "anoEventoInfarto": "string",
            "descricaoInfarto": "string",
            "insuficienciaCardiaca": true,
            "anoEventoInsuficiencia": "string",
            "descricaoInsuficiencia": "string",
            "arritmiaCardiaca": true,
            "anoEventoArritmia": "string",
            "descricaoArritmia": "string",
            "outroCoracao": true,
            "anoEventoOutro": "string",
            "descricaoOutro": "string",
            "diabetes": true,
            "diabetesTipo1": true,
            "diabetesTipo2": true,
            "tireoide": true,
            "hipertireoidismo": true,
            "hipotireoidismo": true,
            "outroTireoide": true,
            "colesterolTriglicerideos": true,
            "respiratorio": true,
            "efisema": true,
            "asma": true,
            "bronquite": true,
            "rinite": true,
            "sinusite": true,
            "desvioSepto": true,
            "outroRespiratorio": true,
            "acidente": true,
            "anoAcidente": "string",
            "descricao": "string",
            "ossos": true,
            "osteoporose": true,
            "herniaDisco": true,
            "artrite": true,
            "artrose": true,
            "outroOsso": true,
            "deformidade": true,
            "digestivo": true,
            "gastrite": true,
            "ulcera": true,
            "colite": true,
            "hemorroidas": true,
            "calculoVesicula": true,
            "outroDigestivo": true,
            "figado": true,
            "hepatite": true,
            "hepatopatia": true,
            "cirrose": true,
            "outroFigado": true,
            "hiv": true,
            "urologica": true,
            "incontinencia": true,
            "hiperplasia": true,
            "calculoRenal": true,
            "fimose": true,
            "outroUrulogica": true,
            "cirurgia": true,
            "ginecologicaMamas": true,
            "mioma": true,
            "cistoOvario": true,
            "endometriose": true,
            "noduloMama": true,
            "outroGinecologicaMama": true,
            "sistemaNervoso": true,
            "epilepsia": true,
            "alzheimer": true,
            "parkinson": true,
            "esclerose": true,
            "avc": true,
            "exaqueca": true,
            "outroSistemaNervoso": true,
            "olhos": true,
            "glaucoma": true,
            "catarata": true,
            "descolamentoRetina": true,
            "estrabismo": true,
            "retinopatia": true,
            "outroOlhos": true,
            "oculos": true,
            "hipermetropia": true,
            "miopia": true,
            "astigmatismo": true,
            "presbiopia": true,
            "simGenerico": true,
            "outro": true,
            "cirurgiaFutura": true,
            "ouvido": true,
            "surdez": true,
            "otites": true,
            "labirintite": true,
            "outroOuvidos": true,
            "sangue": true,
            "anemia": true,
            "talassemia": true,
            "outroSangue": true,
            "psicologico": true,
            "depressao": true,
            "ansiedade": true,
            "fobia": true,
            "esquizofrenia": true,
            "bipolar": true,
            "autoimunes": true,
            "lupus": true,
            "artriteReumatoide": true,
            "escleroseMultipla": true,
            "outroAutoimune": true,
            "cancer": true,
            "hernia": true,
            "umbilical": true,
            "inguinal": true,
            "epigastrica": true,
            "outroHernia": true,
            "varizs": true,
            "tratamentoAtual": true,
            "descricaoTratamento": "string",
            "outroInfo": true,
            "descricaoOutroInfo": "string",
            "orientacaoCredenciado": true,
            "orientacaoPreposto": true,
            "semOrientacao": true,
            "cienciaTermos": true
        }

Here is my index settings

{
  "dev-plano-titular-declaracao-saude" : {
    "settings" : {
      "index" : {
        "routing" : {
          "allocation" : {
            "include" : {
              "_tier_preference" : "data_content"
            }
          }
        },
        "mapping" : {
          "total_fields" : {
            "limit" : "3000"
          }
        },
        "number_of_shards" : "1",
        "blocks" : {
          "read_only_allow_delete" : "false"
        },
        "provided_name" : "dev-plano-titular-declaracao-saude",
        "creation_date" : "1626229379362",
        "number_of_replicas" : "1",
        "uuid" : "JHP3wpTtQ5SdWEeOP984cw",
        "version" : {
          "created" : "7130299"
        }
      }
    }
  }
}

When I use the DevTools on Elastic Cloud it works as expected

Expected behavior

Index document working

Your Environment

delvedor commented 3 years ago

Hello! This is not related to the client, if the Dev Tools are behaving differently it's very likely that you are sending two different documents.

I would recommend to read this guide to understand how to handle this case and also how to handle the mappings.

vtr-rivia commented 3 years ago

Hello! This document that I've pasted as an example I got from my application logs before call index function Then I copied and paste the exactly same document on dev tools and it works