【问题标题】:Elastic search model gem (rails), add new field to mapping弹性搜索模型 gem (rails),向映射添加新字段
【发布时间】:2016-04-24 11:08:29
【问题描述】:

以下是更新 Elastic 搜索映射的 API

PUT twitter/_mapping/tweet 
{
 "properties": {
   "user_name": {
    "type": "string"
   }
  }
 }

这会向推文映射类型添加一个名为 user_name 的新字段。 如何使用弹性搜索模型 gem 来实现这一点 https://github.com/elastic/elasticsearch-rails/tree/master/elasticsearch-model

【问题讨论】:

    标签: ruby-on-rails elasticsearch


    【解决方案1】:

    您可以为此目的使用 put_mapping API。

    对于您的情况,以下应该有效。

    client = Elasticsearch::Model.client
    
    data = { "tweet" => { "properties" => { "user_name" => { "type" => "string" } } } }
    
    client.indices.put_mapping(
    {
     index: 'twitter',
     type: 'tweet',
     body: data 
    })
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-08
    相关资源
    最近更新 更多