找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 253|回复: 0

[ElasticSearch] ElasticSearch 6.x 学习小结(创建表/索引、添加数据)

  [复制链接]
发表于 2023-2-28 14:45 | 显示全部楼层 |阅读模式
废话不多说,直接上源码:这些数据格式,是在kibana格式化并且执行通过的。

1、创建表(索引)
请求:
PUT /user_search2
{
  "mappings": {
    "user_search_keyword2": {
      "properties": {
        "id": {
          "type": "long"
        },
        "keyword_": {
          "type": "text"
        },
        "type_": {
          "type": "text"
        },
        "user_id": {
          "type": "long"
        },
        "create_time": {
          "type": "date"
        }
      }
    }
  }
}

返回结果:
#! Deprecation: the default number of shards will change from [5] to [1] in 7.0.0; if you wish to continue using the default of [5] shards, you must manage this on the create index request or with an index template
{
  "acknowledged" : true,
  "shards_acknowledged" : true,
  "index" : "user_search2"
}

2、查询结构:
请求:
GET /user_search2/user_search_keyword2/_mapping
返回结果:
{
  "user_search2" : {
    "mappings" : {
      "user_search_keyword2" : {
        "properties" : {
          "create_time" : {
            "type" : "date"
          },
          "id" : {
            "type" : "long"
          },
          "keyword_" : {
            "type" : "text"
          },
          "type_" : {
            "type" : "text"
          },
          "user_id" : {
            "type" : "long"
          }
        }
      }
    }
  }
}

3、添加测试数据
请求:
POST /user_search2/user_search_keyword2
{
  "keyword_":"我来测试下",
  "type_":"article",
  "user_id":"711260",
  "create_time":"2018-12-18"
}
返回结果:
{
  "_index" : "user_search2",
  "_type" : "user_search_keyword2",
  "_id" : "Vpp1v2cBc3Sembhf9MFq",
  "_version" : 1,
  "result" : "created",
  "_shards" : {
    "total" : 2,
    "successful" : 2,
    "failed" : 0
  },
  "_seq_no" : 0,
  "_primary_term" : 1
}

4、查看数据
请求:
GET /user_search2/user_search_keyword2/_search
返回结果:
{
  "took" : 1,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "user_search2",
        "_type" : "user_search_keyword2",
        "_id" : "Vpp1v2cBc3Sembhf9MFq",
        "_score" : 1.0,
        "_source" : {
          "keyword_" : "我来测试下",
          "type_" : "article",
          "user_id" : "711260",
          "create_time" : "2018-12-18"
        }
      }
    ]
  }
}

5、删除
请求:
DELETE /user_search2

返回结果:
{
  "acknowledged" : true
}
 
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|学习笔记

GMT+8, 2024-5-3 20:25 , Processed in 0.034921 second(s), 13 queries , APCu On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表