ElasticSearch入门笔记

1、角色关系对照

elasticsearch 跟 MySQL 中定义资料格式的角色关系对照表如下

MySQL             elasticsearch

database                 index

table                         type

table schema        mapping

row                          document

field                         field

 

2、索引映射

创建索引:

$ curl -XPUT http://localhost:9200/test-index  test-index为库名。

 

创建Mapping:

$ curl -XPUT http://10.1.11.183:9200/test-index/test-type/_mapping -d'{

    "properties" : {

        "name" : { "type" : "string" }

    }

}'

test-index为库名。对应index

test-type 为类型名。对应type

例如:

    mapping ={

           u'id': {'store': 'yes',

                    'type': u'integer'},

           u'author': {'boost': 1.0,

                       'index': 'not_analyzed',

                       'store': 'yes',

                       'type': u'string'},

           u'published': {'boost': 1.0,

                          'index': 'not_analyzed',

                          'store': 'yes',

                          'type': u'datetime'},

           u'url': {'store': 'yes',

                        'type': u'string'},

           u'title': {'boost': 1.0,

                       'index': 'analyzed',

                       'store': 'yes',

                       'type': u'string'},

           u'content': {'boost': 1.0,

                       'index': 'analyzed',

                       'store': 'yes',

                       'type': u'string',

                       "term_vector" : "with_positions_offsets"}

           }

 3、索引

#索引

$ curl -XPUT http://localhost:9200/test-index/test-type/1-d'{

    "user": "kimchy",

    "post_date": "2009-11-15T13:12:00",

    "message": "Trying out elasticsearch, so far so good?"

}'

#获取

$ curl -XGET http://localhost:9200/test-index/test-type/1

#删除

$ curl -XDELETE'http://localhost:9200/test-index/test-type/1'

 

 4、搜索

#lucene语法方式的查询

$ curl -XGET http://localhost:9200/test-index/test-type/q=user:_search?kimchy

#query DSL方式查询

$ curl -XGET http://localhost:9200/test-index/test-type/_search -d'{

    "query" : {

        "term" : { "user": "kimchy" }

    }

}'

#query DSL方式查询

$ curl -XGET http://localhost:9200/test-index/_search?pretty=true-d'{

    "query" : {

        "range" : {

            "post_date" : {

                "from" : "2009-11-15T13:00:00",

                "to" : "2009-11-15T14:30:00"

            }

        }

    }

}'

#查找全部索引内容

$ curl -XGET http://localhost:9200/test-index/test-type/_search?pretty=true

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值