zoukankan      html  css  js  c++  java
  • es 复合数据类型——数组,对象和嵌套

    嵌套代码如下:

    PUT demo
    {
      "settings": {
        "number_of_shards": 4,
        "number_of_replicas": 1
      },
      "mappings": {
          "properties": {
            "id": {
              "type": "long"
            },
            "title": {
              "type": "text"
            },
            "university": {
              "type": "nested",
              "properties": {
                "name": {
                  "type": "text"
                },
                "foundingYear": {
                  "type": "date"
                },
                "address": {
                  "type": "text"
                },
                "college": {
                  "type": "nested",
                  "properties": {
                    "name": {
                      "type": "text"
                    }
                  }
                }
              }
            }
          
        }
      }
    }
    
    POST demo/_doc
    {
      "id": 1,
      "title": "北京市学校信息列表",
      "university": [
        {
          "name": "清华大学",
          "address": "北京市海淀区双清路30号",
          "foundingYear": "1911-04-09",
          "college": [
            {
              "name": "土木水利学院"
            },
            {
              "name": "信息科学技术学院"
            },
            {
              "name": "材料学院"
            }
          ]
        },
        {
          "name": "北京大学",
          "address": "北京市海淀区颐和园路5号",
          "foundingYear": "1898-06-01",
          "college": [
            {
              "name": "经济学院"
            },
            {
              "name": "外国语学院"
            },
            {
              "name": "信息科学技术学院"
            }
          ]
        }
      ]
    }
    
    PUT demo/_doc
    {
      "id": 2,
      "title": "上海市学校信息列表",
      "university": [
        {
          "name": "复旦大学",
          "address": "上海市杨浦区邯郸路220号",
          "foundingYear": "1905-06-29",
          "college": [
            {
              "name": "哲学学院"
            },
            {
              "name": "信息科学与工程学院"
            },
            {
              "name": "计算机科学技术学院"
            }
          ]
        },
        {
          "name": "上海交通大学",
          "address": "上海市闵行区东川路800号",
          "foundingYear": "1896-12-01",
          "college": [
            {
              "name": "船舶海洋与建筑工程学院"
            },
            {
              "name": "环境科学与工程学院"
            },
            {
              "name": "外国语学院"
            }
          ]
        }
      ]
    }
    
    GET demo/_doc/_search
    {
      "_source": {
        "includes": [
          "*"
        ],
        "excludes": [
          "university"
        ]
      },
      "query": {
        "nested": {
          "path": "university",
          "query": {
            "bool": {
              "must": [
                {
                  "match": {
                    "university.name": "清华"
                  }
                }
              ]
            }
          },
          "inner_hits": {}
        }
      }
    }

      对象代码如下:

    PUT demo2
    {
      "settings": {
        "number_of_shards": 4,
        "number_of_replicas": 1
      },
      "mappings": {
          "properties": {
            "id": {
              "type": "long"
            },
            "title": {
              "type": "text"
            },
            "university": {
              "type": "object",
              "properties": {
                "name": {
                  "type": "text"
                },
                "foundingYear": {
                  "type": "date"
                },
                "address": {
                  "type": "text"
                }
              }
            }
          
        }
      }
    }
    
    POST demo2/_doc
    {
      "id": 1,
      "title": "北京市学校信息列表",
      "university": 
        {
          "name": "北京大学",
          "address": "北京市海淀区颐和园路5号",
          "foundingYear": "1898-06-01"
        }
    }
    
    GET demo2/_doc/_search
    {
       "query": {
          "bool": {
             "must": [
                {
                   "match": {
                      "university.name": "北京"
                   }
                }
             ]
          }
       }
    }
  • 相关阅读:
    使用jenkins发布docker容器
    使用jenkins构建和部署前端(jenkins是k8s集群中搭建)
    kubernetes的ingress-nginx使用案例
    使用jenkins的SSH Publishers远程执行
    kubernetes集群:向pod里的/etc/hosts添加解析
    kubernetes集群:nacos搭建
    JavaBean的概念
    Statement与PreparedStatement的区别
    JDBC的概念&使用步骤
    session的用法
  • 原文地址:https://www.cnblogs.com/-mrl/p/14985433.html
Copyright © 2011-2022 走看看