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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 如何快速成长为不可或缺的技术人才?

    如何快速成长为不可或缺的技术人才?

    2021年10月22日
    38
  • 关于CommandType.StoredProcedure输出参数访问问题

    关于CommandType.StoredProcedure输出参数访问问题MSDN解释:当您将 Command 对象用于存储过程时,可以将 Command 对象的 CommandType 属性设置为 StoredProcedure。当 CommandType 为 StoredProcedure 时,可以使用 Command 的 Parameters 属性来访问输入及输出参数和返回值。无论调用哪一个 Execute 方法,都可以访问 Parameters 属性。但是,

    2022年7月26日
    6
  • linux系统centos7安装nginx

    linux系统centos7安装nginxlinux系统centos7安装nginx,简单亲自测试成功

    2022年5月15日
    33
  • 基于MATLAB的卷积神经网络车牌识别系统

    基于MATLAB的卷积神经网络车牌识别系统车牌识别是基于车牌照片的车牌信息的识别工作,车牌识别技术对我们的实际生活至关重要,例如交通违规行为的增加,拦截非法车辆,在速度上能够进行快速识别能够很好地解决这些问题。获得的照片的质量是影响车牌识别准确性的最重要因素之一。卷积神经网络在图像识别领域具有良好的适应性,目前在计算机视觉任务中应用广泛,并在手写数字识别、人脸识别、车牌识别等图像领域的应用中取得了很好的效果。本文基于MATLAB卷积神…

    2022年5月29日
    25
  • dz论坛修改html编辑器,discuz二次开发更换百度ueditor编辑器

    dz论坛修改html编辑器,discuz二次开发更换百度ueditor编辑器修改前必读:1、修改编辑器后会造成以前发过的帖子再次进行修改时(也就是编辑帖子操作)出现很多被DZ重写过的html标签,不方便进行修改,所以尽量在安装DZ后立刻进行修改。(当然,如果你有能力重写代码的话就可以无视啦)2、修改前请先在本地进行尝试或备份相关文件。需要修改的文件:templatedefaultforumpost_editor_body.htmtemplatedefaultforumpo…

    2022年5月12日
    44
  • Linux学习—退出vi编辑模式

    在Linux学习中总结退出vi编辑模式

    2022年2月24日
    62

发表回复

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

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