Elastic Search常用命令

Elastic Search常用命令ES的基本指令:1. 查看es的集群状态:curl ‘IP:9200/_cat/health?v’注释:?v表示格式化输出2. 查看节点列表curl ‘IP:9200/_cat/nodes?v’3.查询所有索引及数据大小curl ‘IP:9200/_cat/indices?v’ 4.创建索引(名称为studentIndex)并指定分片数和备份数curl -XPUT http:/…

大家好,又见面了,我是你们的朋友全栈君。

ES的基本指令:
1. 查看es的集群状态:
curl ‘IP:9200/_cat/health?v’
注释:?v表示格式化输出
2. 查看节点列表
curl ‘IP:9200/_cat/nodes?v’
3.查询所有索引及数据大小
curl ‘IP:9200/_cat/indices?v’
 
4.创建索引(名称为studentIndex)并指定分片数和备份数
curl -XPUT http://localhost:9200/studentIndex -d’
{

    “settings” : {

        “index” : {

            “number_of_shards” : 3, 
            “number_of_replicas” : 2 
        }
    }
}’

5.创建索引studentIndex,并添加类型student,并指定分词是studentname
curl -XPUT ‘http://localhost:9200/studentIndex’ -d ‘
{

  “mappings”: {

    “student”: {

      “properties”: {

        “studentname”: {

          “type”: “string”
        }
      }
    }
  }
}’

ES和mysql的对应关系
MySql        ElasticSearch
database  — index
table        — type
row          — document
cloumn    — field
schema   — mapping
index       — Everything is indexed
slect * from…   — get http://…
update talbe set… — put http://…

6.查询索引是studentIndex,type是student,studentname字段的值是“李”的信息,默认返回第一页,10条数据

http://localhost:9200/studentIndex/student/_search?q=studentname:李

{

    “took”: 32,
    “timed_out”: false,
    “_shards”: {

        “total”: 5,
        “successful”: 5,
        “failed”: 0
    },
    “hits”: {

        “total”: 645161,
        “max_score”: 13.882782,
        “hits”: [{

                “_index”: “studentIndex”,
                “_type”: “student”,
                “_id”: “AWNIsqEX4aqkPyNgQr06”,
                “_score”: 13.882782,
                “_source”: {

                    “studentname”: “李李四”
                }
            },
            {

                “_index”: “studentIndex”,
                “_type”: “student”,
                “_id”: “AWNIsqEX4aqkPyNgQr06”,
                “_score”: 13.23425,
                “_source”: {

                    “studentname”: “李五”
                }
            }
        ]
    }
}

7.使用post查询elastic search

curl -X POST \
http://1ip:9200/studentIndex/student/_search 
  -d ‘{

    “query”: {

        “match”: {

            “studentname”: “李”
        }
    },
    “from”: 100,  // 第几页开始
    “size”: 10   // 每页的大小
}’

返回结果同上:

注释:
在url中的q=* 相等于body中的
{

    “query”: { “match_all”: {} }
  }

8.查询数据总数:http://localhost:9200/studentIndex/student/_count

9.
a.插入数据:
curl -X POST ‘localhost:9200/studentIndex/student?pretty’ -d’ {“studentname”: “Jane Doe” }’
b.指定数据的Id是id1
curl -X POST ‘localhost:9200/studentIndex/student/id1?pretty’ -d’ {“studentname”: “John Doe” }’
10 删除数据
a.删除studentIndex中ID为2的数据
curl -X DELETE ‘localhost:9200/studentIndex/student/2?pretty’

b.根据条件删除数据
curl -X POST ‘localhost:9200/studentIndex/student/_delete_by_query?pretty’ -d ‘{

    “query”: {

        “match”: {

            “studentname”: “John”
        }
    }
}’
11.
修改id=1的name属性,并直接增加属性和属性值
curl -X POST ‘localhost:9200/studentIndex/student/1/_update?pretty’ -d ‘ {

    “doc”: {

        “studentname”: “xyd” 
    }
}’

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/149530.html原文链接:https://javaforall.net

赞 (0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 各种浏览器怎么换ip

    各种浏览器怎么换ip

    2021年10月23日
  • eclipse离线安装svn插件使用教程_eclipse导入svn项目

    eclipse离线安装svn插件使用教程_eclipse导入svn项目最近要在eclipse上安装一个svn插件,本来以为是很简单的一件事,没想到尝试了很多方法,还是各种不成功以下是网上常见的解决方案:第一种(失败):help->EclipseMarketplace在线安装结果:下载不下来,换一个版本的插件安装成功,但连接仓库会提示0x00400006第二种(失败):help->InstallNewSoftware手动在线安装:给的地址是类似这样的:http://subclipse.tigris.org/update_1.8…

    2022年10月14日
  • Shiro框架:Shiro简介、登陆认证入门程序、认证执行流程、使用自定义Realm进行登陆认证、Shiro的MD5散列算法

    Shiro框架:Shiro简介、登陆认证入门程序、认证执行流程、使用自定义Realm进行登陆认证、Shiro的MD5散列算法

    2021年9月26日
  • 杂谈 – 自定义搜索引擎

    杂谈 – 自定义搜索引擎在Firefox上,以{肯定被驳回}搜索引擎为例。{肯定被驳回}搜索引擎搜索英文关键词时,给出的也基本是英文,例如这样:看了几篇不符合自己的胃口,遂点击了左上角小提示:仅限简体中文结果,例如这样:发现第二篇就是自己想要的东西,遂想,中文的结果也不错,何不设置不管中英文关键字,都先输出中文呢?所以实现方式,就是:添加addcustomsearchengine。2.点击扩展图标其中,SearchURL为:为了避免被驳回,请自行输入。然后点击蓝色按钮。然后在Firefox的

    2022年7月13日
  • 简单利用conda安装tensorflow-gpu=2.2.0

    简单利用conda安装tensorflow-gpu=2.2.0网上安装tensorflow-gpu=2.2.0什么的一大推,而且最后还报错,一般问题出现在:一、安装下载慢二、cuda和cudnn版本不对我最后实验了,很好解决上面的问题。一、安装tensorflow-gpu=2.2.0使用清华源安装,代码如下:pipinstalltensorflow-gpu==2.2.0-ihttps://pypi.tuna.tsinghua.edu.cn/simple这样下载速度飞起!二、什么去官网下载cuda版本配置路径,感觉都不靠谱,我实验了,一个命令搞定

    2022年6月15日
  • 重启nginx命令

    重启nginx命令进入到nginx/sbin目录下面首先需要获取超级管理员的权限1、输入sudosu然后输入密码2、输入sudobash然后输入密码然后输入./nignx-sreloadnginx重启成功

    2022年6月19日

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号