• 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": "北京"
                   }
                }
             ]
          }
       }
    }
  • 相关阅读:
    form表单有条件的提交
    当月第一天、最后一天、下月第一天,时间date
    网站分享
    如何做浏览器网站搜索
    js关闭当前页面跳转新页面
    img图片居中
    laravel 重定向路由带参数
    线段判严格相交+思维——poj1066
    线段判非严格相交+暴力——poj2653
    线段判严格相交+最短路建图——poj1556
  • 原文地址:https://www.cnblogs.com/-mrl/p/14985433.html
Copyright © 2020-2023  润新知