{
    "query": {
        "bool": {
            "should": [
                {
                    "term": {
                        "title.keyword": "P128"
                    }
                },
                {
                    "bool": {
                        "minimum_should_match": 0,
                        "filter": [
                            {
                                "bool": {
                                    "minimum_should_match": 1,
                                    "should": [
                                        {
                                            "match": {
                                                "all": {
                                                    "query": "(p128)",
                                                    "operator": "AND"
                                                }
                                            }
                                        },
                                        {
                                            "match": {
                                                "all.plain": {
                                                    "query": "(p128)",
                                                    "operator": "AND"
                                                }
                                            }
                                        },
                                        {
                                            "match": {
                                                "descriptions.en": {
                                                    "query": "(p128)",
                                                    "operator": "AND"
                                                }
                                            }
                                        },
                                        {
                                            "match": {
                                                "labels.en": {
                                                    "query": "(p128)",
                                                    "operator": "AND"
                                                }
                                            }
                                        }
                                    ]
                                }
                            }
                        ],
                        "should": [
                            {
                                "dis_max": {
                                    "tie_breaker": 0,
                                    "queries": [
                                        {
                                            "constant_score": {
                                                "filter": {
                                                    "match": {
                                                        "labels.en.near_match": "(p128)"
                                                    }
                                                },
                                                "boost": 0.78
                                            }
                                        },
                                        {
                                            "constant_score": {
                                                "filter": {
                                                    "match": {
                                                        "labels.en.near_match_folded": "(p128)"
                                                    }
                                                },
                                                "boost": 0.01
                                            }
                                        }
                                    ]
                                }
                            },
                            {
                                "bool": {
                                    "minimum_should_match": 1,
                                    "should": [
                                        {
                                            "match": {
                                                "all": {
                                                    "query": "(p128)",
                                                    "operator": "OR",
                                                    "boost": 0.04
                                                }
                                            }
                                        },
                                        {
                                            "match": {
                                                "all.plain": {
                                                    "query": "(p128)",
                                                    "operator": "OR",
                                                    "boost": 0.04
                                                }
                                            }
                                        },
                                        {
                                            "dis_max": {
                                                "tie_breaker": 0.2,
                                                "queries": [
                                                    {
                                                        "match": {
                                                            "labels.en.plain": {
                                                                "query": "(p128)",
                                                                "boost": 0.07
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "match": {
                                                            "descriptions.en.plain": {
                                                                "query": "(p128)",
                                                                "boost": 0.07
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "match": {
                                                            "labels.en": {
                                                                "query": "(p128)",
                                                                "boost": 0.07
                                                            }
                                                        }
                                                    },
                                                    {
                                                        "match": {
                                                            "descriptions.en": {
                                                                "query": "(p128)",
                                                                "boost": 0.07
                                                            }
                                                        }
                                                    }
                                                ]
                                            }
                                        }
                                    ]
                                }
                            }
                        ]
                    }
                }
            ],
            "minimum_should_match": 1,
            "filter": [
                {
                    "terms": {
                        "namespace": [
                            120
                        ]
                    }
                }
            ]
        }
    },
    "rescore_query": [
        {
            "window_size": 8192,
            "query": {
                "query_weight": 1,
                "rescore_query_weight": 1,
                "score_mode": "total",
                "rescore_query": {
                    "function_score": {
                        "score_mode": "sum",
                        "functions": [
                            {
                                "script_score": {
                                    "script": {
                                        "source": "pow(doc['incoming_links'].value , 1) \/ ( pow(doc['incoming_links'].value, 1) + pow(100,1))",
                                        "lang": "expression"
                                    }
                                },
                                "weight": 0.6
                            },
                            {
                                "script_score": {
                                    "script": {
                                        "source": "pow(doc['sitelink_count'].value , 2) \/ ( pow(doc['sitelink_count'].value, 2) + pow(20,2))",
                                        "lang": "expression"
                                    }
                                },
                                "weight": 0.4
                            },
                            {
                                "weight": 1,
                                "filter": {
                                    "bool": {
                                        "must_not": [
                                            {
                                                "match": {
                                                    "statement_keywords": "P31=Q4167410"
                                                }
                                            }
                                        ]
                                    }
                                }
                            }
                        ]
                    }
                }
            }
        }
    ]
}