简体   繁体   中英

Elasticsearch Javascript Client Update not working

I am using elasticsearch JavaScript client with nodejs (Typescript). The update query is not working as expected can any one help me on this

My code is

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

And the response is

{
    "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}"
}

My package.json file is

{
  "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"
  }
}

My elastic search version is 6.3

The reason is because you're using a 7.x client against a 6.3 ES cluster.

You just need to configure the client to talk to 6.x clusters using the apiVersion configuration setting , like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM