1

当我尝试使用 express 更新 elasticJS 上的索引时,我遇到了这个奇怪的错误:

router.put('/update/:id', async (req, res) => {
  try {
    console.log('Entered updateuser', req.params.id);
    const salt = await bcrypt.genSalt(10);
    let password = await bcrypt.hash(req.body.password, salt);

    const data = {
      email: req.body.email,
      firstName: req.body.firstName,
      lastName: req.body.lastName,
      phone: req.body.phone,
      password
    };

    await client.update({
      index: 'users',
      type: 'mytype',
      id: req.params.id,
      body: data
    });
    res.json({ msg: 'Updated Successfully' });
  } catch (err) {
    // res.status(500).send(err.message);
    console.log(err);
  }
});

我检查了所有参数,但出现错误:

use the endpoint /{index}/_update/{id} instead."' ],

[0]      meta:
[0]       { context: null,
[0]         request: [Object],
[0]         name: 'elasticsearch-js',
[0]         connection: [Object],
[0]         attempts: 0,
[0]         aborted: false } } }
[0] Entered updateuser GIt7NW0BKLEzmnN0prT2
[0] { ResponseError: x_content_parse_exception
[0]         request: [Object],
[0]         name: 'elasticsearch-js',
[0]         connection: [Object],
[0]         attempts: 0,
[0]         aborted: false } } }

有谁知道什么问题?

4

1 回答 1

5

如果您想使用updateapi 并更新文档的一部分,您必须将更改包装在doc.

await client.update({
  index: 'users',
  type: 'mytype',
  id: req.params.id,
  body: { 
     doc: data // <===
  }
});

更新文档的一部分

于 2020-08-23T16:29:05.443 回答