elasticSearch多条件高级检索语句,包含多个must、must_not、should嵌套示例,并考虑nested对象的特殊检索

多条件高级检索模板

多条件高级检索es语句,包含多个must、must_not、should嵌套示例,并考虑nested对象的特殊检索

该模板适用于所有情况,尤其适用于侧边栏多级多条件联合查询

{
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "title": "Science"
                    }
                },
                {
                    "match": {
                        "countryArea": "United States"
                    }
                },
                {
                    "bool": {
                        "should": [
                            {
                                "match": {
                                    "sponsor": "National Science Foundation"
                                }
                            },
                            {
                                "match": {
                                    "sponsor": "David and Lucile Packard Foundation"
                                }
                            }
                        ],
                        "minimum_should_match": 1
                    }
                },
                {
                    "bool": {
                        "should": {
                            "nested": {
                                "path": "researchAreas",
                                "query": {
                                    "bool": {
                                        "should": [
                                            {
                                                "match": {
                                                    "researchAreas.subjectName": "Arts and Humanities"
                                                }
                                            },
                                            {
                                                "match": {
                                                    "researchAreas.subjectName": "Ecology"
                                                }
                                            }
                                        ],
                                        "minimum_should_match": 1
                                    }
                                }
                            }
                        }
                    }
                }
            ],
            "must_not": {
                "match": {
                    "fundingType": "Program or Curriculum Development or Provision"
                }
            }
        }
    }
}
posted @ 2020-06-29 11:45  近朱朱者赤  阅读(16144)  评论(0编辑  收藏  举报