zoukankan      html  css  js  c++  java
  • elasticsearch 数据认识 与 数据表文档 的增删改

    【Elasticsearch 7.8.1】当前版本

    新建 mingduhui 的数据库 检索库  向其中新增表 操作如下

    PUT /mingduhui/_mapping/goods
        {
                
                    "properties": {
                        "id": {
                            "type": "long",
                            "store": true,
                        },
                        "title": {
                            "type": "text",
                            "store": true,
                            "index":true,
                            "analyzer":"standard"
                        },
                        "content": {
                            "type": "text",
                            "store": true,
                            "index":true,
                            "analyzer":"standard"
                        }
                    }
                
            
        }

    运行结果如下: 报错

    出现问题的原因:在ES7中,不推荐使用映射类型,这会导致此问题的根源发生重大变化。ES团队宣布了弃用,路线图和替代方案。

    解决方式:
    
    方式一:删除对映射类型的所有引用(在此示例中为“article”)
    
    方式二:平滑过渡到ES7的另一个临时解决方案是包含?include_type_name=true在URL中。

    添加 指定关键 参数 如下提交请求

    PUT /mingduhui/_mapping/goods?include_type_name=true
        {
                
                    "properties": {
                        "id": {
                            "type": "long",
                            "store": true,
                        },
                        "title": {
                            "type": "text",
                            "store": true,
                            "index":true,
                            "analyzer":"standard"
                        },
                        "content": {
                            "type": "text",
                            "store": true,
                            "index":true,
                            "analyzer":"standard"
                        }
                    }
                
            
        }

    结果任然报错。

      A. 数据类型

     B. index

     C. store 

    解决方式:把“index”的值全部改为true/false
    指定index true

    数据类型 keyword 为关键词 不可以进行分词
    PUT /mingduhui/_mapping/goods?include_type_name=true
        {
          "properties": {
              "id": {
                "type": "long",
                "store": true,
                "index":true
              },
              "title": {
                "type": "text",
                "store": true,
                "index":true,
                "analyzer":"standard"
              },
              "subtitle": {
                "type": "text",
                "store": true,
                "index":true,
                "analyzer":"ik_max_word"
              },
              "images": {
                "type": "keyword",
                "index":true
              },
              "content": {
                "type": "text",
                  "store": true,
                  "index":true,
                  "analyzer":"standard"
              }
          }
        }

    执行结果: 成功

    GET mingduhui    

    查看 mingduhui的信息,我们刚刚的操作就已经完成了

    • mingduhui:索引库名称
    • mapping:type名称
       
    • goods:文档ID,并不是下面的id属性值

    向 刚刚新建检索表中插入数据

      POST /mingduhui/goods/1
      {
        "id":1,
        "title":"【标题】这是一件出众的衣服",
        "subtitle":"【副标题】描述这个商品的一些细节",
        "images":"【图片】商品图片地址",
        "content":"【富文本】商品详情描述类容"
      }

    2丶更改指定索引文档

      POST /mingduhui/goods/2
      {
        "id":2,
        "title":"【标题】这是一件出众的衣服",
        "subtitle":"【副标题】222描述这个商品的一些细节",
        "images":"【图片】222商品图片地址",
        "content":"【富文本】222商品详情描述类容"
      }

    3丶删除文件

    在我们mingduhui 检索库中 的goods检索表中  有两个 检索文档。分别为1 和2。

    DELETE /mingduhui/goods/1
    //删除 1的 检索文档。 操作完成

  • 相关阅读:
    「Python」pandas入门教程
    「Python」字符串操作内置函数
    「Python」10个python项目
    python-基础入门-序
    提取网站图片
    c#图片添加水印
    js获取url传递的参数
    构建之法阅读笔记01
    学习进度条<第一周>
    30道四则运算<1>
  • 原文地址:https://www.cnblogs.com/heijinli/p/13518300.html
Copyright © 2011-2022 走看看