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


相关推荐

  • java服务器后端框架_现在主流的java后端框架

    java服务器后端框架_现在主流的java后端框架Mars-javaMars是一个声明式API编程框架,可以帮助你很快的建立后端服务接口你可以专注在业务逻辑上,而不需要花太多的时间去写Controller和DAO同时我们依然支持传统ControllerPlayFrameworkplayframework是一个full-stack(全栈的)JavaWeb的应用框架,包括一个简单的无状态MVC模型,具有Hibernate的对象持续,一个基于Gro…

    2022年6月1日
    49
  • 响应式久草编程基础教程:久草Spring Boot 与 Lettuce 在线整合「建议收藏」

    响应式久草编程基础教程:久草Spring Boot 与 Lettuce 在线整合「建议收藏」本文主要介绍响应式编程访问Redis,以及SpringBoot与Lettuce的整合使用。Lettuce是可扩展性线程安全的Redis客户端,用于同步、异步和响应式使用。如果多个线程避免阻塞和事务性操作(例如BLPOP和MULTI/EXEC),则它们可以共享一个连接。Lettuce是基于Netty构建的。支持很多高级的Redis特性。根据SpringDataRedis2.0的更新的消息显示,SpringDataRedis不再支持JRedis的驱动,

    2022年10月19日
    1
  • h5 实现图片上传 案例

    h5 实现图片上传 案例如何在 h5 中实现图片上传 单图片上传 先写一个按钮 通过点击按钮触发文件上传的 onclick 事件 divclass btn onclick takePhone 请点击进行拍照 inputtype file name file id upload capture camera onchange uploadImg accept image value inputtype file name file id upload capture camera onchange uploadImg accept image divclass btn onclick takePhone

    2025年6月25日
    4
  • js和java那个难_javascript与java哪个难?

    js和java那个难_javascript与java哪个难?javascript与java哪个难?答案是:JavaScript比Java更难。那么这是为什么?下面本篇文章就来给大家介绍一下,希望对大家有所帮助。原因:JavaScript有太多东西需要你自己去理解,这些东西里有很多要么Java已经给你做成范式了,你可以通过学习范式来理解;要么就是根本没有,无需理解。JavaScript需要在语言的基础上再整理一套方法论,这个过程会有不同流派。而Java基本上…

    2022年7月7日
    29
  • Java基础大家必看啊

    Java基础大家必看啊写代码:1,明确需求。我要做什么?2,分析思路。我要怎么做?1,2,3。3,确定步骤。每一个思路部分用到哪些语句,方法,和对象。4,代码实现。用具体的java语言代码把思路体现出来。学习新技术的四点:1,该技术是什么?2,该技术有什么特点(使用注意):3,该技术怎么使用。demo4,该技术什么时候用?test。——————-…

    2022年6月20日
    23
  • 判断 checkbox 是否选中以及 设置checkbox选中

    判断 checkbox 是否选中以及 设置checkbox选中JS

    2022年7月1日
    21

发表回复

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

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