热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

ElasticsearchJavascript客户端更新不起作用

我正在将ElasticsearchJavaScript客户端与nodejs(Typescript)结合使用。更新查询无法

我正在将Elasticsearch Javascript客户端与nodejs(Typescript)结合使用。更新查询无法正常工作

我的代码是

const EsRespOnse= await esClient.update({
index: "myindex",type: "mytype",id: "1",body: {
// put the partial document under the `doc` key
doc: {
title: "Updated"
}
}
});

响应是

{
"msg": "[invalid_type_name_exception] Document mapping type name can't start with '_',found: [_update]","path": "/myindex/_update/1","query": {
"type": "mytype"
},"body": "{\"doc\":{\"title\":\"Updated\"}}","statusCode": 400,"response": "{\"error\":{\"root_cause\":[{\"type\":\"invalid_type_name_exception\",\"reason\":\"Document mapping type name can't start with '_',found: [_update]\"}],\"type\":\"invalid_type_name_exception\",found: [_update]\"},\"status\":400}"
}

我的package.json文件是

{
"name": "backend","version": "1.0.0","description": "The backend system","main": "dist/index.js","scripts": {
"prebuild": "tslint -c tslint.json -p tsconfig.json --fix","build": "tsc","prestart": "npm run build","start": "nodemon .","test": "echo \"Error: no test specified\" && exit 1"
},"author": "Jagadeesh Kumar CK","license": "ISC","dependencies": {
"@types/body-parser": "^1.17.1","@types/cors": "^2.8.6","cors": "^2.8.5","elasticsearch": "^16.5.0","express": "^4.17.1","ts-node": "^8.5.2"
},"devDependencies": {
"@types/elasticsearch": "^5.0.36","@types/express": "^4.17.2","@types/node": "^12.12.12","tslint": "^5.20.1","typescript": "^3.7.2"
}
}

我的弹性搜索版本是6.3



原因是因为您针对6.3 ES群集使用了7.x客户端。

您只需要配置客户端即可使用apiVersion configuration setting与6.x群集进行通信,如下所示:

var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
... other config options ...
"apiVersion": "6.8" <--- add this line
});


推荐阅读
author-avatar
252575936_8ea84a
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有