title: How to use a bool Query with function_score in Elasticsearch?
body: <p>I have 3 types of data [doctor,article,place] which I want to match their documents based on a bool query. but I want to give doctor type a boost of 3, place type a boost of 2 and article a boost of 1.I have a search Query which uses <code>function_score</code> and <code>bool query</code> to match documents. but the problem is it throws an exception which says <code>No function with the name [bool] is registered.</code>. Here is my Query :</p>
  
  <pre><code>GET /my_index/doctor,article,place/_search
  {
      "query": {
          "function_score": {
              "bool": {
                  "should":
                  [
                      {
                        "common": {
                          "title": {
                              "query":"$q",
                              "cutoff_frequency": 0.001,
                              "low_freq_operator": "and"
                              }
                          }
                      },
                      {
                          "prefix": {
                              "title": "$q"
                              }
  
                      },
                      {
                          "match_phrase_prefix" : {
                              "title" : {
                                  "query": "$q",
                                  "slop":  10
                              }
                          }
                      }
                  ]
              },
              "functions":[
                  {
                      "filter":{
                          "type":{
                             "value":"doctor"
                          }
                      },
                      "weight":3
                  },
                  {
                      "filter":{
                          "type":{
                             "value":"place"
                          }
                      },
                      "weight":2
                  },
                  {
                      "filter":{
                          "type":{
                             "value":"article"
                          }
                      },
                      "weight":1
                  }
              ],
              "score_mode":"first",
              "boost_mode":"multiply"
          }
      }
  }
  </code></pre>
  
  <p>thanks for your help.</p>
  
  <p><strong>EDIT</strong> :</p>
  
  <p><strong>ERROR :</strong></p>
  
  <pre><code>{
    "error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed;
              shardFailures {[fWqkaeoLSva_QwhrYHnG3A][darmanjoo][0]:
              SearchParseException[[darmanjoo][0]: from[-1],size[-1]:
                Parse Failure [Failed to parse source [
                  {
                    "query": {
                      "function_score": {
                        "query": {
                          "bool": {
                            "should": [
                              {
                                "common": {
                                  "title": {
                                    "query": "دکتر",
                                    "cutoff_frequency": 0.001,
                                    "low_freq_operator": "and"
                                  }
                                }
                              },
                              {
                                "prefix": {
                                  "title": "دکتر"
                                }
                              },
                              {
                                "match_phrase_prefix": {
                                  "title": {
                                    "query": "دکتر",
                                    "slop": 10
                                  }
                                }
                              }
                            ]
                          }
                        },
                        "functions": [
                          {
                            "filter": {
                              "type": {
                                "value": "doctor"
                              }
                            },
                            "weight": 3
                          },
                          {
                            "filter": {
                              "type": {
                                "value": "place"
                              }
                            },
                            "weight": 2
                          },
                          {
                            "filter": {
                              "type": {
                                "value": "article"
                              }
                            },
                            "weight": 1
                          }
                        ],
                        "score_mode": "first",
                        "boost_mode": "multiply"
                      }
                    }
                  }
                ]]];
              nested: QueryParsingException[[darmanjoo] No function with the name [weight] is registered.]; }{[fWqkaeoLSva_QwhrYHnG3A][darmanjoo][1]:
              SearchParseException[[darmanjoo][1]: from[-1],size[-1]:
                Parse Failure [Failed to parse source [
                  {
                    "query": {
                      "function_score": {
                        "query": {
                          "bool": {
                            "should": [
                              {
                                "common": {
                                  "title": {
                                    "query": "دکتر",
                                    "cutoff_frequency": 0.001,
                                    "low_freq_operator": "and"
                                  }
                                }
                              },
                              {
                                "prefix": {
                                  "title": "دکتر"
                                }
                              },
                              {
                                "match_phrase_prefix": {
                                  "title": {
                                    "query": "دکتر",
                                    "slop": 10
                                  }
                                }
                              }
                            ]
                          }
                        },
                        "functions": [
                          {
                            "filter": {
                              "type": {
                                "value": "doctor"
                              }
                            },
                            "weight": 3
                          },
                          {
                            "filter": {
                              "type": {
                                "value": "place"
                              }
                            },
                            "weight": 2
                          },
                          {
                            "filter": {
                              "type": {
                                "value": "article"
                              }
                            },
                            "weight": 1
                          }
                        ],
                        "score_mode": "first",
                        "boost_mode": "multiply"
                      }
                    }
                  }
                ]]];
              nested: QueryParsingException[[darmanjoo] No function with the name [weight] is registered.]; }{[fWqkaeoLSva_QwhrYHnG3A][darmanjoo][4]:
              SearchParseException[[darmanjoo][4]: from[-1],size[-1]:
                Parse Failure [Failed to parse source [
                  {
                    "query": {
                      "function_score": {
                        "query": {
                          "bool": {
                            "should": [
                              {
                                "common": {
                                  "title": {
                                    "query": "دکتر",
                                    "cutoff_frequency": 0.001,
                                    "low_freq_operator": "and"
                                  }
                                }
                              },
                              {
                                "prefix": {
                                  "title": "دکتر"
                                }
                              },
                              {
                                "match_phrase_prefix": {
                                  "title": {
                                    "query": "دکتر",
                                    "slop": 10
                                  }
                                }
                              }
                            ]
                          }
                        },
                        "functions": [
                          {
                            "filter": {
                              "type": {
                                "value": "doctor"
                              }
                            },
                            "weight": 3
                          },
                          {
                            "filter": {
                              "type": {
                                "value": "place"
                              }
                            },
                            "weight": 2
                          },
                          {
                            "filter": {
                              "type": {
                                "value": "article"
                              }
                            },
                            "weight": 1
                          }
                        ],
                        "score_mode": "first",
                        "boost_mode": "multiply"
                      }
                    }
                  }
                ]]];
              nested: QueryParsingException[[darmanjoo] No function with the name [weight] is registered.]; }]",
    "status": 400
  }
  </code></pre>
  
  <p><strong>MY EDITED QUERY STRAIGHT COPIED FROM MARVEL SENSE :</strong></p>
  
  <pre><code>GET /darmanjoo/doctor,article,place/_search
  {
      "query": {
          "function_score": {
              "query": {
                  "bool": {
                      "should": [
                          {
                              "common": {
                                  "title": {
                                      "query": "$q",
                                      "cutoff_frequency": 0.001,
                                      "low_freq_operator": "and"
                                  }
                              }
                          },
                          {
                              "prefix": {
                                  "title": "$q"
                              }
                          },
                          {
                              "match_phrase_prefix": {
                                  "title": {
                                      "query": "$q",
                                      "slop": 10
                                  }
                              }
                          }
                      ]
                  }
              },
              "functions": [
                  {
                      "filter": {
                          "type": {
                              "value": "doctor"
                          }
                      },
                      "weight": 3
                  },
                  {
                      "filter": {
                          "type": {
                              "value": "place"
                          }
                      },
                      "weight": 2
                  },
                  {
                      "filter": {
                          "type": {
                              "value": "article"
                          }
                      },
                      "weight": 1
                  }
              ],
              "score_mode": "first",
              "boost_mode": "multiply"
          }
      }
  }
  </code></pre>