簡體   English   中英

彈性JS節點JS無法更新索引

[英]Elastic JS node JS unable to update index

我在嘗試使用 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 } } }

有誰知道問題是什么?

如果您想使用update api 並更新文檔的一部分,您必須將更改包裝在doc

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

更新文檔的一部分

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM