Error updating angular Elasticsearch index

Asked

Viewed 21 times

0

I basically have the following 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);

When using a function that adds to the index everything works correctly:

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

But using the update ES function:

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

The POST returns the following errors in the console:

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
  }

1 answer

0


I managed to solve this problem by putting inside the body the tag doc:

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);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.