gpt4 book ai didi

node.js - 如何使用node.js lib更新Elasticsearch中的项目?

转载 作者:行者123 更新时间:2023-12-03 02:24:40 24 4
gpt4 key购买 nike

每次更新对我来说都是失败的。我不确定自己在做什么错:

    await search
.update({
index: 'posts',
id: post._id,
body: post,
})
.catch(err => {
failed.updates += 1;
console.log('update failed', post._id);
});

这是插入文档的方式:
    await search
.index({
index: 'posts',
id: post._id,
body: post,
})
.catch(err => {
failed.inserts += 1;
console.error(err);
});

插入工作完美无缺。我想知道默认情况下更新是否会失败?不知道为什么,但他们都失败了。

这是错误:

{
"name": "ResponseError",
"meta": {
"body": {
"error": {
"root_cause": [
{
"type": "x_content_parse_exception",
"reason": "[1:2] [UpdateRequest] unknown field [score]"
}
],
"type": "x_content_parse_exception",
"reason": "[1:2] [UpdateRequest] unknown field [score]"
},
"status": 400
},
"statusCode": 400,
"headers": {
"content-type": "application/json; charset=UTF-8",
"content-length": "221"
},
"warnings": null,
"meta": {
"context": null,
"request": {
"params": {
"method": "POST",
"path": "/posts/_update/5ea1947ebbb15d001c408c4d",
"body": "{\"score\":2,\"views\":21,\"type\":\"link\",\"ranking\":2.7183885087703956,\"sponsored\":false,\"title\":\"Why a âreturn to normalâ could mean disaster for the stock market - MarketWatch\",\"url\":\"https://www.marketwatch.com/story/why-a-return-to-normal-could-mean-disaster-for-the-stock-market-2020-04-22\",\"thumb\":\"https://s.marketwatch.com/public/resources/images/MW-IE973_corona_ZH_20200422114239.jpg\",\"author\":{\"karma\":3910,\"subscriptions\":[\"5e4dad2e5a6930001d9bad99\",\"5e9a298303c86d001c8cf584\",\"5e9aae5d03c86d001c8cf5b9\",\"5e9aa4d703c86d001c8cf5b4\",\"5e622896def3ed002821b9bf\",\"5e507210bdbc8100286fbeee\",\"5e4e3a4d5a6930001d9badb0\",\"5e9da81bd0ff32001c5fd0b9\",\"5e9eecf3ef8abb001ddc2696\"],\"username\":\"marcolanz\",\"created\":\"2020-03-23T03:27:46.936Z\",\"bitcoinAddress\":\"1EsBjmHakFkTnRxxcsB8M1hNHdUnyLg2w7\",\"links\":[],\"id\":\"5e782cb248f8c00027f14f10\"},\"category\":{\"subscriberCount\":2,\"nsfw\":false,\"_id\":\"5e9eecf3ef8abb001ddc2696\",\"name\":\"StockMarket\",\"description\":\"Stock market\",\"owner\":\"5e782cb248f8c00027f14f10\",\"created\":\"2020-04-21T12:54:11.398Z\",\"__v\":0},\"votes\":[{\"user\":\"5e782cb248f8c00027f14f10\",\"vote\":1},{\"user\":\"5e92618ba33715001c54530b\",\"vote\":1}],\"comments\":[],\"created\":\"2020-04-23T13:13:34.989Z\",\"text\":null,\"upvotePercentage\":100,\"commentCount\":0,\"id\":\"5ea1947ebbb15d001c408c4d\"}",
"querystring": "",
"headers": {
"User-Agent": "elasticsearch-js/7.6.1 (linux 4.15.0-96-generic-x64; Node.js v12.16.2)",
"Content-Type": "application/json",
"Content-Length": "1278"
},
"timeout": 30000
},
"options": {
"warnings": null
},
"id": 33
},
"name": "elasticsearch-js",
"connection": {
"url": "http://es01:9200/",
"id": "http://es01:9200/",
"headers": {},
"deadCount": 0,
"resurrectTimeout": 0,
"_openRequests": 1,
"status": "alive",
"roles": {
"master": true,
"data": true,
"ingest": true,
"ml": false
}
},
"attempts": 0,
"aborted": false
}
}
}


这是输入:
  {
score: 2,
views: 21,
type: 'link',
ranking: 2.7183885087703956,
sponsored: false,
_id: 5ea1947ebbb15d001c408c4d,
title: 'Why a âreturn to normalâ could mean disaster for the stock market - MarketWatch',
url: 'https://www.marketwatch.com/story/why-a-return-to-normal-could-mean-disaster-for-the-stock-market-2020-04-22',
thumb: 'https://s.marketwatch.com/public/resources/images/MW-IE973_corona_ZH_20200422114239.jpg',
author: {
karma: 3910,
subscriptions: [
5e4dad2e5a6930001d9bad99,
5e9a298303c86d001c8cf584,
5e9aae5d03c86d001c8cf5b9,
5e9aa4d703c86d001c8cf5b4,
5e622896def3ed002821b9bf,
5e507210bdbc8100286fbeee,
5e4e3a4d5a6930001d9badb0,
5e9da81bd0ff32001c5fd0b9,
5e9eecf3ef8abb001ddc2696
],
_id: 5e782cb248f8c00027f14f10,
username: 'marcolanz',
password: '$2a$10$qDEn46Qr0uGr0pGDP5FWO.aD411ARsOdVJpgzevWAgz1XR0tUW6kK',
created: 2020-03-23T03:27:46.936Z,
__v: 0,
ip: '201.21.39.32',
bitcoinAddress: '1EsBjmHakFkTnRxxcsB8M1hNHdUnyLg2w7',
links: []
},
category: {
subscriberCount: 2,
nsfw: false,
_id: 5e9eecf3ef8abb001ddc2696,
name: 'StockMarket',
description: 'Stock market',
owner: 5e782cb248f8c00027f14f10,
created: 2020-04-21T12:54:11.398Z,
__v: 0
},
votes: [
{ user: 5e782cb248f8c00027f14f10, vote: 1 },
{ user: 5e92618ba33715001c54530b, vote: 1 }
],
comments: [],
created: 2020-04-23T13:13:34.989Z,
text: null
}

最佳答案

    await search
.update({
index: 'posts',
id: post._id,
body: { doc: post }, // this is the fix, wrap in "doc"
})
.catch(err => {
failed.updates += 1;
console.log('update failed', post._id);
});

关于node.js - 如何使用node.js lib更新Elasticsearch中的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61379686/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com