zoukankan      html  css  js  c++  java
  • 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
    }
  • 相关阅读:
    [原]音视频播放笔记
    [原]很多时候, 错误源于自己
    [原]找工作之tj
    [原]昨天碰到的一个诡异问题
    [原]硬盘分区规划
    [原]编程手记2008.08.26
    [原]编程手记2008.08.28
    eclipse 某些java文件乱码
    图片垂直居中,兼容ie6
    ul里不能直接嵌套div
  • 原文地址:https://www.cnblogs.com/wanglan/p/10770427.html
Copyright © 2011-2022 走看看