zoukankan      html  css  js  c++  java
  • ES基础(四十二)文档的父子关系

     

     

     

     

     

     

     

     

     

     

    课程demo

    PUT my_blogs/_doc/comment1?routing=blog1
    {
      "comment":"I am learning ELK",
      "username":"Jack",
      "blog_comments_relation":{
        "name":"comment",
        "parent":"blog1"
      }
    }
    
    #索引子文档
    PUT my_blogs/_doc/comment2?routing=blog2
    {
      "comment":"I like Hadoop!!!!!",
      "username":"Jack",
      "blog_comments_relation":{
        "name":"comment",
        "parent":"blog2"
      }
    }
    
    #索引子文档
    PUT my_blogs/_doc/comment3?routing=blog2
    {
      "comment":"Hello Hadoop",
      "username":"Bob",
      "blog_comments_relation":{
        "name":"comment",
        "parent":"blog2"
      }
    }
    
    # 查询所有文档
    POST my_blogs/_search
    {
    
    }
    
    
    #根据父文档ID查看
    GET my_blogs/_doc/blog2
    
    # Parent Id 查询
    POST my_blogs/_search
    {
      "query": {
        "parent_id": {
          "type": "comment",
          "id": "blog2"
        }
      }
    }
    
    # Has Child 查询,返回父文档
    POST my_blogs/_search
    {
      "query": {
        "has_child": {
          "type": "comment",
          "query" : {
                    "match": {
                        "username" : "Jack"
                    }
                }
        }
      }
    }
    
    
    # Has Parent 查询,返回相关的子文档
    POST my_blogs/_search
    {
      "query": {
        "has_parent": {
          "parent_type": "blog",
          "query" : {
                    "match": {
                        "title" : "Learning Hadoop"
                    }
                }
        }
      }
    }
    
    
    
    #通过ID ,访问子文档
    GET my_blogs/_doc/comment3
    #通过ID和routing ,访问子文档
    GET my_blogs/_doc/comment3?routing=blog2
    
    #更新子文档
    PUT my_blogs/_doc/comment3?routing=blog2
    {
        "comment": "Hello Hadoop??",
        "blog_comments_relation": {
          "name": "comment",
          "parent": "blog2"
        }
    }

    本文来自博客园,作者:秋华,转载请注明原文链接:https://www.cnblogs.com/qiu-hua/p/14197863.html

  • 相关阅读:
    【ARTS】打卡第七周
    【ARTS】打卡第六周
    【ARTS】打卡第五周
    【leetcode】 438. Find All Anagrams in a String
    【ARTS】打卡第四周
    【ARTS】打卡第三周
    【leetcode】 11. Container With Most Water
    【ARTS】打卡第二周
    【ARTS】打卡第一周
    深度VS广度——谈谈对测试职业的一些思考
  • 原文地址:https://www.cnblogs.com/qiu-hua/p/14197863.html
Copyright © 2011-2022 走看看