elasticsearch: create index with mappings using javascript

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

    Note: this uses client.indices.create() and not client.indices.putMapping()

    I recently succeeded in creating an index with a custom mapping like this:

    client.indices.create({
      index: 'yourIndex',
      body: {
        yourIndex: {
          mappings: {
            yourType: {
              properties: {
                yourText: {
                  type: 'string',
                }
              }
            }
          }
        }
      }
    });
    

    It seems you have to start defining the body with your index, followed by the mappings keyword, followed by your type and so forth. I used the elasticsearch package version 15.4.1 with elastic version 6.5.4

提交回复
热议问题