ElasticSearch简单介绍

本文介绍了Elasticsearch的配置方法及基本操作命令,包括安装步骤、配置文件详解及常用的查询语句等。

ElasticSearch

1、网址

官方网址:https://www.elastic.co/

文档地址:https://www.elastic.co/guide/index.html(教程加权威指南)

2、版本

      1.5(此版本要求jdk 1.7.50及以上)

3、安装

      3.1 配置java环境变量(jdk 1.7.50及以上)

      3.2 下载压缩包、解压

      3.3 运行

./bin/elasticsearch –d

      (如果不加-d参数,会前台运行,退出的时候进程也就停止了)

4、配置

      4.1配置文件路径config下的elasticsearch.yml(主配置文件)、logging.yml(日志)

      4.2 主要配置项说明     

 cluster.name: xxx     #集群名称

      node.name: "xxx"        #节点名称

      index.number_of_shards: 5    #分片数量(每台机器的分片数数据分散到每个片上,减少每个片的总数据量,加快查询速度)

      index.number_of_replicas:1    #复制数量(每个分片的备份数,保证数据的完整性)

      bootstrap.mlockall: true        #锁定内存

      network.host: xxx.xxx.xxx.xxx        #设置本机地址和发布地址

      transport.tcp.port: 9300         #TCP访问端口

      http.port: 9200                      #HTTP访问端口

#集群间通讯超时以及频次设置

      discovery.zen.ping.timeout: 60s

discovery.zen.fd.ping_interval: 5s

discovery.zen.fd.ping_timeout: 60s

discovery.zen.fd.ping_retries: 5



discovery.zen.ping.multicast.enabled: false        #不使用广播

discovery.zen.ping.unicast.hosts: ["ip:port"]      #其他机器地址,多个用逗号分隔

#以下为慢查询时间设置

index.search.slowlog.threshold.query.warn: 10s

index.search.slowlog.threshold.query.info: 5s

index.search.slowlog.threshold.query.debug: 2s

index.search.slowlog.threshold.query.trace: 500ms



http.cors.enabled: true          #允许head插件访问

5、启动文件设置

      5.1 打开bin/elasticsearch

      

5.2保存即可

6、查询语句

      6.1增删改查

      增索引

    

  $ curl -XPUT 'http://localhost:9200/twitter/'

    索引别名(更平顺的迁移数据,不影响线上)   

 curl -XPOST 'http://localhost:9200/_aliases' -d '

{

    "actions" : [

        { "add" : { "index" : "test1", "alias" : "alias1" } }

    ]

}'

    增Mapping     

$ curl -XPUT 'http://localhost:9200/twitter/_mapping/tweet' -d '

{

    "tweet" : {

        "properties" : {

            "message" : {"type" : "string", "store" : true }

        }

    }

}

'

    增加文档

$ curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{

    "user" : "kimchy",

    "post_date" : "2009-11-15T14:12:12",

    "message" : "trying out Elasticsearch"

}'

      根据Id查找

curl -XGET 'http://localhost:9200/twitter/tweet/1'

删除

$ curl -XDELETE 'http://localhost:9200/twitter/tweet/1'

更新

curl -XPOST 'localhost:9200/test/type1/1/_update' -d '{

    "doc" : {

        "name" : "new_name"

    }

}'

6.1 query(分词查询,全文检索),

      6.2 filter(普通查询)

转载于:https://my.oschina.net/hhdys412/blog/680357

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值