# Boosting a Nested Query Isn't Working

**URL:** <https://discuss.elastic.co/t/boosting-a-nested-query-isnt-working/155901>\
**Category:** Elasticsearch\
**Created:** [November 8, 2018, 2:17pm UTC](https://discuss.elastic.co/t/boosting-a-nested-query-isnt-working/155901 "2018-11-08T14:17:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![haych1702](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/haych1702/32/37427_2.png) [@haych1702](https://discuss.elastic.co/u/haych1702)\
**Post date:** [November 8, 2018, 2:17pm UTC](https://discuss.elastic.co/t/boosting-a-nested-query-isnt-working/155901/1 "2018-11-08T14:17:24Z")

</div>

Here is the query I am using in it's entirety:

```
GET /property_index/_search
{
   "from" : 0, "size" : 25,
   "query": {
      "function_score": {
         "query": {
            "bool": {
                "should": [
                   {
                      "nested" : {
                         "path" : "propertyNames",
                         "query" : {
                            "bool": {
                               "should": [
                                  {
                                     "match": {
                                        "propertyNames.value": {
                                           "query": "downing",
                                           "operator": "and"
                                        }
                                     }
                                  },
                                  {
                                     "match_phrase": {
                                        "propertyNames.value": {
                                           "query": "downing",
                                           "slop": 100
                                        }
                                     }
                                  },
                                  {
                                     "match_phrase_prefix" : {
                                        "propertyNames.value" : {
                                           "query" : "downing",
                                           "max_expansions" : "500"
                                        }
                                     }
                                  }
                               ]
                            }
                         }
                      }
                   },
                   {
                      "nested" : {
                         "path": "propertyNames",
                         "boost": 1000,
                         "query": {
                            "bool": {
                               "must": [
                                  {
                                     "match": {
                                        "propertyNames.type.raw": {
                                           "query": "Primary Name"
                                        }
                                     }
                                  },
                                  {
                                     "match_phrase": {
                                        "propertyNames.value.raw": {
                                           "query": "downing"
                                        }
                                     }
                                  }
                               ]
                            }
                         }
                      }
                   }
                ]
             }
          },
          "boost": "5",
          "functions": [
             {
                "filter": {
                   "bool": {
                      "must": [
                         {
                            "terms": {
                               "propertyType": [
                                  "House",
                                  "Flat",
                                  "Bungalow",
                                  "Mansion",
                                  "Shed",
                                  "Penthouse"
                               ]
                            }
                         }
                      ]
                   }
                },
                "weight": 44
             },
             {
                "filter": {
                "bool": {
                   "must_not": [
                      {
                         "terms": {
                            "area.propertyType": [
                               "House",
                               "Flat",
                               "Bungalow",
                               "Mansion",
                               "Shed",
                               "Penthouse"
                            ]
                         }
                      }
                   ]
                }
             },
             "weight": 42
          }
       ],
       "max_boost": 42,
       "score_mode": "max",
       "boost_mode": "replace",
       "min_score" : 0
    }
 },
 "sort": [
    {"status": { "order": "asc" }},
    {"sortKey": { "order": "asc" }}       
 ]
}

```

The part that I am adding is the second nested query in `query.function_score.query.bool.should`. The data in propertyNames looks like this:

```
{
   "names": [
      {
         "type": "Primary Name",
         "value": "10 Downing Street"
      },
      {
         "type": "Other Name",
         "value": "The prime minister's house"
      }
   ],
}

```

If, the search term was "downing", then the above document should get a higher score. If it was "prime", then it shouldn't be boosted.

However, the part that I have added is making no difference whatsoever.

I think that this is roughly correct. I have been playing around with lots of combinations of the `should`s and `must`s but no combination gives the correct results.

Am I along the right lines here?

It doesn't matter if the nested query that I have added is there or not. The same results are returned.

Would it help to see the mappings file?

---

<div class="post-metadata">

**Author:** ![Jaspreet\_Singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaspreet_singh/32/58296_2.png) [@Jaspreet\_Singh](https://discuss.elastic.co/u/Jaspreet_Singh)\
**Post date:** [November 14, 2018, 7:50pm UTC](https://discuss.elastic.co/t/boosting-a-nested-query-isnt-working/155901/2 "2018-11-14T19:50:13Z")

</div>

Can you rephrase what are you looking to do? If your concern about a specific document or are you looking for help at a general query level. If you share your requirement, people may be able to help you out with alternatives, if any.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 12, 2018, 7:50pm UTC](https://discuss.elastic.co/t/boosting-a-nested-query-isnt-working/155901/3 "2018-12-12T19:50:13Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
