我正在使用带有nodejs(Typescript(的elasticsearch JavaScript客户端。更新查询未按预期工作,任何人都可以帮助我解决这个问题
我的代码是
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","reason":"Document mapping type name can't start with '_', 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
配置设置将客户端配置为与 6.x 群集通信,如下所示:
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
... other config options ...
"apiVersion": "6.8" <--- add this line
});