elasticsearch: create index with mappings using javascript

后端 未结 5 1607
别那么骄傲
别那么骄傲 2020-12-15 04:25

I\'m trying to create an elasticsearch index with mappings using the official javascript client.

My code is as follows:



        
5条回答
  •  有刺的猬
    2020-12-15 04:32

    Refining the answer that is in the comment above from Sander Spilleman. The "mappings" property needs to be inside the "body" property. I am also using the Javascript client 1.3.0 and the docs are still not updated with an example.

    Adding an example that worked for me with the javascript API provided by elasticsearch on NPM 1.3.0

    var body = {
        tweet:{
            properties:{
                tag         : {"type" : "string", "index" : "not_analyzed"},
                type        : {"type" : "string", "index" : "not_analyzed"},
                namespace   : {"type" : "string", "index" : "not_analyzed"},
                tid         : {"type" : "string", "index" : "not_analyzed"}
            }
        }
    }
    
    client.indices.putMapping({index:"tweets", type:"tweet", body:body});
    

提交回复
热议问题