zoukankan      html  css  js  c++  java
  • Windows下ElasticSearch学习(二)

    欢迎关注【无量测试之道】公众号,回复【领取资源】,
    Python编程学习资源干货、
    Python+Appium框架APP的UI自动化、
    Python+Selenium框架Web的UI自动化、
    Python+Unittest框架API自动化、

    资源和代码 免费送啦~
    文章下方有公众号二维码,可直接微信扫一扫关注即可。

    今天继续学习ES 在Windows 下的使用,主要是通过curl 命令行来操作ES:
    备注:说明一下ES 的版本为6.8.8.

    1.查看ES的相关信息

     1 C:Users	dcengineer>curl http://127.0.0.1:9200/?pretty
     2 {
     3 "name" : "node-1",
     4 "cluster_name" : "myes",
     5 "cluster_uuid" : "jImvcOwnQbilYTD8JLNtFA",
     6 "version" : {
     7 "number" : "6.8.8",
     8 "build_flavor" : "default",
     9 "build_type" : "zip",
    10 "build_hash" : "2f4c224",
    11 "build_date" : "2020-03-18T23:22:18.622755Z",
    12 "build_snapshot" : false,
    13 "lucene_version" : "7.7.2",
    14 "minimum_wire_compatibility_version" : "5.6.0",
    15 "minimum_index_compatibility_version" : "5.0.0"
    16 },
    17 "tagline" : "You Know, for Search"
    18 }

    2.创建一个索引

    1 C:Users	dcengineer>curl -XPUT http://127.0.0.1:9200/index_01
    2 {"acknowledged":true,"shards_acknowledged":true,"index":"index_01"}

    3.创建一个索引,并初始化一个文档

    1 C:Users	dcengineer>curl -XPUT -H "content-Type:application/json" "http://127.0.0.1:9200/testindex/student/1" -d"{"name":"tony","age":25,"score":99}"
    2 {"_index":"testindex","_type":"student","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}
    3  
    4 C:Users	dcengineer>curl -XPUT -H "content-Type:application/json" "http://127.0.0.1:9200/testindex/student/2" -d"{"name":"tony","age":33,"score":99}"
    5 {"_index":"testindex","_type":"student","_id":"2","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}

    4.更新指定的id=2的索引内容

    1 C:Users	dcengineer>curl -XPUT -H "content-Type:application/json" "http://127.0.0.1:9200/testindex/student/2" -d"{"name":"tony","age":32,"score":98}"
    2 {"_index":"testindex","_type":"student","_id":"2","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":1,"_primary_term":1}

    5.删除指定索引下的数据

    1 C:Users	dcengineer>curl -XDELETE -H "content-Type:application/json" "http://127.0.0.1:9200/testindex/student/2"
    2 {"_index":"testindex","_type":"student","_id":"2","_version":3,"result":"deleted","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":2,"_primary_term":1}

    6.删除指定的索引

    1 C:Users	dcengineer>curl -XDELETE -H "content-Type:application/json" "http://127.0.0.1:9200/test0823"
    2 {"acknowledged":true}

    7.获取指定索引下id=2 的数据信息

    1 C:Users	dcengineer>curl -XGET -H "content-Type:application/json" "http://127.0.0.1:9200/testindex/student/2"
    2 {"_index":"testindex","_type":"student","_id":"2","_version":1,"_seq_no":3,"_primary_term":1,"found":true,"_source":{"name":"tony","age":32,"score":98}}

    格式化后输出:

     1 C:Users	dcengineer>curl -XGET -H "content-Type:application/json" "http://127.0.0.1:9200/testindex/student/2?pretty"
     2 {
     3 "_index" : "testindex",
     4 "_type" : "student",
     5 "_id" : "2",
     6 "_version" : 1,
     7 "_seq_no" : 3,
     8 "_primary_term" : 1,
     9 "found" : true,
    10 "_source" : {
    11 "name" : "tony",
    12 "age" : 32,
    13 "score" : 98
    14 }
    15 }

    8.查询指定索引下的所有数据

     1 C:Users	dcengineer>curl -XGET -H "content-Type:application/json" "http://127.0.0.1:9200/testindex/_search?pretty"
     2 {
     3 "took" : 1,
     4 "timed_out" : false,
     5 "_shards" : {
     6 "total" : 5,
     7 "successful" : 5,
     8 "skipped" : 0,
     9 "failed" : 0
    10 },
    11 "hits" : {
    12 "total" : 2,
    13 "max_score" : 1.0,
    14 "hits" : [
    15 {
    16 "_index" : "testindex",
    17 "_type" : "student",
    18 "_id" : "2",
    19 "_score" : 1.0,
    20 "_source" : {
    21 "name" : "tony",
    22 "age" : 32,
    23 "score" : 98
    24 }
    25 },
    26 {
    27 "_index" : "testindex",
    28 "_type" : "student",
    29 "_id" : "1",
    30 "_score" : 1.0,
    31 "_source" : {
    32 "name" : "tom",
    33 "age" : 35,
    34 "score" : 89
    35 }
    36 }
    37 ]
    38 }
    39 }

    9.指定条件name=tony的数据

     1 C:Users	dcengineer>curl -XPOST -H "content-Type:application/json" "http://127.0.0.1:9200/testindex/_search?pretty" -d "{"query":{"match":{"name":"tony"}}}"
     2 {
     3 "took" : 72,
     4 "timed_out" : false,
     5 "_shards" : {
     6 "total" : 5,
     7 "successful" : 5,
     8 "skipped" : 0,
     9 "failed" : 0
    10 },
    11 "hits" : {
    12 "total" : 1,
    13 "max_score" : 0.2876821,
    14 "hits" : [
    15 {
    16 "_index" : "testindex",
    17 "_type" : "student",
    18 "_id" : "2",
    19 "_score" : 0.2876821,
    20 "_source" : {
    21 "name" : "tony",
    22 "age" : 32,
    23 "score" : 98
    24 }
    25 }
    26 ]
    27 }
    28 }

    10.查询条件为name=tony or tom 的数据

     1 C:Users	dcengineer>curl -XPOST -H "content-Type:application/json" "http://127.0.0.1:9200/testindex/_search?pretty" -d "{"query":{"match":{"name":"tony tom"}}}"
     2 {
     3 "took" : 6,
     4 "timed_out" : false,
     5 "_shards" : {
     6 "total" : 5,
     7 "successful" : 5,
     8 "skipped" : 0,
     9 "failed" : 0
    10 },
    11 "hits" : {
    12 "total" : 2,
    13 "max_score" : 0.2876821,
    14 "hits" : [
    15 {
    16 "_index" : "testindex",
    17 "_type" : "student",
    18 "_id" : "2",
    19 "_score" : 0.2876821,
    20 "_source" : {
    21 "name" : "tony",
    22 "age" : 32,
    23 "score" : 98
    24 }
    25 },
    26 {
    27 "_index" : "testindex",
    28 "_type" : "student",
    29 "_id" : "1",
    30 "_score" : 0.2876821,
    31 "_source" : {
    32 "name" : "tom",
    33 "age" : 35,
    34 "score" : 89
    35 }
    36 }
    37 ]
    38 }
    39 }

    11.查询结果返回size=1的数据

     1 C:Users	dcengineer>curl -XPOST -H "content-Type:application/json" "http://127.0.0.1:9200/testindex/_search?pretty" -d "{"query":{"match":{"name":"tony"}},"size":1}"
     2 {
     3 "took" : 3,
     4 "timed_out" : false,
     5 "_shards" : {
     6 "total" : 5,
     7 "successful" : 5,
     8 "skipped" : 0,
     9 "failed" : 0
    10 },
    11 "hits" : {
    12 "total" : 2,
    13 "max_score" : 0.2876821,
    14 "hits" : [
    15 {
    16 "_index" : "testindex",
    17 "_type" : "student",
    18 "_id" : "2",
    19 "_score" : 0.2876821,
    20 "_source" : {
    21 "name" : "tony",
    22 "age" : 32,
    23 "score" : 98
    24 }
    25 }
    26 ]
    27 }
    28 }

    12.从查询结果的第二条开始返回size=1的数据

     1 C:Users	dcengineer>curl -XPOST -H "content-Type:application/json" "http://127.0.0.1:9200/testindex/_search?pretty" -d "{"query":{"match":{"name":"tony"}},"size":1,"from":1}"
     2 {
     3 "took" : 1,
     4 "timed_out" : false,
     5 "_shards" : {
     6 "total" : 5,
     7 "successful" : 5,
     8 "skipped" : 0,
     9 "failed" : 0
    10 },
    11 "hits" : {
    12 "total" : 2,
    13 "max_score" : 0.2876821,
    14 "hits" : [
    15 {
    16 "_index" : "testindex",
    17 "_type" : "student",
    18 "_id" : "3",
    19 "_score" : 0.2876821,
    20 "_source" : {
    21 "name" : "tony",
    22 "age" : 33,
    23 "score" : 90
    24 }
    25 }
    26 ]
    27 }
    28 }

    13.设置mapping

    1 C:Users	dcengineer>curl -XPUT -H "content-Type:application/json" "http://127.0.0.1:9200/index0823/person/_mapping" -d "{"person" : {"properties" : {"name" : {"type" : "text"},"status" : {"type" : "integer" }}}}"
    2 {"acknowledged":true}

    14.获取mapping

     1 C:Users	dcengineer>curl -XGET -H "content-Type:application/json" "http://127.0.0.1:9200/testindex/_mapping?pretty"
     2 {
     3 "testindex" : {
     4 "mappings" : {
     5 "student" : {
     6 "properties" : {
     7 "age" : {
     8 "type" : "long"
     9 },
    10 "name" : {
    11 "type" : "text",
    12 "fields" : {
    13 "keyword" : {
    14 "type" : "keyword",
    15 "ignore_above" : 256
    16 }
    17 }
    18 },
    19 "score" : {
    20 "type" : "long"
    21 }
    22 }
    23 }
    24 }
    25 }
    26 }

    15.查看索引的配置信息

     1 C:Users	dcengineer>curl -XGET -H "content-Type:application/json" "http://127.0.0.1:9200/testindex/_settings?pretty"
     2 {
     3 "testindex" : {
     4 "settings" : {
     5 "index" : {
     6 "creation_date" : "1598166190725",
     7 "number_of_shards" : "5",
     8 "number_of_replicas" : "1",
     9 "uuid" : "-Vc2G8szSLKNsmykPfL3WQ",
    10 "version" : {
    11 "created" : "6080899"
    12 },
    13 "provided_name" : "testindex"
    14 }
    15 }
    16 }
    17 }

    16.设置索引的副本信息(分片个数不允许修改)

    1 C:Users	dcengineer>curl -XPUT -H "content-Type:application/json" "http://127.0.0.1:9200/testindex/_settings" -d "{"number_of_replicas":5}"
    2 {"acknowledged":true}

    总结:以上内容就是今天的全部分享,文章内容都是个人在工作中常用的一些操作示例总结,有些内容可能不太全面,大家需要自行补充一下(查资料),同时可以结合“ Windows下ElasticSearch学习(一)”文章一起来阅读。

    备注:我的个人公众号已正式开通,致力于测试技术的分享,包含:大数据测试、功能测试,测试开发,API接口自动化、测试运维、UI自动化测试等,微信搜索公众号:“无量测试之道”,或扫描下方二维码:

     添加关注,让我们一起共同成长!

  • 相关阅读:
    如何学习linux编程
    SharpMap学习9调侃WebGIS
    蛮力法01
    SharpMap学习10比例尺
    蛮力法03
    系统学习Linux11点建议
    蛮力算法02
    大地坐标系
    Windows 7下删除右键新建菜单项的多余选项
    GIS中的坐标系相关概念
  • 原文地址:https://www.cnblogs.com/Wu13241454771/p/13576199.html
Copyright © 2011-2022 走看看