Elasticsearch-(parent-child) 查询

Elasticsearch 版本 7.6.2

//测试自关联查询

PUT my-index

{

  "settings":{

    "number_of_shards":20,

    "number_of_replicas":1

  },

  "mappings": {

        "properties" : {

            "my-join-field" : {

                "type" : "join",

                "relations": {

                    "extWoNbr": "wonbr"    //父文档字段:子文档字段

                }

            }

        }

    }

}

POST my-index/_doc/1

{

  "my-join-field":"extWoNbr",    //父文档字段

  "tag":"Elasticsearch",

  "extWoNbr":"123"

}

POST my-index/_doc/2?routing=1    //父文档路由值

{

  "my-join-field":{

    "name":"wonbr",

    "parent":"1"                       //父文档ID

  },

  "tag":"RRElasticsearch",

  "wonbr":"123"

}

POST /my-index/_search

{

    "query": {

        "has_parent" : {

            "parent_type": "extWoNbr",

             "query" : {

                "term" : {

                    "extWoNbr" : {

                        "value" : "Elasticsearch"

                    }

                }

            }

        }

    }

}

你可能感兴趣的:(Elasticsearch-(parent-child) 查询)