Bib*_*pal 5 ruby-on-rails elasticsearch
以下是更新弹性搜索映射的API
PUT twitter/_mapping/tweet
{
"properties": {
"user_name": {
"type": "string"
}
}
}
Run Code Online (Sandbox Code Playgroud)
这会将一个名为user_name的新字段添加到tweet映射类型中.如何使用弹性搜索模型来实现这一点宝石 https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model
Pra*_*h R 10
您可以使用put_mapping API来实现此目的.
对于您的情况,以下应该有效.
client = Elasticsearch::Model.client
data = { "tweet" => { "properties" => { "user_name" => { "type" => "string" } } } }
client.indices.put_mapping(
{
index: 'twitter',
type: 'tweet',
body: data
})
Run Code Online (Sandbox Code Playgroud)