【问题标题】:Elastic JS node JS unable to update index弹性JS节点JS无法更新索引
【发布时间】:2019-09-15 16:02:21
【问题描述】:

我在尝试使用 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 } } }

有谁知道问题出在哪里?

【问题讨论】:

  • 发送给elastic的请求体错误。这意味着data 变量中的某些变量丢失或未正确发送
  • @NikosM。好吧,我检查了所有字段,没有任何遗漏..
  • 可能格式错误
  • @NikosM。它们都是字符串,我不认为是,也许我缺少一些参数?
  • 这是错误ResponseError: x_content_parse_exception,快速查找得到:discuss.elastic.co/t/…, github.com/elastic/elasticsearch/issues/30261

标签: node.js express elasticjs


【解决方案1】:

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

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

Update part of a document

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-21
    • 2016-12-09
    • 2019-04-19
    • 2018-05-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-16
    相关资源
    最近更新 更多