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


相关推荐

  • fsync函数

    fsync函数fsync函数,将文件数据同步到硬盘功能描述: 系统调用fsync将所有已写入文件描述符fd的数据真正的写道磁盘或者其他下层设备上。用法:#includeintfsync(intfd);#ifdef_POSIX_SYNCHRONIZ

    2022年5月31日
    126
  • 如何写软件项目技术标

    如何写软件项目技术标技术标作为一个初期评价软件供应商的重要标准之一,需要覆盖多方面的考虑因素,从需求的理解,到系统的设计,到项目的实施与管理,以及项目的验收与后期支持。那么我们如何来编写一个完整的技术标呢?第一,项目概述   项目情况的一个综合介绍,这是一个综述,通过这个综述说明项目的背景

    2022年5月11日
    61
  • java8 stream流操作的flatMap(流的扁平化)

    java8 stream流操作的flatMap(流的扁平化)flatMap的用法和含义住要通过一个案例来讲解,案例:对给定单词列表["Hello","World"],你想返回列表["H","e","l","o","W","r","d"]第一种方式String[]words=newString[]{"Hello","World&quot

    2022年6月2日
    38
  • [股票预测]股票历史数据获取[通俗易懂]

    [股票预测]股票历史数据获取[通俗易懂]一、编程环境准备第一步:安装Anaconda3;第二步:安装工具包Pandas、tusharepipinstallPandaspipinstalltushare第三步:查看Pandas、tushare版本piplistpandas1.2.4tushare1.2.64二、股票历史行情数据提取2.1获取近3年个股日线交易数据通过参数设置获取日k线、周k线、月k线,…

    2022年6月24日
    36
  • centos7安装vsftp配置虚拟用户「建议收藏」

    centos7安装vsftp配置虚拟用户「建议收藏」安装前的准备关闭防火墙或者开端口权限。一般是firewalld或者iptables。systemctlstopfirewalldsystemctldisablefirewalld关闭sellinux立即关闭setenforce0重启也关闭vi/etc/selinux/config修改SELINUX=disabled查看是否关闭get

    2022年9月25日
    0
  • getelementbyid属性与用法[通俗易懂]

    getelementbyid属性与用法[通俗易懂]语法:oElement=document.getElementById(sID)参数:sID――必选项。字符串 (String) 。返回值:oElemen――对象 (Element) 。说明:根据指定的 id 属性值得到对象。返回 id 属性值等于 sID 的第一个对象的引用。假如对应的为一组对象,则返回该组对象中的第一个。 如果无符合条件的对象,则返回 nul

    2022年7月15日
    43

发表回复

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

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