zoukankan      html  css  js  c++  java
  • elasticsearch的join查询

    1.概述

    官方文档

    https://www.elastic.co/guide/en/elasticsearch/reference/current/joining-queries.html

    两种类型的查询

    嵌套查询

    has_child和has_parent

    其中,has_child返回包含特定查询字段文档的父文档;

    has_parent返回包含特定查询字段的父文档的子文档。

    2.实例

    2.1 嵌套查询

    GET /_search
    {
        "query": {
            "nested" : {
                "path" : "obj1",
                "score_mode" : "avg",
                "query" : {
                    "bool" : {
                        "must" : [
                        { "match" : {"obj1.name" : "blue"} },
                        { "range" : {"obj1.count" : {"gt" : 5}} }
                        ]
                    }
                }
            }
        }
    }

    2.2 has_child 查询

    GET /_search
    {
        "query": {
            "has_child" : {
                "type" : "blog_tag",
                "query" : {
                    "term" : {
                        "tag" : "something"
                    }
                }
            }
        }
    }

    2.3 has_parent 

    GET /_search
    {
        "query": {
            "has_parent" : {
                "parent_type" : "blog",
                "query" : {
                    "term" : {
                        "tag" : "something"
                    }
                }
            }
        }
    }

    2.4 parent_id 查询

    PUT my_index
    {
      "mappings": {
        "_doc": {
          "properties": {
            "my_join_field": {
              "type": "join",
              "relations": {
                "my_parent": "my_child"
              }
            }
          }
        }
      }
    }
    
    PUT my_index/_doc/1?refresh
    {
      "text": "This is a parent document",
      "my_join_field": "my_parent"
    }
    
    PUT my_index/_doc/2?routing=1&refresh
    {
      "text": "This is a child document",
      "my_join_field": {
        "name": "my_child",
        "parent": "1"
      }
    }
    GET /my_index/_search
    {
      "query": {
        "parent_id": {
          "type": "my_child",
          "id": "1"
        }
      }
    }
  • 相关阅读:
    python注释中文
    python学习好文
    浅析python 的import 模块(转)
    Python解释器镜像源修改
    Python解释器安装
    Python和Python解释器
    计算机基础小结
    网络瓶颈效应
    编程语言分类
    子查询|视图事务
  • 原文地址:https://www.cnblogs.com/davidwang456/p/10078301.html
Copyright © 2011-2022 走看看