美文网首页
Elasticsearch-(parent-child) 查询

Elasticsearch-(parent-child) 查询

作者: 地古丁 | 来源:发表于2021-01-15 10:02 被阅读0次

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) 查询

      本文链接:https://www.haomeiwen.com/subject/gxpiaktx.html