标签: elasticjs

如何修复我对 Elastic search 的一半请求中的“400 Bad request”?

我正在使用具有单个文档的单个索引的弹性搜索云。我正在使用@elastic/elasticsearch最新版本。我从 Firebase 云函数调用弹性搜索。

这是我的弹性客户端在云函数中的初始化方式

const { Client, errors } = require('@elastic/elasticsearch');
const elasticClient = new Client({
    cloud: {
        id: 'xxxxxxxx',
    },
    auth: {
        username: 'xxxx',
        password: 'xxxxxx'
    },
    maxRetries: 5,
    requestTimeout: 60000,
});
Run Code Online (Sandbox Code Playgroud)

这是查询elasticsearch的云函数

exports.stickerSearch = functions.runWith(runtimeOpts).https.onRequest(async (req, res) => {
    try {
        const searchQuery = req.query.query;
        const searchResult = await elasticClient.search(
            {
                index: "packs",
                from: 0,
                q: searchQuery,
                size: 20,
                sort: 'dataCreatedAt'
            });
        res.status(searchResult.statusCode).send(searchResult.body.hits);
    }
    catch (e) {        
        console.log("search error", e)
        res.status(200).send({ "total": { "value": 0, "relation": …
Run Code Online (Sandbox Code Playgroud)

javascript elasticsearch elasticjs elastic-stack google-cloud-functions

7
推荐指数
0
解决办法
5459
查看次数

弹性JS节点JS无法更新索引

我在尝试使用 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);
  }
});
Run Code Online (Sandbox Code Playgroud)

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

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

[0]      meta:
[0]       { context: null,
[0] …
Run Code Online (Sandbox Code Playgroud)

node.js express elasticjs

1
推荐指数
1
解决办法
909
查看次数