[ElasticSearch] mappings and type

http://www.cnblogs.com/buzzlight/p/elasticsearch_mapping_fields.html

require 'elasticsearch'

$client = Elasticsearch::Client.new hosts:['127.0.0.1'],randomize_hosts:true

def create_index
    $client.indices.create index:'weibo',body:{
         settings: {
          index: {
            number_of_shards: 10,
            number_of_replicas: 1
          }
        },
        mappings: {
          weibo: {
            _all: {
              analyzer: "ik_max_word",
              search_analyzer: "ik_max_word",
            },
            properties: {
              content: { type: 'string', analyzer: 'ik_max_word',  search_analyzer: 'ik_max_word' },
              tags: { type: 'string', index: "not_analyzed" },
              site_user: { type: 'string', index: 'not_analyzed' },
              created_time: { type: 'integer' },
              created_date: { type: 'string', index: 'not_analyzed' },
            }
          }
        },
        blog:{
            _all:{
                analyzer: "ik_max_word",
                search_analyzer: "ik_max_word",
            },
            properties:{
              title: { type: 'string', analyzer: 'ik_max_word',  search_analyzer: 'ik_max_word' },
              content: { type: 'string', index: "not_analyzed" },
              tags: { type: 'string', index: "not_analyzed" },
              site_user: { type: 'string', index: 'not_analyzed' },
              created_time: { type: 'integer' },
              created_date: { type: 'string', index: 'not_analyzed' },
            }
        }
    }
end

# create_index


def create_type
    $client.index index: 'weibo', type: 'weibo', id: '1', body: {
    content: '//1.昆凌:“因为这个月18号我要去一件重要的事.” 2.主持人说,最近周杰伦宣传期接受了一些采访,你知道吗,他说“没有人会不喜欢你.”昆凌听后还在哭[泪] 祝福你和杰伦能永远幸福下去!倒计时14天~',
    tags: [ '周杰伦', '昆凌' ],
    site_user: 'BettyHu-',
    created_time: 1420435348,
    created_date: '20150105'
  }

  $client.index index:'weibo',type:'blog',id:'1',body:{
    content: 'this is my first blog',
    title: 'how to use ruby array',
    tags: [ 'ruby', 'array' ],
    site_user: 'kla-',
    created_time: 1420435348,
    created_date: '20150105'
  }

  $client.index index:'weibo',type:'comment',id:'1',body:{
    content: 'so good news',
    tags: [ '周杰伦', '昆凌' ],
    site_user: 'kla-',
    created_time: 1420435348,
    created_date: '20150105'
  }
end

# create_type

def add_data
    $client.index index:'weibo',type:'comment',id:'2',body:{
    comment_id:'001',
    content: 'so good news',
    tags: [ '周杰伦', '昆凌' ],
    site_user: 'kla-',
    created_time: 1420435348,
    created_date: '20150105'
  }
end
add_data
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值