Error at updating ES index using JS API

Basically I have this function:

   this.es.update({
                index: 'contentman',
                type: 'sites',
                id: "_id",
                body: {
                  name: form.value.name,
                  description: form.value.description,
                  url: form.value.url,
                  author: form.value.author,
                  data_altered: new Date().toLocaleString()
                }
              }).then((hits) => {
              console.log(hits);
              alert('Site Editado, veja o log para mais informações');
              this.siteEdited(true);

Using a function that add things to the index, it all occurs as expected:

 addToIndex(value): any {
    return this.client.index(value);
  }

But when I use an update ES function:

update(value): any {
    return this.client.update(value);
  }

My console returns a POST error:

RACE: 2019-05-09T11:39:24Z
  -> POST http://localhost:9200/contentman/sites/id/_update
  {
    "name": "nomeAtualizado...",
    "description": "",
    "data_altered": "09/05/2019 08:39:24"
  }
  <- 400
  {
    "error": {
      "root_cause": [
        {
          "type": "action_request_validation_exception",
          "reason": "Validation Failed: 1: script or doc is missing;"
        }
      ],
      "type": "action_request_validation_exception",
      "reason": "Validation Failed: 1: script or doc is missing;"
    },
    "status": 400
  }

Fixed it by adding the doc tag inside body

 this.es.update({
            index: 'contentman',
            type: 'sites',
            id: _id,
            body: {
              doc:{
                name: form.value.name,
                description: form.value.description,
                url: form.value.url,
                author: form.value.author,
                data_altered: new Date().toLocaleString()
              }
            }
          }).then((hits) => {
          console.log(hits);
          alert('Site Editado, veja o log para mais informações');
          this.siteEdited(true);
1 Like

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