Mac安装elasticsearch-- head插件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hunandexingkong/article/details/86492860

需要nodejs和git的支持

brew install node

查看是否安装成功 node -v 

➜  ~ node -v
v6.9.2
➜  ~

看到版本,说明安装成功

➜  ~ git --version
git version 2.9.3 (Apple Git-75)
➜  ~

本机已经有git

git clone git://github.com/mobz/elasticsearch-head.git

cd elasticsearch-head

npm install

npm run start

open http://localhost:9100/

配置elasticsearch,允许head插件访问

进入配置文件修改head权限

cd /usr/local/etc/elasticsearch/ 

vim elasticsearch.yml

添加,保存

http.cors.enabled: true                # elasticsearch中启用CORS
http.cors.allow-origin: "*"         # 允许访问的IP地址段,* 为所有IP都

需要重新启动elasticsearch,

进入elasticsearch-head目录,一定要进入这个目录才能执行npm run start命令,实际上是找目录下的package.json文件。

重新执行npm run start。否则会出现跨域问题。授权后要重启ES和head插件

重新进入http://localhost:9100/

记录原始状态

开始操作

操作一:创建索引

复合查询,类型PUT,URL:http://localhost:9200/helei

提交请求

{
"acknowledged": true,
"shards_acknowledged": true,
"index": "helei"
}

从返回看到我应该是创建了一个索引 helei , ES中索引是最大一级,然后是type,document, field。

回到首页验证

操作二:创建索引

进入索引页签创建索引

问题:分片数,副本数,代表了什么?

操作三:添加文档

使用post方式添加,url: http://localhost:9200/helei/first/12

这里helei是索引,first是类别,12是ID

如果12不写,是什么情况?试一下  http://localhost:9200/helei/first 

系统给随机生成了一个ID,其他和指定ID的结果一样。

那我再执行一次ID:12的URL会是什么结果?

能够看到三处变化"result": "updated" "_version": 2  "_seq_no": 1  说明这是个修改操作。

添加json继续提交,看到添加了索引文档

操作四:修改文档

修改过程与上面一样,指定URL到具体ID,post提交

操作五:查询文档

指定URL,get提交   http://localhost:9200/helei/first/12/   

去掉ID,尝试  http://localhost:9200/helei/first/    结果报错了。。看来查询只能具体到ID

操作六:删除文档

指定URL,delete提交   http://localhost:9200/helei/first/12/   

再次查询

尝试能否删除类型first?报错,类型的查询和删除都报错。

尝试删除索引,成功。

操作七:打开关闭索引

关闭索引_close  http://localhost:9200/helei/_close/

打开索引_open  http://localhost:9200/helei/_open/

操作八:添加索引映射

PUT   http://localhost:9200/helei3/

添加了索引helei3  文档类型 first 添加字段name  字段类型是keyword 

(keyword类型适合短词汇内容,比如邮件,姓名,性别等等,text类型适合长文本,可以分词,比如文章标题,文章内容等)  

操作九

一、例子

{
  "query": {
    "bool": {
      "must": [ // == 的关系
        {
          "range": {
            "create_time": {
              "gt": "1911-01-01",
              "lt": "2019-01-01"
            }
          }
        }
      ],
      "must_not": [], // != 的关系
      "should": []   // || 的关系
    }
  },
  "from": 0,  // 开始
  "size": 50,  // 页大小
  "sort": [   // 用什么排序 
    {
      "clue_create_time": "desc"
    }
  ],
  "aggs": {}
}

二、must, must not,should的区别

must 返回的文档必须满足must子句的条件,类似于 ==   and 

must not返回的文档必须不满足must not 子句的条件  类似于!=  not 

should 返回的文档只要满足should中的一个条件即可  类似于 ||  or

三、各类查询参数

  • prefix 前缀
  • wildcard 通配符查询  例:*商品*
  • term 分词, long int 类型 , 17 的 分词就是 17 , string 类型 为 空格 分割的单词 。 test data 分词之后是 test ,data . 【test data】 不是

  • range 区间 范围 只对整形 有作用 ,string 无效。

  • fuzzy  区间    value +- min_similarity   本实例中   是  -19 ~21 之间

{"query":{"bool":{"must":[],"must_not":[],"should":[{"fuzzy":{"10120.token_id":{"value":"1","min_similarity":"20"}}}]}},"from":0,"size":10,"sort":[],"facets":{}}:

  • query_string  可以对 int long string 进行 查询。   对 int long 只能 本身查询;   对 string 进行 分词查询  本身 也可以查询。

  • missing  对 那列中 没有 值的列 进行显示。

总结:

PUT新增,POST修改,GET查询,DELETE删除;

类型不能删除和查询;

图形操作和URL命令都能创建索引和删除索引,可以用POST命令打开关闭索引;

添加文档不指定ID,系统会随机ID;

对同一ID的多次post操作是修改操作,版本号递增;

命令_close _open _mapping _search;

mapping是映射关键字  properties是添加指定文档类型的字段的关键字;

keyword类型适合短词汇内容,比如邮件,姓名,性别等等,text类型适合长文本,可以分词,比如文章标题,文章内容等;

text用于全文搜索的, 而keyword用于关键词搜索;

猜你喜欢

转载自blog.csdn.net/hunandexingkong/article/details/86492860