elasticsearch: create index with mappings using javascript

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

    None of these examples worked for me on ElasticSearch 5.3 API.

    Here is an example that works for 5.3.

    elasticClient.indices.putMapping({
        index: indexName,
        type: "document",
        body: {
            properties: {
                title: { type: "string" },
                content: { type: "string" },
                suggest: {
                    type: "completion",
                    analyzer: "simple",
                    search_analyzer: "simple",
                    payloads: true
                }
            }
        }
    })
    

    Note that the type has been pulled out of the body, and only the sub-params that were under the type are now in the body.

    Source: https://blog.raananweber.com/2015/11/24/simple-autocomplete-with-elasticsearch-and-node-js/

提交回复
热议问题