elasticSearch基本命令学习

本文详细介绍如何使用Elasticsearch进行数据操作,包括索引、映射创建、数据查询及索引管理等关键任务。通过具体的cURL命令示例,读者可以学习到如何有效地与Elasticsearch交互,实现数据的高效管理和检索。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. index 为 students ,type为stu 查看id为2点数据

curl 'localhost:9200/students/stu/1?pretty'

结果:

{

  "_index" : "students",

  "_type" : "stu",

  "_id" : "1",

  "_version" : 1,

  "found" : true,

  "_source" : {

    "id" : "1",

    "name" : "中华人民共和国"

  }

}

2. 查看index的内容 如

 curl 'localhost:9200/students?pretty'

{

  "students" : {

    "aliases" : { },

    "mappings" : {

      "stu" : {

        "properties" : {

          "id" : {

            "type" : "string"  //类型id

          },

          "name" : {

            "type" : "string"   //字段name string类型

          }

        }

      }

    },

    "settings" : {

      "index" : {

        "creation_date" : "1475633663838",

        "number_of_shards" : "5",

        "number_of_replicas" : "1",

        "uuid" : "z8SNOI2tTHKO0G2mYfmFzg",

        "version" : {

          "created" : "2030599"

        }

      }

    },

    "warmers" : { }

  }

}

3. 查看全部索引 

curl 'localhost:9200/_cat/indices?v'


4. 查询index为area的全部数据

curl -XPOST 'localhost:9200/area/_search?pretty' -d '
 {
  "query":{"match_all":{}}
 }'



5. 索引和mapping的创建

1.ES的mapping非常类似于静态语言中的数据类型:声明一个变量为int类型的变量, 以后这个变量都只能存储int类型的数据。同样的, 一个number类型的mapping字段只能存储number类型的数据。

2.

(1)创建索引 curl -X PUT http://localhost:9200/account

(2)创建如下mapping


curl -X PUT http://localhost:9200/account/stu/_mapping -d '{
"stu": {
"_all": {
"analyzer": "ik_smart",
"search_analyzer": "ik_smart",
"term_vector": "no",
"store": "false"
},
"properties":    {
"sid": {
"type": "string"
},
"name": {
"type": "string"
},
"age": {
"type": "string"
},
"sex": {
"type": "string"
},
"address": {
"type": "string"
},
"telePhone": {
"type": "nested"
},
"persionList": {
"type": "nested"}
      }
    }
}'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值