• elasticsearch简单操作


    现在,启动一个节点和kibana,接下来的一切操作都在kibanaDev Tools下的Console里完成

    创建一篇文档

    将小黑的小姨妈的个人信息录入elasticsearch。我们只要输入

    PUT t1/doc/1
    {
      "name":"小黑的小姨妈",
      "age": 18
    }

    PUT表示创建命令。虽然命令可以小写,但是我们推荐大写

    {
      "_index" : "t1",
      "_type" : "doc",
      "_id" : "1",
      "_version" : 1,
      "result" : "updated",
      "_shards" : {
        "total" : 2,
        "successful" : 1,
        "failed" : 0
      },
      "_seq_no" : 2,
      "_primary_term" : 1
    }

    结果中的result则是操作类型,现在是created,表示第一次创建。如果我们再次点击执行该命令,那么result则会是updated。我们细心则会发现_version开始是1,现在你每点击一次就会增加一次。表示第几次更改。

    查看所有的索引

    GET _cat/indices

    查询指定的索引信息

    GET t1

    返回了t1索引的创建信息

    {
      "t1" : {
        "aliases" : { },
        "mappings" : {
          "doc" : {
            "properties" : {
              "age" : {
                "type" : "long"
              },
              "name" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              }
            }
          }
        },
        "settings" : {
          "index" : {
            "creation_date" : "1553163739688",
            "number_of_shards" : "5",
            "number_of_replicas" : "1",
            "uuid" : "_7jNW5XATheeK84zKkPwlw",
            "version" : {
              "created" : "6050499"
            },
            "provided_name" : "t1"
          }
        }
      }
    }

    查看文档信息

    GET t1/doc/1

    返回结果

    {
      "_index" : "t1",
      "_type" : "doc",
      "_id" : "1",
      "_version" : 2,
      "found" : true,
      "_source" : {
        "name" : "小黑的小姨妈",
        "age" : 18
      }
    }

    查询文档的所有的信息

    GET t1/doc/_search

    返回信息

    {
      "took" : 38,
      "timed_out" : false,
      "_shards" : {
        "total" : 5,
        "successful" : 5,
        "skipped" : 0,
        "failed" : 0
      },
      "hits" : {
        "total" : 2,
        "max_score" : 1.0,
        "hits" : [
          {
            "_index" : "t1",
            "_type" : "doc",
            "_id" : "2",
            "_score" : 1.0,
            "_source" : {
              "name" : "小黑的二姨妈",
              "age" : 16
            }
          },
          {
            "_index" : "t1",
            "_type" : "doc",
            "_id" : "1",
            "_score" : 1.0,
            "_source" : {
              "name" : "小黑的小姨妈",
              "age" : 18
            }
          }
        ]
      }
    }

    查看索引配置信息

    GET t1/_settings

    返回信息

    {
      "t1" : {
        "settings" : {
          "index" : {
            "creation_date" : "1556191748817",
            "number_of_shards" : "5",
            "number_of_replicas" : "1",
            "uuid" : "WDJy3_KYTjS_ljqr9QIETw",
            "version" : {
              "created" : "6050499"
            },
            "provided_name" : "t1"
          }
        }
      }
    }

    查看映射关系

    GET t1/_mappin

    返回信息

    {
      "t1" : {
        "mappings" : {
          "doc" : {
            "properties" : {
              "age" : {
                "type" : "long"
              },
              "name" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              }
            }
          }
        }
      }
    }

    删除索引

    删除指定文档

    DELETE t1/doc/2

    删除索引

    DELETE t1
    
    返回结果
    {
      "acknowledged" : true
    }
  • 相关阅读:
    ORA-06530: 引用未初始化的组合 ;
    oracle 简单的sysTimeStamp类型转date 类型
    Luogu P3388 【模板】割点(割顶)
    Luogu P2048 [NOI2010]超级钢琴
    Luogu P2657 [SCOI2009]windy数
    QZEZ第一届“饭吉圆”杯程序设计竞赛
    Luogu P2286 [HNOI2004]宠物收养场
    在平衡树的海洋中畅游(一)——Treap
    Luogu P1129 [ZJOI2007]矩阵游戏
    LOJ #559. 「LibreOJ Round #9」ZQC 的迷宫
  • 原文地址:https://www.cnblogs.com/wanglan/p/10770427.html
Copyright © 2020-2023  润新知