简体   繁体   中英

elasticsearch js update an index

Hi guys I have an index which I want to update a part of using elastic search js

for example: I have this index:

{
        "_index" : "users",
        "_type" : "j_users",
        "_id" : "CpmE0G0BteODhj-lZNPP",
        "_score" : 1.0,
        "_source" : {
          "email" : "alex@walla.co.il",
          "firstName" : "aa",
          "lastName" : "aa",
          "confirmed" : false,

        }

and I wish to change only the "confirmed" field to true, how do I do that?

await client.update({
      index: "users",
      id: "CpmE0G0BteODhj-lZNPP",
      body: {
        confirmed: true
      }
    });

I tried this according to the documentation but I get an error, can anyone tell me whats wrong with my syntax?

Try this:

await client.update({
      index: "users",
      type : "j_users" 
      id: "CpmE0G0BteODhj-lZNPP",
      body: {
        doc: {
        confirmed: true
      }
     }
    });

you can also try to add

 doc_as_upsert: true

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