elasticsearch: create index with mappings using javascript

后端 未结 5 1632
别那么骄傲
别那么骄傲 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:54

    I tried same but got error from the name of index. aName is not valid, error was about the using lowercase index name. Then It created with mappings.

    it.only('putMapping', function (done) {
        client.indices.create({
            index: "aname",
            body: {
                "mappings": {
                    "aType": {
                        "properties": {
                            "aProp1": {"type": "string", "index": "not_analyzed"},
                            "aProp2": {"type": "string", "index": "not_analyzed"},
                            "aProp3": {"type": "string", "index": "not_analyzed"},
                            "aProp4": {"type": "string", "index": "not_analyzed"}
                        }
                    }
                }
            }
        }, function (err, resp, respcode) {
            console.log(err, resp, respcode);
        });
    })
    

    Output:

    Elasticsearch DEBUG: 2015-08-08T15:23:09Z
      starting request { method: 'POST',
        path: '/aname',
        body: { mappings: { aType: [Object] } },
        query: {} }
    
    
    Elasticsearch TRACE: 2015-08-08T15:23:10Z
      -> POST http://localhost:9200/aname
      {
        "mappings": {
          "aType": {
            "properties": {
              "aProp1": {
                "type": "string",
                "index": "not_analyzed"
              },
              "aProp2": {
                "type": "string",
                "index": "not_analyzed"
              },
              "aProp3": {
                "type": "string",
                "index": "not_analyzed"
              },
              "aProp4": {
                "type": "string",
                "index": "not_analyzed"
              }
            }
          }
        }
      }
      <- 200
      {
        "acknowledged": true
      }
    

提交回复
热议问题