ElasticSearch基本操作

Title ElasticSearch基本操作
Framework ElasticSearch
User wy8817399@vip.qq.com
Id 25
Created 1/13/26, 1:09 PM
Modified 1/21/26, 2:23 PM
Published Yes
Content

1、创建一个名为note的空索引

PUT
http://elastic:A3MZa=H5sjtyIyE+7aSr@localhost:9201/note

 

2、查询一个名为note的索引

GET
http://elastic:A3MZa=H5sjtyIyE+7aSr@localhost:9201/note

 

3、删除一个名为note的索引

DELETE
http://elastic:A3MZa=H5sjtyIyE+7aSr@localhost:9201/note

 

4、创建note索引映射并指定分词器

PUT
http://elastic:A3MZa=H5sjtyIyE+7aSr@localhost:9201/note

{
    "mappings":{
        "properties":{
            "id":{
                "type":"keyword"
            },
            "title":{
                "type":"text",
                "analyzer":"ik_max_word",
                "copy_to":"all"
            },
            "content":{
                "type":"text",
                "analyzer":"ik_max_word",
                "copy_to":"all"
            },
            "framework_id":{
                "type":"keyword"
            },
            "framework_name":{
                "type":"text",
                "analyzer":"ik_max_word",
                "copy_to":"all"
            },
             "published": {
                "type": "boolean"
            },
            "user_id": {
                "type": "keyword"
            },
            "created": {
                "type": "date"
            },
            "modified": {
                "type": "date"
            },
            "all":{
                "type":"text",
                "analyzer":"ik_max_word"
            }
        }
    }
}

 

5、查看索引映射

GET
http://elastic:A3MZa=H5sjtyIyE+7aSr@localhost:9201/note/_mapping

 

6、创建文档数据

POST
http://elastic:A3MZa=H5sjtyIyE+7aSr@localhost:9201/note/_doc

{
   "title":"今天天气不错4",
   "content":"今天天气确实不错4,风和日丽",
   "framework_id":1,
   "framework_name":"测试数据"
}

 

7、自定义id创建note的文档数据

POST
http://elastic:A3MZa=H5sjtyIyE+7aSr@localhost:9201/note/_doc/1

{
   "title":"今天天特别气不错",
   "content":"这是自定义id创建的天气不错",
   "framework_id":1,
   "framework_name":"测试数据"
}

 

8、根据id修改note的文档数据

POST
http://elastic:A3MZa=H5sjtyIyE+7aSr@localhost:9201/note/_update/1

{
   "doc":{
      "content":"这是自定义id创建的天气不错2222"
   }
}

 

9、根据id查询note的文档数据

GET
http://elastic:A3MZa=H5sjtyIyE+7aSr@localhost:9201/note/_doc/1

 

10、根据id删除note的文档数据

DELETE
http://elastic:A3MZa=H5sjtyIyE+7aSr@localhost:9201/note/_doc/c-hgDZsBGizCsGCMESuU

 

11、查询所有note的文档数据

GET
http://elastic:A3MZa=H5sjtyIyE+7aSr@localhost:9201/note/_search

 

12、根据特定条件查询note的文档数据

POST
http://elastic:A3MZa=H5sjtyIyE+7aSr@localhost:9201/note/_search


{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "published": true
          }
        },
       {
          "term": {
            "framework_id": 4
          }
        },
        {
          "match": {
            "all": "古"
          }
        }
      ]
    }
  },
  "size": 20
}