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"
                }
            }
        }
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM