作者:252575936_8ea84a | 来源:互联网 | 2023-09-08 13:07
我正在将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
});